jit.model to jit.phys: preserve richness of 3D model (incl. color)

Ritwik Banerji's icon

I'd like to import 3D models into Max and preserve the richness of their colors/shading/etc. while also using them to set/define the shape of a 3D rigid body. I am successful in getting the model to set the shape of a rigid body, but not yet successful in getting the original model's colors/shading/etc to stay intact. I know it is with some combination of jit.phys.body, jit.gl.mesh, and jit.gl.model that I need to work with to accomplish this, but so far I am not sure how this works. Any tips?

Federico-AmazingMaxStuff's icon

Have you tried loading the material (.mtl) file from the model inside jit.gl.material attached to jit.gl.mesh?

Federico-AmazingMaxStuff's icon

Have you tried loading the material of the model (.mtl) in the jit.gl.material attached to the jit.gl.mesh?
Or directly into the jit.gl.model if you are not using jit.gl.mesh.

Rob Ramirez's icon

yeah would be useful to know more specifics. loading a model file into jit.gl.model will preserve it's material and color settings (adjust @material_mode to your needs).

attaching a rigid body to the mesh of a model file can be done in several different ways. the most performant is to pick 1 or more simple shapes that can enclose the body. more complex is to output the mesh geometry (via matrixoutput) and use that to create a concave mesh. And the least performant, yet most physically accurate is to use the mesh geometry to create a concave mesh.

synching the model to it's rigid body and applying appropriate transform offsets is easily achieved via jit.anim.node:

Max Patch
Copy patch and select New From Clipboard in Max.

Federico-AmazingMaxStuff's icon

Cool Rob!
Could you expand a bit on this concave mesh thingy?

Rob Ramirez's icon

more than what's in the phys.body help patch (matrix tab) and ref page (shape attribute)? you can also check out the phys.body.concave.maxpat example patch.

what are you curious about?

Federico-AmazingMaxStuff's icon

That's great Rob! That's definitely enough info, I never really delved into the physics stuff, but there is really so much cool stuff there!

Ritwik Banerji's icon

Thanks! What I would like to do is build a model using another platform (Blender, etc.), import it to Max, and use it as a landscape that one can traverse. Thus the dynamicmesh or concave mesh option is unfortunately what I'm looking for. I've gotten that part to happen, but I'm still struggling with how to give things some nice texturing.

Ritwik Banerji's icon

Ok so thanks again for posting that model to work with above! I've made some progress on this: I'm getting the shape I import to a model to shape the jit.phys object's shape (check) and then also getting some color/material information to show up as well (check).
So it's "working," except there is a problem when I use a .obj file (not sure if that's the cause). I get an error: "jit.gl.model: jit_ob3d_drawimmediate: GL Error: Invalid value"

What am I missing here?

rework rr suggestion.maxpat
Max Patch

Rob Ramirez's icon

hard to say what the errors are related to without having the file. One change I'd recommend is to disable automatic mode on the jit.gl.model and instead use a bang to send the matrix geometry out only when needed (usually only if the geometry changes, e.g. you're reloaded a model file).

Ritwik Banerji's icon

The strangest problem I have is that with .dae there are major transform issues -- the shape loads as the constraint i want but i can't do anything to easily get the animated shape to map to the constraint shape itself without lots of guessing and adjusting. with .obj, no problem: shape loads as constraint and model appears (animation) as the same physical constraint. what's wrong with dae? is there a way that i'm not exporting from blender correctly?

Ritwik Banerji's icon

Also whenever I try to load an .mtl file into jit.gl.model I get this error:
jit.gl.model: unable to load Jitter material file untitled.mtl

Rob Ramirez's icon

you can send file to me privately if preferred, email link in avi

Ritwik Banerji's icon

Alright: so what appears to be happening as well is that I'm actually able to load the textures just fine using a .obj file and I don't have an error message (a running one at least) when I use .obj to set the shape of the physical object and .dae (of the same shape/Blender file) to set the actual animation (not physical constraint).

The issue is that all the nice materials I can build in Blender don't show up when I load the .obj in Max. This isn't necessarily a problem since I can use jit.gl.material to get some nice materials, but Blender seems to build some much more sophisticated materials?