hit2501 Posted February 23, 2015 Share Posted February 23, 2015 Hi.Im having some problems when I try to do a condition to run an animation while "onoff" is zero, with the condition nothing happens. I think Im not using properly the "BABYLON.ValueCondition", this is my code:var onoff = 0; var obj1 = scene.getMeshByName("Knob");var obj2 = scene.getMeshByName("Curtains");var obj3 = scene.getMeshByName("Fire");var obj4 = scene.getMeshByName("Solid");var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false }); var COND1 = new BABYLON.ValueCondition(obj3.actionManager, obj3, "onoff", 0, BABYLON.ValueCondition.IsEqual); obj3.actionManager = new BABYLON.ActionManager(scene);obj3.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj4, 0, 360, 0), new BABYLON.PlaySoundAction(BABYLON.ActionManager.NothingTrigger, audio), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { onoff = 1; console.log(onoff);}) ], COND1) ).then(new BABYLON.StopSoundAction(BABYLON.ActionManager.OnPickTrigger, audio));Thank you all. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 23, 2015 Share Posted February 23, 2015 ValueCondition checks value on a specific propery. This should work:obj3.onoff = 0; var obj1 = scene.getMeshByName("Knob");var obj2 = scene.getMeshByName("Curtains");var obj3 = scene.getMeshByName("Fire");var obj4 = scene.getMeshByName("Solid");var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false }); var COND1 = new BABYLON.ValueCondition(obj3.actionManager, obj3, "onoff", 0, BABYLON.ValueCondition.IsEqual); obj3.actionManager = new BABYLON.ActionManager(scene);obj3.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj4, 0, 360, 0), new BABYLON.PlaySoundAction(BABYLON.ActionManager.NothingTrigger, audio), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { obj3.onoff = 1; console.log(onoff);}) ], COND1) ).then(new BABYLON.StopSoundAction(BABYLON.ActionManager.OnPickTrigger, audio)); hit2501 and julien-moreau 1 1 Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 24, 2015 Author Share Posted February 24, 2015 Sorry DK dont worked. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 24, 2015 Share Posted February 24, 2015 Can you repro on the playground? This will be easier for me to test Quote Link to comment Share on other sites More sharing options...
hit2501 Posted February 25, 2015 Author Share Posted February 25, 2015 Sorry I dont know how to do that but I put my complete code: I tried to do it with an "if" statement instead of condition in different ways but it did not work, you think its possible to use: " if(onoff == 0){ " ?<!DOCTYPE html><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Action</title> <!-- Babylon.js --> <script src="js/hand.minified-1.2.js"></script> <script src="js/cannon.js"></script> <script src="js/oimo.js"></script> <script src="js/babylon.js"></script> <script src="js/babylon.2.0.beta.js"></script> <style> html, body { overflow: hidden; width: 100%; height: 100%; margin: 0; padding: 0; } #renderCanvas { width: 100%; height: 100%; touch-action: none; } </style> </head><body> <canvas id="renderCanvas"></canvas> <script> var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var onoff = 0; var createScene = function () { var scene = new BABYLON.Scene(engine); var uselessCamera = new BABYLON.ArcRotateCamera("nothing", 0, 0, 2, new BABYLON.Vector3(0,0,0), scene); BABYLON.SceneLoader.Load("WonDoor/", "Prueba01.babylon", engine, function (newscene){ scene = newscene; scene.executeWhenReady(function () { var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.0, scene); var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene); skyboxMaterial.backFaceCulling = false; skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("skybox/skybox", scene); skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0); skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0); skybox.material = skyboxMaterial; var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); scene.activeCamera = camera; scene.activeCamera.attachControl(canvas); scene.activeCamera.keysUp.push(87); // W scene.activeCamera.keysLeft.push(65); // A scene.activeCamera.keysDown.push(83); // S scene.activeCamera.keysRight.push(68); // D camera.setTarget(BABYLON.Vector3.Zero()); camera.attachControl(canvas, true); camera.speed = 0.5; //##################### ACCIONES ######################## var obj1 = scene.getMeshByName("Knob"); var obj2 = scene.getMeshByName("Curtains"); var obj3 = scene.getMeshByName("Fire"); var obj4 = scene.getMeshByName("Solid"); var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false }); var objA = scene.getMeshByName("Knob2"); var objB = scene.getMeshByName("Curtains2"); var objC = scene.getMeshByName("Solid2"); objA.setEnabled(false); objB.setEnabled(false); objC.setEnabled(false); obj3.actionManager = new BABYLON.ActionManager(scene); var cond1 = new BABYLON.ValueCondition(obj3.actionManager, obj3, "", 0, BABYLON.ValueCondition.IsEqual); obj3.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj4, 0, 360, 0), new BABYLON.PlaySoundAction(BABYLON.ActionManager.NothingTrigger, audio), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { onoff = 1; console.log(onoff); }) ]) ).then(new BABYLON.StopSoundAction(BABYLON.ActionManager.OnPickTrigger, audio)); obj1.actionManager = new BABYLON.ActionManager(scene); obj1.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { objA.setEnabled(true); objB.setEnabled(true); objC.setEnabled(true); obj1.setEnabled(false); obj2.setEnabled(false); obj4.setEnabled(false); }), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, objA, 0, 170, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, objB, 0, 170, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, objC, 0, 170, 0) ]) ); //##################### BOTON IZQUIERDO (To do the same actions)######################## var cameraWrapper = BABYLON.Mesh.CreateBox("cameraWrapper", 1, scene); BABYLON.SceneLoader.ImportMesh("", "WonDoor/", "LefButton.babylon", scene, function (newMeshes) { var boxButton = scene.getMeshByName("Plane"); boxButton.position = new BABYLON.Vector3(-4, -2, 6); boxButton.rotation = new BABYLON.Vector3(-1.56, 0.15, -0.2); boxButton.parent = cameraWrapper; scene.registerBeforeRender(function(){ cameraWrapper.position = camera.position; cameraWrapper.rotation = camera.rotation; cameraWrapper.target = new BABYLON.Vector3(-4, -2, 6); }); var audio = new BABYLON.Sound("Fire", "Fire.wav", scene, null, { loop: true, autoplay: false }); boxButton.actionManager = new BABYLON.ActionManager(scene); boxButton.actionManager.registerAction( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { objA.setEnabled(false); objB.setEnabled(false); objC.setEnabled(false); obj1.setEnabled(true); obj2.setEnabled(true); obj4.setEnabled(true); }), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 0, 360, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj4, 0, 360, 0), new BABYLON.PlaySoundAction(BABYLON.ActionManager.NothingTrigger, audio), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { onoff = 1; console.log(onoff); }) ]) ).then( new BABYLON.CombineAction(BABYLON.ActionManager.OnPickTrigger, [ new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { objA.setEnabled(false); objB.setEnabled(false); objC.setEnabled(false); obj1.setEnabled(true); obj2.setEnabled(true); obj4.setEnabled(true); }), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj1, 360, 720, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj2, 360, 720, 0), new BABYLON.PlayAnimationAction(BABYLON.ActionManager.NothingTrigger, obj4, 360, 720, 0), new BABYLON.StopSoundAction(BABYLON.ActionManager.OnPickTrigger, audio), new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.NothingTrigger, function () { onoff = 0; console.log(onoff); }) ]) )}); //##################### BOTON DERECHO (To refresh the page) ######################## var cameraWrapper2 = BABYLON.Mesh.CreateBox("cameraWrapper2", 1, scene); BABYLON.SceneLoader.ImportMesh("", "WonDoor/", "RightButton.babylon", scene, function (newMeshes) { var boxButton2 = scene.getMeshByName("Plane2"); boxButton2.position = new BABYLON.Vector3(4, -2, 6); boxButton2.rotation = new BABYLON.Vector3(-1.55, 0.1, -0.1); boxButton2.parent = cameraWrapper2; scene.registerBeforeRender(function(){ cameraWrapper2.position = camera.position; cameraWrapper2.rotation = camera.rotation; }); boxButton2.actionManager = new BABYLON.ActionManager(scene); boxButton2.actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { window.location.reload(); }) ); }); //##################### RENDERER ######################## engine.runRenderLoop(function() { scene.render(); }); }); }, function(progress) { } ); return scene; } var scene = createScene(); engine.runRenderLoop(function () { scene.render(); }); window.addEventListener("resize", function () { engine.resize(); }); </script></body></html> Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 25, 2015 Share Posted February 25, 2015 To use the playground, just go there: www.babylonjs.com/playground and recreate your problem 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.