Jump to content

Rotate , get Vertices from loeader object


Arktius
 Share

Recommended Posts

Hey guys,

I want to edit the loading Object in the following code. I want to rotate it or to set the vertices and normals. I tried it with "this" .

 BABYLON.SceneLoader.Load(document.getElementById("path").value, document.getElementById("name").value, engine, function (scene) {
              
                    // Ground
                    var ground = BABYLON.Mesh.CreateGround("ground", 15,15, 1, scene, false);
                    var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
                    groundMaterial.specularColor = BABYLON.Color3.Black();
                    ground.material = groundMaterial;
                    //ground.rotation.x += Math.PI/2 ;
                    //ground.rotation.y += Math.PI/2 ;

                    // Light
                    var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(, 1, ), scene); //newScene
                    light1.intensity = 0.4 ;

                    var cam = new BABYLON.VirtualJoysticksCamera("VJC",new BABYLON.Vector3(, 4, -10) , scene);
            
                    //Attach a camera to the scene and the canvas
                    scene.activeCamera = cam;
                    cam.attachControl(canvas, false);

                    //this.rotation.y -= 35;<---- ?


                    // Render
                    engine.runRenderLoop(function () {
                        scene.render();
                    });
                    // Resize
                    window.addEventListener("resize", function () {
                        engine.resize();
                    });

                }); // Babylon loader
Link to comment
Share on other sites

Hi Arktius!

    I am not very experienced with sceneLoader, but "exposing" the model (so it can be rotated, and vertices adjusted)... is not always easy.  Many users have problems getting a "reference" to a model, after it's loaded.  SOME of the problem... is with waiting for the model to complete it's loading.  Some of the problem is escaping from the load's callback function.

Perhaps, this playground will help:  http://www.babylonjs-playground.com/#1GEYSB#2

I wish I was smarter in this subject.  But I don't even know when to use .ImportMesh(), or when to use .Load(), or when to use Append().  I have yet to see a clear explanation of it all, too.  Every time I load a mesh, the mesh seems "trapped" inside the callback function.  In the above demo, I used a scene.executeWhenReady()... to ensure everything was done.  Maybe it is necessary, maybe not. 

Perhaps someday, the puzzling world of sceneLoader... will become less puzzling. 

I hope this helps.  Let's hope smarter people than I... will also comment.  :)  Be well.

Link to comment
Share on other sites

var model = BABYLON.SceneLoader.Load(document.getElementById("pfad").value, document.getElementById("name").value, engine, function (scene) {
 scene.executeWhenReady(function () {
        scene.getMeshByName(document.getElementById("name").value).position.y = 8;
        scene.registerBeforeRender(function () {
          //Code...
        });
    });


    // Render
    engine.runRenderLoop(function () {
        scene.render();
    });
    // Resize
    window.addEventListener("resize", function () {
        engine.resize();
    });

}); // Babylon loader

 

I get the message,that getMeshByName(...) ISNULL. Same error with .getMeshByID(0) ,(1) or if I move the Code after the SceneLoader.

:-/

Link to comment
Share on other sites

9 hours ago, Deltakosh said:

Hello and welcome!

the Load function callback give you the loaded scene. You can just use scene.getMeshByName for instance to find the mesh you want to control


@Arktius  Not trying to hijack your thread, but I was just about to ask about this. More or less, except at the basic, "how do i alter a mesh inside an imported scene".

@Deltakosh  I know that SceneLoader.Append is preferred over Load.

http://www.babylonjs-playground.com/#F8ZO#10

What I was going to ask is, Is the onSuccess callback the only way to manipulate meshes in an imported scene? Along with Arktius' question, I'm also not able to access the mesh with getMeshById. though I tried it on Append and ImportMesh, not sure if it applies to those anyway. Responses to @Arktius will hopefully answer my questions. In the playground scene above, Load won't even work with my github url & file, though Append and Import Mesh both work.

My goal is to use it for a visualization, but was just going to make sure i could do something with it first, like:

var speaker1 = mesh.getMeshById("Torus.002");
speaker1.position.y = 100;

or however, within the callback.

 

Link to comment
Share on other sites

Try this:

 

//shows scene
BABYLON.SceneLoader.ImportMesh("", "https://raw.githubusercontent.com/gson78/miscWebGLpages/gh-pages/blender-scenes/", "custom-speakers2.babylon", scene);        

BABYLON.MeshBuilder.CreateTorus("torus", {thickness: 0.2}, scene);
var speaker1 = scene.getMeshByName("torus");
speaker1.position.y = 4;
speaker1.position.x = 1;

Link to comment
Share on other sites

console.log(scene.meshes);
var i = ;
while (scene.meshes[i] != null)
{
    console.log("Mesh[" + i.toString() + "]" + scene.meshes[i].name);
    //alert(scene.meshes[i].name);    Messagebox
    i++;
}

 

This shows all the names of meshes. I don't know if a counter exists.

The Output is in the console from Browser. (press F12 and look in console)

Link to comment
Share on other sites

9 hours ago, Arktius said:
console.log(scene.meshes);
var i = ;
while (scene.meshes[i] != null)
{
    console.log("Mesh[" + i.toString() + "]" + scene.meshes[i].name);
    //alert(scene.meshes[i].name);    Messagebox
    i++;
}

 

This shows all the names of meshes. I don't know if a counter exists.

The Output is in the console from Browser. (press F12 and look in console)

contemplated doing something like that and then just did    scene.debugLayer.show()    from david's post above.

LOVE IT its so great. You just select "meshes tree" and it shows a box with all the mesh names.

i may need the console trick someday when i'm not using babylon

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...