Jump to content

load mulpitle objects .babylon to scene with heightmap, skybox etc


Mira
 Share

Recommended Posts

Ty,

 

BABYLON.SceneLoader.ImportMesh("", "mesh/3/", "3.babylon", newScene, function (newMeshes) {

    newMeshes[0].position = BABYLON.Vector3.Zero();

});

 

BABYLON.SceneLoader.ImportMesh("", "mesh/tulpan/", "tulpan.babylon", newScene, function (newMeshes) {   

    newMeshes[0].position = new BABYLON.Vector3(-66,15);
    newMeshes[0].scaling  new BABYLON.Vector3(0.10.10.1);
});

 

BABYLON.SceneLoader.ImportMesh("", "mesh/dfk/", "dfk.babylon", newScene, function (newMeshes) {   
    newMeshes[0].position = new BABYLON.Vector3(14.59, -24.5);

});

Link to comment
Share on other sites

I tried. 

Also I tried to remove the first object from scene: who is resourse for all textures, so in result surface textures that were occupied with the first object, were empty

 
so I think that somehow they are stored in each object maybe when first loaded
I tried to clear the cache, but it doesn't work 
Link to comment
Share on other sites

From Mira's last two posts:

 

1.meshes have right ID but they have used texture from scene whose that loaded first

 

2. I think that somehow they are stored in each object maybe when first loaded

 

Yes the "meshes" contain a reference to its materials for example:

{"name":"tulpan","id":"tulpan","materialId":"Multimaterial#0" ....and{"name":"dfk","id":"dfk","materialId":"Multimaterial#0" ...

(Open a babylon file in a text editor and search for "meshes".)

 

Each one makes a reference to "Multimaterial#0" (a description of which you can find at the end of the babylon file. So if you are trying to load three different meshes there will be three "Multimaterial#0". No idea what impact this will have on your scene but may explain - "they have used texture from scene whose that loaded first" - maybe the coders on here can help.

 

With that said, there is another thread that seems to be related :

 

Multimaterial problem with Blender exporter

 

is there any one realize that if you load some .babylon file with multi material mesh , and then add mesh to this scene by import next multi material mesh from another .babylon, second loaded mesh will take material from multi material loaded on beginning.

 

 

Might be an explanation, though not a fix, for what you are seeing.

 

cheers, gryff :)

Link to comment
Share on other sites

When you said multi material, I then knew what the problem was. 

 

Background: Babylon & Blender both have a shared/named list of single materials in which some may contain textures.  In Babylon, a mesh has either one of the single materials or a multi material(which is also shared/named), but the Blender API always assumes a mesh has a multi materials, and they are not shared.  It just so happens that somettimes there is just one entry in the blender List of materials for a mesh.  There is also no need to name this materials list for each mesh, since it is not shared.

 

The python script writes out a multimaterial for each mesh with more than 1 material in it.  It gives it an arbitrary name of Multimaterial#N, where N is a counter.  All works ok unless 2 .babylon files with multi materials is loaded into the same scene.

 

Mira, you can both confirm this hypothesis and give your self a temp fix, by editing one of the .babylon files in like Wordpad.  Do a replaceall from "Multimaterial#0" to "Multi-me-baby".  If that works there are many different places this could be fixed & a new thread should probably be started.

 

My 2 cents would be to change the python script with the following changes which will make highly improbable that a name collision will ever occur by adding the # of milliseconds since Jan 1, 1970:

 

import time

...

class Export_babylon(bpy.types.Operator, ExportHelper):

    multiSeed = int(time.time() * 1000)

...

        elif len(object.material_slots) > 1:
            multimat = MultiMaterial()
            multimat.name = "Multimaterial#" + str(len(multiMaterials) + multiSeed) # add seed to index for uniqueness
            multimat.materials = []
            Export_babylon.write_string(file_handler, "materialId", multimat.name)
            for mat in object.material_slots:
                multimat.materials.append(mat.name)
                 
            multiMaterials.append(multimat)
            billboardMode = 0

 

Link to comment
Share on other sites

Youir suggestion seems to work fine Jeff - I changed the files dfk babylon and tulpan.babylon to have Multimaterial#1 & 2 respectively. Result - see image below.

 

There are still a couple of small issues - the big windows of the church-like building are missing. This maybe due to the fact that the tulpan babylon file defines one material this way:

{"name":"Translucent_Glass_Safety","id":"Translucent_Glass_Safety","ambient":[0.3765,0.2784,0.0275],"diffuse":[0.3012,0.2227,0.0220],"specular":[0.1650,0.1650,0.1650],"specularPower":50.0000,"emissive":[0.0000,0.0000,0.0000],"alpha":0.9700,"backFaceCulling":true,"diffuseTexture":{"name":"Translucent_Glass_Safety.png","level":1.0000,"hasAlpha":1.0000,"coordinatesMode":0,"uOffset":0.0000,"vOffset":0.0000,"uScale":1.0000,"vScale":1.0000,"uAng":0.0000,"vAng":0.0000,"wAng":0.0000,"wrapU":1,"wrapV":1,"coordinatesIndex":0}}

The files from Mira have no texture called : "Translucent_Glass_Safety.png" but do have a texture called "Translucent_Glass_Safety.jpg" in the tulpan directory.

 

And/or it maybe that the normals for the faces that make up the windows point in the wrong direction. Best suggestion is to go back to the model in Blender and in Edit mode select all faces of the model then Mesh ->Normals->Recalculate Outside.

 

This might also get rid of some of those ugly dark areas for some faces.

 

cheers, gryff :)

post-7026-0-27615100-1402776627.jpg

Link to comment
Share on other sites

Thanks to everyone! Now it works! Not so good, but I hope enough to get a good point for my diploma :)

You can see a part at web-page  http://cit.rusoil.net/index.html on a third item from left on page. I still work on realization camera control cause it work on my localhost but doesn't on web page. You can see what all models have their own texture and I really happy ) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...