Python Export from C4D Help

So is there anyway to get more details on why this object would be failing to load?

I am trying to get a basic exporter written up from c4d, and am pretty close I feel like to at least getting the meshes exported.

here is the babylon file I have generated.
{“sceneName”:“My Scene”,“producer”:{“exporter_version”:“0.1”,“version”:18011,“name”:“Cinema4D”,“file”:“MyScene.babylon”},“autoClear”:1,“shadowGenerators”:[],“cameras”:[],“gravity”:[0.0,-9.81,0.0],“morphTargetManagers”:[],“skeletons”:[],“lights”:[],“materials”:[],“meshes”:[{“indices”:[0,1,3,2,3,5,4,5,7,6,7,1,1,7,5,6,0,2],“positions”:[-98.8,-98.8,-98.8,-98.8,98.8,-98.8,98.8,-98.8,-98.8,98.8,98.8,-98.8,98.8,-98.8,98.8,98.8,98.8,98.8,-98.8,-98.8,98.8,-98.8,98.8,98.8],“normals”:[],“name”:“Cube”,“id”:0}],“clearColor”:[0.5215686559677124,0.30588236451148987,0.47058823704719543],“multiMaterials”:[],“ambientColor”:[0.0,0.0,0.0]}

There is prolly some defaults that I need to include what is the bare minimum I can go with?

After reading this, I think I might need to make some changes to the way that I do this and start with the basic stuff like adding a sphere and box instead of a geometry object.
actually think I might have it figured out, but any input will be nice.

Here we go… but allas no Cube Appears in my scene when I use
BABYLON.SceneLoader.ImportMesh(null, “./”, “MyScene.babylon”, scene, function (meshes) {}
It does appear in the inspector, but other then that I don’t see anything.

{“sceneName”:“My Scene”,“producer”:{“exporter_version”:“0.1”,“version”:18011,“name”:“Cinema4D”,“file”:“MyScene.babylon”},“autoClear”:1,“shadowGenerators”:[],“cameras”:[],“gravity”:[0.0,-9.81,0.0],“morphTargetManagers”:[],“skeletons”:[],“lights”:[],“materials”:[],“meshes”:[{“subMeshes”:[],“uvs”:[],“billboardMode”:0,“name”:“Cube”,“positions”:[-0.494,-0.494,-0.494,-0.494,0.494,-0.494,0.494,-0.494,-0.494,0.494,0.494,-0.494,0.494,-0.494,0.494,0.494,0.494,0.494,-0.494,-0.494,0.494,-0.494,0.494,0.494],“isEnabled”:true,“normals”:[],“checkCollisions”:false,“materialId”:false,“scaling”:[1.0,1.0,1.0],“isVisible”:true,“indices”:[0,1,3,2,3,5,4,5,7,6,7,1,1,7,5,6,0,2],“position”:[0.2882779033425892,0.48743946727828097,0.0],“rotation”:[0.0,0.0,0.0],“id”:5413169845416503088}],“clearColor”:[0.5215686559677124,0.30588236451148987,0.47058823704719543],“multiMaterials”:[],“ambientColor”:[0.0,0.0,0.0]}

Do you mind using it into a playground?
I could easily debug what’s wrong then
And btw thanks for working on a c4d exporter:)

^_^… it was needed.

I was sitting here trying to learn blender just so I could export out some skeletons and its like kinda frustrating being a c4d user who can do anything in that software but then the second I get into blender I feel like I am half brain dead…

Plus I did not realize I knew python as well as I apparently do… Its been kinda hard picking through the c4d SDK as well its kinda wordy and not in a good way or in a nomenclature that I recognize.

Ill toss up a PG here today. If I get the meshes exporting Ill do the materials next, then Imposters and clones…

1 Like

wonderful, I’ll check that asap

Ok found. The mesh has no submeshes :slight_smile:
To create a mesh you first need to create a vertexData object and then call applyToMesh to get all additional info set up.

