Contents
Integrating MaxScript and .NET Systems
 
 
Printer-Friendly VersionPrinter-Friendly Version
 
Latest News
spacer View All spacer
 
November 22, 2009
 
Video Game Watchdog National Institute On Media And The Family Shutting Down [11]
 
Modern Warfare 2 Infinity Ward's 'Most Successful PC Version' Yet [12]
 
New Tech, Design Details Of Project Natal To Emerge At Gamefest In February
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
November 22, 2009
 
Sucker Punch Productions
Character Artist
 
Sucker Punch Productions
3D Environment Artist
 
Sucker Punch Productions
Network Programmer
 
Sucker Punch Productions
Texture Artist
 
Sony Online Entertainment
Brand Manager
 
Monolith Productions
Sr. Software Engineer, Engine - Monolith Productions - #113767
 
Crystal Dynamics
Sr. Level Designer
 
Gargantuan Studios
Lead World Designer
spacer
Latest Features
spacer View All spacer
 
November 22, 2009
 
arrow Upping The Craft: Susan O'Connor On Games Writing [6]
 
arrow Small Developers: Minimizing Risks in Large Productions - Part II [6]
 
arrow iPhone Piracy: The Inside Story [48]
 
arrow And Yet It Grows: Analyzing the Size and Growth of the European Game Market [5]
 
arrow NPD: Behind the Numbers, October 2009 [13]
 
arrow Reflecting On Uncharted 2: How They Did It [5]
 
arrow Sponsored Feature: Rasterization on Larrabee -- Adaptive Rasterization Helps Boost Efficiency
 
arrow Postmortem: Wadjet Eye's The Blackwell Convergence [2]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
November 22, 2009
 
Accepting the Inherent Value of Games
 
Planckogenesis, Part II: Song Structure & Gravy Train [1]
 
Designing Games Is About Matching Personalities [1]
spacer
About
spacer News Director:
Leigh Alexander
Features Director:
Christian Nutt
Editor At Large:
Chris Remo
Advertising:
John 'Malik' Watson
Recruitment/Education:
Gina Gross
 
Features
  Integrating MaxScript and .NET Systems
by Shea McCombs, Kevin Rabun
7 comments
Share RSS
 
 
September 9, 2008 Article Start Previous Page 2 of 5 Next
 

.NET Languages

Any programming language that complies with the Common Language Infrastructure (CLI) specification can be used to write .NET applications. At this point C# and Visual Basic .NET are the most common and well documented CLI languages for development.

At Vicarious Visions, we have decided to use C# whenever possible for developing .NET applications. We settled on C# because the language was developed with the .NET Framework in mind, and looks to integrate some of the best practices from C++ and Java to produce a straightforward application development language.

Advertisement

One of the key features of C# is that it is a reference-based language, and pointers do not exist. This may seem like a drawback over C++, but pointers are the source of many issues in applications because of the unrestricted control they give to the engineer.

