A cube (exported from unity default 3d cube obj) seems to have swapped surfaces of in and out in babylon scene


The gray box is from Cube.obj file. And the small purple one in it is made with CreatBox constructor.

As we can see, the gray box has penetrated surfaces, and inside surfaces are only visible but external transparent.

I used ImportMesh to import the obj file. To solve this distorted mesh, I tried
setVerticesData(flip normal),
backFaceCulling and so on.

But nothing worked out…

Also when I tried to change material color of normal cube from glb (converted from max fbx file), it also has same effect.

What should I do? Please help me…

here is my code

BABYLON.SceneLoader.ImportMesh("", "res/", "Cube.obj", scene, function(meshes, particleSystems, skeletons) {
                for (var i in meshes) {
//                var m = scene.getMeshByName('__root__');
                var m2 = scene.getMeshByName('Cube');
//                m2.scaling.z = 20;
//                m.position.y = 3;
//                m.setPositionWithLocalVector(new BABYLON.Vector3(0, 0, 0));
                //m.absolutePosition.y = -10;
//                console.log(BABYLON.Mesh.DOUBLESIDE);
//                m2.material = myMaterial;
//                m2.sideOrientation = BABYLON.Mesh.DOUBLESIDE;
//                m2.material.needDepthPrePass = true;
//                m2.material.alph = 1;
//                var normals = m2.getVerticesData(BABYLON.VertexBuffer.NormalKind);
//                for (var i in normals) {
//                    normals[i] *= -;
//                }
//                m2.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals);
//                m2.material.wireframe = true;
//                m2.backFaceCulling = false;


Also I loaded 3d text in babylonjs using threejs. but when I try to change its color material, its surfaces are broken… what should I do…

Is is wrong to try to put color material? Actually, even I couldn’t find any PG showing the exactly same cases.
I am sure it is very simple to reproduce this bug at your working environment.

Pinging @MackeyK24

I don’t think any of these are actually Unity Exporter issue.

What did you export Cube.obj from ???

Unity Exporter does not create .obj files

Yes, I agree with that. First of all, sorry I forgot to explain the export process.
There are 3 cases.

  1. c# script to export Unity Cube obj
    ExportOBJ - Unify Community Wiki

  2. export threejs 3d text glb file to load in babylonjs

  1. max fbx to glb converter
    GitHub - facebookincubator/FBX2glTF: A command-line tool for the conversion of 3D model assets on the FBX file format to the glTF file format.

If you want, I can share this test project as .zip file. Should I send an email with file?

BTW, I couldn’t find babylon 3d text plugin anywhere, so in the end I had no choice but to try threejs 3d text. If possible, I want to try babylon’s modules to create 3d text.

Well the only thing that is close to one of your export type is the first c# unity export.

But instead of using that Unity wiki code to export obj files… we have the Babylon Editor Toolkit to export directly to .babylon scene files. We have an upcoming version that will export unity content to gltf/glb

That’s what I do … the Unity Exporter for Babylon

Ok… then… currently, it is unstable to try to change materials of meshes loaded from external resources like glb, obj and so on except .babylon extension file.

Also recently I found the newest unityexporter works fine with typescript. Unity also has 3d text asset… I will give it a try with babylon file. Thank you.

I dont think i can support Unity 3D Text as far as a component. You would have to use something that produced actual Unity Meshes. Whether you IMPORTED some 3D text from any other authoring package as FBX or something. But once it gets into Unity as a Mesh… 3D Text or not… I can export it.

I started playing around with TextMeshPro that is now a part of Unity 2019.

It does export the 3D text mesh… but you need to TWEAK the material properties in babylon to get it to like as CLOSE AS POSSIBLE to unity.

Btw… once you have a mesh in Babylon … however it got there, creating native geometry, gltf, obj… whatever… you should be able to change or update any material properties at runtime

Yes that’s the point i am trying to explain. I just used standard material to change colors. But I don’t know why it removes visible surfaces as well. Anyway I will try babylon ext again later and then feed back here. Thank you.

Not sure, I would have to see it… Can you setup a playground… ???

But i can tell you (as the Babylon Toolkit Guy)… A mesh is a mesh is a mesh…

Its the exporter… In your C# Unity ExportOBJ… You might have to go in and make sure your getting (serializing) all the mesh properties… I found that missing or messed up normal and or tangents will effect that material appearance.

Make sure your mesh has at least:

  • positions
  • normals
  • tangents
  • uvs
  • triangles (Indices)
  • vertex colors (if it has any)

These are the main things i pickup when exporting geometry (.babylon or .gltf scene files)

Anyways… try setup a playground so we can check it out… What might be missing from the geometry that is cause the funny material issues you are having :slight_smile:

Wow thank you. But I am also talking about common glb files from 3dsmax. It also has same bug with cube after changing color with babylon standardmaterial. It is also same with threejs glb objects.

So all of them have same reason like the csharp exporter

Thats strange… Try make playground… We (the community) we check it out and try help if we can…

But that seems strange though… I export .babylon and .gltf/.glb scene files all the time… And i have EXTENSIVE custom material and shader support… So my GLTF extension modifies material properties (after the instance of the material has been created) all the time… Including color properties… As a matter a fact… i think i am doing a Linear Color Correction on one of my materials and it works perfect. ot too mention stuff like lightmaps… all after the fact using regular babylon material pipeline code.

So… make a playground and we check it out :slight_smile:

huuu this took me ages!!!

I tried my first PG publicly thanks to your suggestion!!

here is the link Babylon.js Playground

I am sure this shows all my intentions.

I hope this experiments are helpful for your exporter development.

btw, is there any storage services for PG? I couldn’t find any, so I just used my github raw files temporarily.

Yo @Serae_Kim

Pretty simple problem you are having… Here is fixed playground: https://playground.babylonjs.com/#DJFQAD#2

You issue is not the geometry itself but the Material Side Orientation and the HAND-SYSTEMS.

Note… You are import meshes with different hand systems… babylon, gltf and obj.
BABYLON is left handed. I know GLTF is right handed… and apparently OBJ is as well.

Babylon by default is Left-Handed System… I think the default is COUNTER-CLOCKWISE on the materials.

Now what side orientation is setup for the material is normally handled by the system or loader. It also depends on if the the SYSTEM is in Left or Right handed mode: scene.useRightHandedSystem = false is default.

Check docs on left and right handed support and material side orientation. Hope that helps :slight_smile:

Playgrounds are an awesome debug tool :slight_smile:

Perfect method also see https://doc.babylonjs.com/resources/External_PG_assets

This situation exactly applies to the idiom “The darkest place is under the candlestick.”

I already mentioned sideOrientation property from the beginning but I didn’t know how to use it properly.

You saved me. Thank you so much. I want to study more and more.

However, the red box(Cube.obj) lighting is still upside down. I shouldn’t use the csharp exporter…

No don’t use obj Exporter… Use my toolkit… I make way better geometry than that obj exporter :grin:

To @Serae_Kim

I added support for the 3D Text component in Unity … it will serialize the metadata about the 3D text and use the MeshWriter extension to render the text as 3D