Jump to content

What is the best way to reference an existing Mesh from a function?


Yazheirx
 Share

Recommended Posts

Assuming all I can pass to a function is the major objects (scene, canvas, camera, etc) what is the best way to reference a specific Mesh?  

I am hopeful that I can create a function with a constructor like:

function moveMesh(meshName, scene){
     //select the namedMesh
     victimMesh.position = new BABYLON.Vector3(0,0,0);
}

I will actually create a key set to animate the Mesh move, but I am not skilled enough in JS to know how to select the child object I want.  I know I saw the method in one of the tutorials, but I have watched over 40 hours of tutorials on youtube and can't remember where I saw it.

Link to comment
Share on other sites

You are looking for this: https://doc.babylonjs.com/api/classes/babylon.scene#getmeshbyname
The API docs are a great source, but also hopefully you are using an IDE that has intellisense as well (like VS code).
 

function moveMesh(meshName, scene){
     let victimMesh = scene.getMeshByName(meshName);
     // this will throw an exception, if there isn't a mesh with that name
     victimMesh.position = new BABYLON.Vector3(0,0,0);
}

 

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