While C# is the language we use to develop .NET tools, there are numerous languages to choose from -- to date, there are over 40 CLI languages available for building programs, including:

  • Smalltalk
  • A# (Ada)
  • Active Oberon
  • APLNext
  • Boo
  • C++/CLI
  • Chrome
  • Cobra
  • Common Larceny (Scheme)
  • Component Pascal
  • Delphi.NET
  • Delta Forth .NET
  • DotLisp
  • EiffelEnvision
  • F# (Experimental ML language)
  • Gardens Point Modula-2/CLR
  • Haskell for .NET/Haskell.net/Hugs for .NET
  • IKVM.NET (converts Java byte code to CIL)
  • IronLisp
  • IronPython
  • IronRun
  • J# (Java)
  • JScript.NET
  • L# (Lisp)
  • Lexico
  • LOLCode.NET
  • Mercury on .NET
  • Mondrian
  • Nemerle (C#/PERL/LISP hybrid)
  • Net Express (COBOL)
  • NetCOBOL
  • OxygenScheme
  • P sharp (Prolog)
  • Phalanger (PHP)
  • Phrogram (CLI language for kids)
  • PowerBuilder
  • Ruby.NET
  • S# (Smalltalk)
  • sml.net (Stardard ML)
  • VBx (dynamic VB.NET)
  • Wildcat Cobol

Our Approach

One of the biggest requirements for our level editor was that it had to be project-independent. It could not be designed to work with any one engine specifically, so it would need to be built upon a truly generic set of functionality. This is unique among editors, which are almost always made for a specific engine, so it meant we immediately ruled out any sort of in-game level editor.

Another limitation was the number of developers who could give full-time support to the level editor. This number turned out to be two; one engineer and one technical artist. As exciting as writing a level editor from the ground up sounded, this option was becoming very unlikely.

We chose to avoid 3DS Max's C++ API for two reasons. The first is due to the scope of the code we were writing in 3DS Max. Most of the code would be for scene manipulation and event registration, which is something MaxScript is already very good at. The other reason comes from maintaining the code across major 3DS Max versions. MaxScript often "just works" in a new version with no modifications, but C++ plug-ins need to be re-compiled against the new API.

Additionally, the requirement of having Visual Studio configured with the 3DS Max API, and having a strong knowledge of C++, makes plug-ins far less accessible to otherwise capable people. Lastly, the need to utilize both 32-bit and 64-bit workstations at Vicarious Visions meant maintaining two versions of our plug-ins. We began to look for solutions that could run in either environment.

Writing this system purely in MaxScript did not seem realistic because of performance requirements and resource limitations. After doing much research into MaxScript, along with performance benchmarks, we found that MaxScript could not support the goals of our system. Benchmarks showed that complex computations could be performed across the .NET boundary in C# much faster than natively within MaxScript. The benchmark involved passing an array of integers to a function, which accumulated the values into a single integer, and returned the result. The benchmark was run using three array lengths; 16, 1024, and 131072 integers (size). Each benchmark was run on the buffer in three phases; 10 times, 100 times, and 1000 times (length).

  • Size 16 Length 10 MS: 0 DN: 0
  • Size 1024 Length 10 MS: 16 DN: 0
  • Size 131072 Length 10 MS: 1250 DN: 563
  • Size 16 Length 100 MS: 16 DN: 0
  • Size 1024 Length 100 MS: 93 DN: 47
  • Size 131072 Length 100 MS: 12281 DN: 5750
  • Size 16 Length 1000 MS: 16 DN: 15
  • Size 1024 Length 1000 MS: 906 DN: 454
  • Size 131072 Length 1000 MS: 119953 DN: 57406

MaxScript (MS) vs. .NET (DN), results given in milliseconds

According to these results, calling a .NET function is consistently about twice as fast as calling a MaxScript function to do the same work. See the benchmark appendix at the end of this article for full benchmark source code.

MaxScript also has memory limitations, which become a problem when dealing with large data sets. From an implementation standpoint, having an engineer and a technical artist meant that we needed a solution which was both C# driven and MaxScript driven, since engineers typically do not work with MaxScript, and most technical artists do not work with traditional programming languages.

We decided 3DS Max's role would be to serve as the user interface. In other words, 3DS Max was the upper layer for interacting with users and displaying information. This design allowed us to implement most of the level editor functionality outside of 3DS Max by calling C# functions and listening for C# events within MaxScript.

The key design philosophy became providing new functionality using C#, with MaxScript as glue, interfacing 3DS Max to the C# code.

The tools group at Vicarious Visions had previously developed a .NET application for viewing and manipulating large data sets. The .NET integration functionality provided in 3DS Max 9 allowed us to plug into this application, thus giving our developers a familiar user interface for creating and manipulating game data. By integrating the two systems, we were able to offload data processing from 3DS Max to our internal tools, which were already optimized for the task.

An integrated solution also gave us the ability to attach Visual Studio to the 3DS Max process, trigger a bug, and step through the .NET code, setting breakpoints, watching values, and exploring data structures while 3DS Max quietly sat in the background. User Interfaces written in .NET can also be used directly in 3DS Max, making for a much more seamless user experience.

One of the fortunate side-effects of this approach comes from our toolchain's ability to communicate directly with the game during runtime. Because of this, changes in 3DS Max can be immediately reflected while the game is running. This has provided us with much shorter iteration time for designers and artists when editing levels.

 
Article Start Previous Page 2 of 5 Next
 
Comments

Klaus Drobec
profile image
As usual, I appreciate the quality of your feature articles very much. As a small point of critique: For articles with long code sections, could you please make an effort at formatting those to a more readable form. As I've seen blog software do this automatically, my guess is a large online offering such as yours has appropriate solutions at hand.
Much obliged.

Simon Carless
profile image
Klaus - looks to me that the main issue is the in-code comments overflowing lines on the code excerpt on Page 3, correct? Going to see if we can fix that, thanks.

Joel Martinez
profile image
"One of the key features of C# is that it is a reference-based language, and pointers do not exist."

This is actually not quite right :-)
http://msdn.microsoft.com/en-us/library/y31yhkeb(VS.80).aspx

