Jump to content

using a function to clone a complex mesh


TheComputerGuy
 Share

Recommended Posts

i using the dude complex mesh for an example.. but im trying to have him loaded as main player then be able to clone him with skeleton on keydown to test the clone ability. here is what i got....

        // Dude        BABYLON.SceneLoader.ImportMesh("him", "models/", "Dude.babylon", scene, function (newMeshes, particleSystems, skeletons) {            newMeshes[0].position = new BABYLON.Vector3(0, 0, 5);  // The original dude            var dude = newMeshes[0];            dude.scaling = new BABYLON.Vector3(0.05,0.05,0.05);               CREAT = dude;			_CREAT = skeletons[0];			follow.target = CREAT; // target 		});window.addEventListener("keydown", function (evt) {        switch (evt.keyCode) {            	        case 83:			createdude();			break;			default: 					break;        }var createdude = function () {		dudes = [];        var xrand = Math.floor(Math.random() * 501) - 250;        var zrand = Math.floor(Math.random() * 501) - 250;            var c2 = CREAT.clone(CREAT.name);			c2.id = CREAT.name+(dudes.length+1);            c2.position = new BABYLON.Vector3(xrand, 0, zrand);            c2.skeleton = _CREAT.clone();            scene.beginAnimation(_CREAT, 0, 120, 1.0, true);            };

when i execute my code.. i get no errors in the console and nothing happens? what might i be doing wrong...  my main character loads but thats it. ty for all the help.

Link to comment
Share on other sites

yes, https://gamesite.x10.mx/avaworld/ and the key that should clone is the "s" key... ty

 

As far as I can tell, you're using the same name for both meshes. Try changing the name.

 

The error is

Uncaught TypeError: Cannot read property 'applyToMesh' of undefined babylon.1.14-beta-debug.js:7791Mesh.clone babylon.1.14-beta-debug.js:7791createdude Game.js:179(anonymous function)
Link to comment
Share on other sites

The problem is not the name here.

 

Actually, the object CREAT represents a dummy object, and thus has no geometry. If you try to clone it, it won't work. 

However, I think this case should be handled by babylon... @Deltakosh, what do you think ?

 

So, should i make dude a global var and use it instead of the CREAT?

Link to comment
Share on other sites

No, the problem is not the CREAT problem. The problem is that CREAT is a reference to newMeshes[0], and newMeshes[0] has no geometry.

You should clone newMeshes[1], [2], ..., but not [0].

So, if i understand right, the CREAT allows me to adjust position and what not but not the actual mesh. The reason i ask is because i am able to make changes to dude like position and such. Would you possibly be able to show me an example to how i could reference the correct mesh? ty either way :)

Link to comment
Share on other sites

I figured it out...

var createdude = function () {		dudes = [];        var xrand = Math.floor(Math.random() * 501) - 250;        var zrand = Math.floor(Math.random() * 501) - 250;        var c = [];		for (j = 1; j < newMeshes2.length; j++) {            c[j] = newMeshes2[j].clone("c" + j);            c[j].position = new BABYLON.Vector3(xrand, 0, zrand);			c[j].scaling = new BABYLON.Vector3(0.05,0.05,0.05);             c[j].skeleton = newMeshes2[j].skeleton.clone();            scene.beginAnimation(c[j].skeleton, 0, 120, 1.0, true);        }		    };

ty for all your help :)

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