Execute maxscripts from notepad++

I wrote a little plugin that let you evaluate max scripts from notepad++ using Ephere’s .NET wrapper for the max SDK and NppPlugin.NET v0.5

I have not tested it extensively, but it seems to work nicely. To evaluate a script just press ctrl+e  or run it from the plugin-dropdown.

I compiled it using the ephere wrapper for max 2012, so it will only work  in that version.

To use it you need to download and install the ephere .Net wrapper and enable .Net remoting inside 3ds max.

Then download the plugin and place it in the plugin folder of an unicode version of notepad++. You also need to copy the Autodesk.Max.dll and Autodesk.Max.Remoting.dll to notepad++’s root folder.

Download

Some new schtuff

A seldom update!
School is hogging all my time so there is not much time to do Max related stuff anymore. Nonetheless, I got three new things to show:

  • Tetrahedralization in Max using TetGen
  • A scripted procedural setup in particle flow for rigging ships plowing through ice.
  • A 2D fluid solver implemented in XNA.

Tetrahedralization in Max using TetGen

I came over this article over at cgtalk and it was an interesting read. The tetrahedralization was new to me, and I started looking at TetGen and how I could interact with it using max. TetGen is a program to generate tetrahedral meshes of any 3D polyhedral domains. TetGen generates exact constrained Delaunay tetrahedralizations, boundary conforming Delaunay meshes, and Voronoi partitions. So I compiled the source files and wrote a maxscript that talks to the cmd line interface using dotNet. The scripts exports a mesh to the .off format, feeds it to TetGen who outputs a .ele and a .node file which Max reads and meshes. The bottleneck is creating the mesh in max. A tip is to check the “Single result mesh”. It gives you a single mesh where the tetrahedrons are created as elements and not as separate nodes. Creating 30K tetrahedrons takes about 4 seconds on my machine when creating as a single mesh. Creating separate nodes for each tetrahedron takes much longer; 4-5K nodes takes 4-5 seconds, 12K nodes takes 40 seconds. So there is a big overhead creating nodes using maxscript.

Cue boring video showing internall structure of a tetgen mesh:

Download tetGen2Max

Scripted procedural setup in particle flow for rigging ships plowing through ice.

Got hired to write some scripts to ease the setup and animation of ships plowing through ice.

Some key points for the system:

  • Support huge scenes > 1k m.
  • Arbitrary number of agents(boats)
  • Quick setup/rigging
  • Easy to make changes / easy iteration => procedural

I came up with some different solutions, but landed on particle flow mixed with agents with custom attributes, mainly because it made it easy to work fully procedural. Doing a rigid body system was out of the question due to the huge scales of the scenes and multiple interactions from the different boats. The user first specifies the number of agents in the system and the scripts creates them. An agent is a shape node with custom attributes linked to helpers for ice crack progagation, ice collision and ice deletion, and parameters for additional settings.

An agent with it's custom attributes

The heart of the system is the particle flow system. It is created after the user have specified the number of agents, which is the only requirement for it to be created. Everything else is customisable. The pflow system consist of mainly four parts: The particle creation, mesh cracking propagation, mesh collision and mesh deletion.

The particle creation is a scripted birth operator sampling mesh objects from the scene to particles. The user writes the common name of the mesh objects to be turned into particles in a custom attribute textfield found on the particle system. Scrubbing the slider now shows the mesh objects being controlled by particles. The original mesh objects are hidden and are not affected. This is because the system needs a reference point for sampling the mesh each time the slider is set back to the starting frame, thus restarting the system.

The next part of the system is the crack propagation check. Each of the agents has a node (by default a sphere deflector) that the pflow setup checks for collision against. If there is a collision the mesh is scaled based on it’s distance to the agent, creating larger cracks near the agents. This is done by a scripted operator.

Showing crack propagation initiated by the largest spherical deflector, the rotated meshes are the objects that collides with the smallest spherical deflector visible in this picture

The third part is the collision with the agent check. If a collision is detected the particles mesh is rotated perpendicular to the collision node referenced by the agent, this could be a custom mesh e.g. a ship hull. This gives the effect of the ice being cracked alongside the ships side. This is also done by a scripted operator.

The last part is the particle deletion check against the agent’s referenced delete node. Particles coming from the previous part are checked againts this node and deleted on collision.

The pflow setup generated by the script using 10 agents.

Seeing it up close it may not look that impressive, but from a distance it gives a nice effect and it’s fully procedural. E.g. changing the path of the boats, changing the crack propagation size or any of the other custom properties are reflected in the system, and it is easy to add custom behavior using the particle view editor.

A little sample video of the system with two agents. I added some debris flying around and noisy push of the ground downwards creating a nice trail:

Some more tests here.

2D Fluid solver in XNA

Since I messed up the vertex colors I applied some gaussian blur to smooth it over :)

Before the new semester started I decided to do something new and I ended up at looking at fluid solvers. Jos Stam gives this great presentation of his – now over 10 year old – implementation of stable 2D fluids. Converting the solver from C to C# was trivial, though I spent most of the time wrestling with XNA, since it was new to me, to get it to display the fluids correctly.