Like here: Babylon.js/boxBuilder.ts at master · BabylonJS/Babylon.js · GitHub

How does that work from and exporting standpoint?

Like what is the barebones setup to make any mesh work?


When do I need to include multiple subMeshes? Kinda just realized I don’t understand their relation.

Yes as you have one material per mesh then you should just have one submesh covering the entire mesh.

so submeshes are the vertices separated for additional draw calls because they have a different material assignment?

but as a whole they make up the mesh?
Can you reuse vertices?

You are correct

Yes totally and that is the goal

Ok, well I am working on the material conversion then and making a interface for the assigned materials hopefully through xpresso.

That way I can build a “assigned Materials” object that I can reference to when compiling the meshes.

Got a little more complicated now because that means I have grab all of the objects tags now and see if there is a texture tag and a polygon group tag because that would determine the submeshes.

1 Like

So I am getting a [.WebGL-000001E8D8992EB0]GL ERROR :GL_INVALID_OPERATION : glDrawArrays: attempt to access out of range vertices in attribute 1

Not sure where to go from here cause:

Looks like its structured correct and has all the data that it should need. Maybe I’m missing something now?

At least the wireframe shows up…
Do I need normals too?

I confirm
You need normals and positions in the file:

If is any help, the structure of the Blender could be a good starting point, if you know the structure & why it is that way.

Each asset type has its own file, but the key thing is that it is a multi-pass process. The first pass gets everything out of the environment into a near Babylon format, e.g. Left handed - Y up. This is done in the constructor of each of the output classes. Matrices of all the instance of the meshes, lights, skeletons, materials, and cameras are accumulated from the first pass.

The 2nd pass creates the output file, then passes through all the objects collected from the first pass, and executes the to_json_file() on each class.

If you hollow out each class’es constructor & replace it with how you gets stuff from their API, then you can use the to_json_file() to write “legal” files without getting all your brackets, commas, and most importantly fields that are needed.

There is also another file which has all the writing functions called Package_level. All the to_json_file()'s call functions to write out each of the data types, e.g. write_matrix4, write_color, write_vector, write_quaternion, & more.

They also limit the number of significant digits, which can greatly reduce the size of the file, but you could also just set the defaults to the max, if you have a problem with that.

Finally, why is this being done this way? The biggest reason is I also have my own Javascript exporter. I have all the same files, except there is a to_js_file() called in the second pass. 95% of the constructor’s are the same. You would be just flipping which part gets reused, if using this as a starting point.

The overall flow control is this file. Technically, the “first pass” is actually multiple passes in itself. This to allow for example all skeletons to be processed first. When meshes run in the next mini-pass, things like ignoring IK bones is a lot easier to do.

Hope this helps.

1 Like

Well I got the first steps happening!

Ill keep y’all update… I was doing some reading this morning and I might not even really need to do all this with r20’s new gltf exporter. Plus if I really wanna dig into this, I need to start doing it in C, and do it as a plugin instead of a script and xpresso tag.

1 Like

Can you explain that more? I get the idea of the two passes though for sure I am currently handling it in one, and was thinking about changing the structure, would there be anything inherently wrong with doing it in a single pass?

This is REALLY cool!

In addition to code re-use, keeping separate objects & isolating reading from writing makes the code a lot more understandable & less complex, especially for meshes in the Blender case.

It might not apply in your case, but for multi-materials Blender does not have multiple vertices when a vertex is on a border of different materials. Writing out each position, normal, vertex color, UV1, UV2, matrix index & weight as each value is acquired would really be messy.

It is really a matter of the complexity required as more and more functionality gets added. Efficiency can also be enhanced. People leave all kinds of stuff in their Blend scenes which does not need to be exported. Biggest example is materials. I could just go down the array of materials & write them all out, but I only do so as they are encountered with a mesh. You need to put in a small check to keep materials from being exported more than once, but other un-used materials are not exported.

1 Like