Rune Braathen
profile image
Thank you very much for an informative article.

The .NET integration-features that have been introduced into MAX is a step in the right direction, but there are some shortcomings that may benefit from the act of being brought to the surface, in case someone out there were dancing a mazurka of joy, thinking they could throw out the MAX sdk come blue morning.

The ability to interface with MAX datatypes from the .NET assembly is practically nonexistant. As a result, shuffling large portions of data to the .NET-side therefore requires iterating the data. This e.g. hardens the possibilities of quickly performing a very common plugin task: munching geometry.

Hopefully, integration will become a bit tighter in the future, although I would rather prefer they put their weight on making MAXscript run faster.

Chaitanya Munjuluri
profile image
I made a level editor in 3DS Max 5/6 back in 2003/2004. We were using Renderware as middleware. There were two main components to the editor I had made. Level building and ai/gameplay related data. I used 3DS Max purely as a user interface and a nice render interface. Artists would export the models from 3DS Max to Renderware specific format and put all of these into a library. Levels were built by placing an art asset from the library. I would save the level to Rendeware's level format by refering only to the asset id (name). The ai/game play artists would build the path nodes and place gameplay data using 3ds Max nodes that I had built after deriving from the 3DS Max Dummy objects. All of the ai and gameplay data was stored in XML files (used Xerces to parse the data). Come to think of it the most difficult part of it was to import Renderware 3D mesh data into 3DS Max and displaying it as 3DS Max geometry.
I had such a bad time with making the UI for the tool. I could never make it as good as I would have liked.
IIRC Maxscript cannot access everything that's visible in the UI. For example I had issues with using the "loft" tool in Maxscript. Not sure if anything's changed now. I used Maxscript essentially for raising events and for the UI. The majority of the work was done in the 3DS Max Plugins.
Could you tell us something about the formats in which you had exported the data from 3DS Max?

Luke Rymarz
profile image
From the article:
"For some developers, integration with 3DS Max may mean rewriting thousands of lines of code within .NET, and each developer will need to assess how reasonable that would be to achieve."

I've been in positions where I needed to get a lot of old C code into C#. Lucky for me, it was in a DLL, and C# makes running DLL functions relatively easy with platform invoke. Microsoft has a tutorial at http://msdn.microsoft.com/en-us/library/aa288468.aspx.

You'll have to marshal data between the DLL and your C# code, but there ends up being about 10 basic types of marshals (string, array, pointers, etc etc), and once you've got a handle on them, building a class that will run all your DLL functions for you becomes pretty easy.

Anyways, just my two cents. With platform invoke, you'll still have to write a good bit of C# code, but you don't have to rewrite (and re-debug) the code that does most of the work.

Erwin Abdulrahman
profile image
thanks for sharing


none
 
Comment:
 


Submit Comment