Jump to content

How can I use properly "BABYLON.ValueCondition"


hit2501
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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));
Link to comment
Share on other sites

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