br4tp1t Posted June 2, 2015 Share Posted June 2, 2015 Hi, ive got a question, because i need to have 400 imported meshes in my scene, im using createInstance at the moment, but first problem came with changing color of clicked element, with instances when i click 1 mesh and change its color, it changes on all meshes i know that i cant change material for each created instance, so ive tried with clone, but its to slow for more elements, so i was trying to make a workaround. First ive created 400 instances, than when someone click on 1 mesh i was trying to dispose this mesh, make a clone of a template make some things that i needed and after someone click on another mesh i disposed the clone and created new instance from template, in theory it should work but in practice it froze the web browser ;] Here is some of mine codevar rackTemplate;BABYLON.SceneLoader.ImportMesh("rack_hp", "./", "rack_hp.babylon", scene, function (newMeshes) { newMeshes[0].scaling = new BABYLON.Vector3(0.1, 0.1, 0.1); rackTemplate = newMeshes[0].clone("rackTemplate"); newMeshes[0].dispose(); rackTemplate.id = "rackTemplate"; rackTemplate.isVisible = false; rackTemplate.material = new BABYLON.StandardMaterial("rackMaterial", scene); rackTemplate.material.diffuseColor = new BABYLON.Color3(0.30, 0.30, 0.30); for (var index = 0; index < 600; index++) { var newInstance = rackTemplate.createInstance("rack" + (index)); newInstance.id = "rack" + (index + 1); newInstance.position = new BABYLON.Vector3(index * 7, 9, 0); } });//EVENTSvar startingPoint;var currentMesh;var prevObjectMaterialDiffuseColor;var onPointerDown = function (evt) { if (evt.button !== 0) { return; } // check if we are under a mesh var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) { return mesh !== ground; }); if (pickInfo.hit) { if (currentMesh != null && currentMesh != undefined) { var newInstance = rackTemplate.createInstance(currentMesh.id); newInstance.id = currentMesh.id; newInstance.position = currentMesh.position; newInstance.isVisible = true; currentMesh.dispose(); } var objectId = pickInfo.pickedMesh.id; var objectPosition = pickInfo.pickedMesh.position; pickInfo.pickedMesh.dispose(); var rackClone = rackTemplate.clone(objectId); rackClone.id = objectId; rackClone.position = objectPosition; rackClone.isVisible = true; rackClone.material = new BABYLON.StandardMaterial("objectMovingMaterial", scene); rackClone.material.diffuseColor = new BABYLON.Color3(0.10, 0.80, 0.10); currentMesh = rackClone; startingPoint = getGroundPosition(evt); if (startingPoint) { camera.detachControl(canvas); } } }P.S. ArcRotateCamera is not working for me with babylon 2.1 beta but its fine on 2.0 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 2, 2015 Share Posted June 2, 2015 For arcRotate please use 2.1-rc, this should be fixed For your question, please try to reproduce on playground Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 3, 2015 Author Share Posted June 3, 2015 its seems to work on 2.1-rc so never mind about mine question both things are working now GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.