Notifications
Clear all

[Closed] .NET and it's Implications for Maxscript [Max 9]

 rdg

Yannick,

the code looks great – but I cannot test it – no max9.
So have to ask you a theoretical question:

is it possible to design a form with the visual form designer and populate the fields with maxscript. Or do I need to compose my form in maxscript?

Georg

Hello Georg,

You need to compose your form in maxscript. But it’s just an “intelligent” copy paste from code generated by Visual Studio 2005 ; “intelligent” because VS generate some undesired and not necessary code. I think it’s possible to develop a small converter between visual form designer generated code and maxscript.

But it’s best to use maxscript rollout because .Net 2.0 forms doesn’t have 3ds max look and feel style. Otherwise their use is easy and it’s possible to integrate .Net 2.0 controls in rollouts.

The best use of dotNet is to access some .Net framework classes like Xmlreader, XmlWritter, file access etc. and load 3rd parties managed libraries.

Yannick

 PEN

This has to be one of the biggest things that I have been waiting for but I just dont’ have the time to mess with any of it. Please keep all the reference material comming, and Bobo thanks for all the work that you do help us out. At some point I have a pile of tools that I want to write and I’m going to need to get deep into this to do it.

Hi.

Some questions here.

Is it possible to loop (for item in arrayList…) through the contents of a collection like ArrayList?. Or do you have to do it via Item property?.

Is it possible to use generics? (that would be great!). And if so, how would you specify the type of the generic?.

Thanks.

2 Replies
(@alpineman)
Joined: 11 months ago

Posts: 0

Right now you cannot loop through an .NET collection though I would like it to. It’s one of the top things on my feature request list.

(@halfvector)
Joined: 11 months ago

Posts: 0

Yes, that would be nice. And what about generics?.

Thanks.

When we create class libraries in C# and use them via maxscript, is it significantly faster than using straight MXS? If so, are custom .ms files filled with common custom functions that I know we all make and use across multiple scripts – are these “MXS modules” better written using C#? Just trying to see how much of my old code would benefit from a C# overhaul, or whether its necessary or even possible.

Is there some sort of interpreter that makes C# not as fast as SDK classes/plugins? Just wondering how innate all of this is, and how its communicating to the C++ core…

3 Replies
(@halfvector)
Joined: 11 months ago

Posts: 0

I’ve done a simple performance test. A script that calculates the square root of 10 million random numbers in MXS, MXS+.NET (using C#) and C++ (this one was an extension tested in MAX8). The results:

MXS -> 24.047 seconds
MXS+.NET -> 0.235 seconds
C++ extension -> 0.61 seconds

The for loop in MXS is overkill. Surprisingly the C# version is the fastest one, over C++ version. Although it’s well known that the JIT compiler does a good job optimizing the code.

Anyway I don’t think this test is a good indicator. I think the performance gap between MXS and MXS+.NET will depend on the type of application. For example, I guess the reflection process used to translate .NET to MXS and viceversa has to affect (negatively) the performance at some level.

But if you’re creating an application where you need to do a lot of intensive computation, .NET will be a good friend.

Lets see what the others say!.

I have a lot of code that makes use of generics… 🙁

Anyway Autodesk people have done a good job. And I guess .NET support will evolve, so things like these will be overcame.

Greets.

(@alpineman)
Joined: 11 months ago

Posts: 0

Maxscript or something else?

(@halfvector)
Joined: 11 months ago

Posts: 0

Oh no. A friend of mine and I developed a C# 3D engine called Haddd (this is the old web, now it is an open source project called Jad) and it is heavily based on generics. So I say that because I could reuse a lot of code from it.

Anyway today I’ve been trying to load some classes from the engine like the parser and it works beautifully.

Greets.

PS: you can see some old images and videos of the engine in the first link.

Yes, that would be nice. And what about generics?.

As far as I know generics are not supported in MAXScript. 🙁

Hi,

Yes, the JIT compiler optimizes the code and more you run it more it’s fast.

In MAXScript reference there’s this note :

Note on DotNet Performance:
Since DotNet uses a Just in Time compiler (JIT), the first time you load or execute any managed code, the Common Language Runtime (CLR) will compile the Intermediate code into machine language code, causing a significant performance hit. The second time the code is executed in the same session, the JIT compiler will use cached binaries instead of compiling the code again and the code will execute much faster.

Hi,

I’ve been able to create a .Net 2.0 Form with a DirectX Rendering inside but it doesn’t work now ; I’ve not changed the code .

Here’s the code :

(
	global g_hDevice
	global g_hForm
	
	fn OnPaint =
	(
		if g_hDevice != undefined do
		(
			ClearFlags = dotNetClass "Microsoft.DirectX.Direct3D.ClearFlags"
			Color = dotNetClass "System.Drawing.Color"
			
			g_hDevice.Clear ClearFlags.Target Color.Black 1.0 0
			g_hDevice.BeginScene()
			
			g_hDevice.EndScene()
			g_hDevice.Present()
			
			g_hForm.Invalidate()
		)
	)
	
	-- Create a DotNet Form
	g_hForm = dotNetObject "System.Windows.Forms.Form"
	g_hForm.Size = dotNetObject "System.Drawing.Size" 300 300
	g_hForm.Text = ".Net 2.0 Form with DirectX Control"
	g_hForm.topmost = true  -- Always displayed over the others windows
	
	PresentParameters = dotNetObject "Microsoft.DirectX.Direct3D.PresentParameters"
	SwapEffect = dotNetClass "Microsoft.DirectX.Direct3D.SwapEffect"
	DeviceType = dotNetClass "Microsoft.DirectX.Direct3D.DeviceType"
	CreateFlags = dotNetClass "Microsoft.DirectX.Direct3D.CreateFlags"
	Device = dotNetClass "Microsoft.DirectX.Direct3D.Device"
	PrimitiveType = dotNetClass "Microsoft.DirectX.Direct3D.PrimitiveType"
	
	PresentParameters.Windowed = true
	PresentParameters.SwapEffect = SwapEffect.Discard
	
	g_hDevice = dotNetObject Device 0 DeviceType.Hardware g_hForm CreateFlags.SoftwareVertexProcessing #(PresentParameters)
	
	--Add an Event Handler for the pain event:
	dotNet.addEventHandler g_hForm "paint" OnPaint
	
	-- Show form
	g_hForm.show()
)

I will not continue to develop with DirectX Managed in MAXSCript because it’s bugged and it seems that I cannot access some DirectX structs :sad:.

Your problem was here:

	PresentParameters = dotNetObject "Microsoft.DirectX.Direct3D.PresentParameters"

You didn’t load your assembly:
You need to do this:

dotnet.LoadAssembly "Microsoft.DirectX.Direct3D.dll"
 	PresentParameters = dotNetObject "Microsoft.DirectX.Direct3D.PresentParameters"
 

Works like a charm…

Chris J.

FYI:

The source code for maxscript .NET comes with the SDK. So for you folks out there who want to tinker with it… go ahead.

Page 3 / 7