2D Fluids with the velocity vector field drawn over it

New scripts!

QHull in 3ds max

I stumbled over the http://www.qhull.org/ library and it got some really powerfull features like computing convex hulls, Delaunay triangulation and Voronoi diagrams. Decided to try and get some of these features to 3dsmax, so first of is a 2d Voronoi diagram as a geometric object plugin and a convex hull script. Instead of writing a c# wrapper I took an easy workaround piping the output from the cmd window into 3dsmax using .net. I guess there is some extra overhead doing it this way, but compared to the meshing time in max, it is miniscule. For the 2d voronoi diagram you can interactivly change the number of points giving a instantly a new diagram/mesh. On my old pc I can mesh a diagram with 2-3k points interactivly.

The second script using qhull is a standard convex hull generator. I have not tested it against other convex hull generators in max, but I guess it is pretty fast where the meshing part and file IO in 3dsmax is the bottleneck.

I’m planning to add particle support to add points to the 2d voronoi diagram, but I’m having a hard time passing large strings as a argument in the cmd window. For the convex hull I solved it by writing the vertex data to a file and pass that on to qhull. This would not be a good solution for the particles if they are animated, as far as I can see. These two scripts are more like tests than full blow complete scripts, so it may be bugs in them!

Download:qHull2Max.rar

Extract all the files to the same location. If you permanently want to install the geometric plugin in you need to place it in the plugins folder as described in the help file, along with the qvoronoi.exe and rbox.exe files

Jigsaw maker

For fun I made a little jigsaw script. Just specify how many pieces you want and optinally draw a template spline for your pieces to generate a fully random jigsaw.

If you want custom pieces, just draw a line following the constraints described in the script’s help button.

Above: The custom spline is displayed to the left.

When created, add a bevel modifier to get the splines meshed.

Download: JigsawMaker.ms

Updated some of the scripts.

I’ve updated some of my scripts; cocktailGreeble, edgeFinder and flowerCreator.

First of is the flowerCreator:

I created a little utility script for scattering and mass-manipulating flowers.

It is basically a custom scatter function with an optional collision check between the distributed objects.

Then the cocktailGreeble:
I rewrote the most essential parts of the script and added some new ways to shuffle the mesh around. It is also WAY more faster!
A screen showing of the difference between the new shuffling methods:

The same objects with, only relaxed this time:

Some more examples (the top edges where chamfered here)

Edgefinder:
I did some optimizing and it really paid of. It’s much faster now.

Here are some test results with standard settings on:
–Very high mesh complexity——–
NEW EF: 43.786s.
OLD EF: 865.042s.

–Medium mesh complexity——–
NEW EF: 2.484s.
OLD EF: 7.687s.

–Low mesh complexity——–
NEW EF: 1.349s.
OLD EF: 2.852s.

Image of the high complexity mesh I tested it on:

New script! Maxscript extended editor


Added a new script. It adds some features to accompany the maxscript editor.

New script: Get feedback from your scripts inside of Max

Using dotnet you can easily send mails from maxscript. I made a simple script that lets the user fill out a form and have it sent to me as a mail.
Just fill in your credentials and be sure to encrypt your script before you deploy it!
Example usage:

http://folk.ntnu.no/havardsc/scripts/mailClass.ms

Compile on the fly source from various post from Denis Trofimov: http://forums.cgsociety.org/member.php?u=384956

Edit:
If you hate having to handle multiple files when dealing with a rather simple script you can fetch supporting files from the web. E.g. say that you have this nice little script you want to share, and you’d want to have the feedback option within the script. The feedback script needs to be in a separate file because you don’t want to expose your credentials. The solution is to fetch the encrypted feedback script from the web by including this function to your script:

fn fetchFileFromWeb url =
(
    try
    (
        local file =  getFilenamePath (getSourceFilename()) + (filenameFromPath url)
        (dotNetObject "System.Net.WebClient").DownloadFile url file
        fileIn file
        deleteFile file
    )
    catch
        messagebox "Failed fetching file."
)

New script: Embed window as viewport

A small little utility that lets you embed almost any window that is currently opened.
Automatic switch to the embedded view source code by Denis Trofimov: http://forums.cgsociety.org/showthread.php?t=792214


Download

New script: ScriptOrganizer


By request, my first go with dotNet. This script displays a script folder of your choosing in a nice little treeview docked in 3ds max. For features and info click on the image!

EdgeFinder script

A scripts that bakes out a edge map to use in texturing and or to create high poly worn edges meshes from low poly meshes.
Link in image to go to the post.


Direct link to video at Youtube

Updated the fracturator script.


I’ve given the old fracturator script an overhaul. You can now paint directly on the mesh where you want it to fracture. Default fracturing and fracturing with details is the same as before. Renamed it to paintFracture as well. Check out the video below for a quick demonstration.


Direct link to video at Youtube