Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 Ah, ok. First, lets look at a tiny bit of JS from BABYLON.Light.js... BABYLON.Light = function (name, scene) { BABYLON.Node.call(this, scene); this.name = name; this.id = name; scene.lights.push(this); // Animations this.animations = []; // Exclusions this.excludedMeshes = []; }; Notice that light.name... and light.id... are BOTH set to be 'name'. Also notice that the light is pushed into an array called scene.lights. So, the light you want to 'talk to'... is maybe in scene.lights[0] or maybe scene.lights[1] or... its somewhere in the scene.lights array. But there is a MUCH easier way. Take a look at http://doc.babylonjs.com/page.php?p=24646 Scroll down into the methods area. See the method getLightByID(id) ? Sure ya do. So... lets pretend your light has a name of "switchedlight". Its ID is also the same. To turn the light ON... scene.getLightByID("switchedlight").intensity = 1.0; To turn the light off... just the opposite... scene.getLightByID("switchedlight").intensity = 0.0; Maybe experiment with scene.getLightByID("switchedlight").setEnabled(false or true) too. I have a feeling that you might ask about NOT knowing if the light is currently on or off... but you need to 'toggle' its condition no matter what. JavaScript contains a conditional operator that assigns a value to a variable based on some condition. Here's how you might use that: var mylight = scene.getLightByID("switchedlight");mylight.intensity = (mylight.intensity > 0.0) ? 0.0 || 1.0; The stuff in the parentheses... is a condition question. If the condition is TRUE, use the value on the left side of the OR bars. If NOT true, use the value on the right side of the OR bars. In other words... is my light currently ON (is its intensity > 0.0) ? YES? Then set the intensity to 0.0 (off). Is it OFF (not > 0.0)... then turn it on by setting its intensity to 1.0. Fun with toggling. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 setEnabled must be a function because it has to check if the parent is enabled and if the parent of the parent is enabled and so on. So this can't be a property alas About videotexture I think you're right> Let me fix that for next version Wingnut 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted March 19, 2014 Share Posted March 19, 2014 Hi everyone, I have a request about this discussion: would it be possible to start a new discussion when the subject is not directly linked to the previous subject? I would love to follow this discussion but I feel like we talk about too many things in it and for me it's like this discussion is a whole forum on its own so it's difficult to remember that a specific subject was talked about in this discussion (moreover, on which page?). Please help me to keep reading it Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 Hi gwenael ! (And hi to you too, DK!) Good to hear from you guys, as always. Actually, the subject has remained the same for the entire thread. "Things Wingnut thinks and talks about". But I understand your comment COMPLETELY. I know you are being serious, but it makes me laugh. I wish I had an answer for you. Maybe forum search? I am honored that this thread has become so active and varied. Its more like chat than a forum thread, eh? *nod*. Sigh. Yes, certain subjects really should be "branched", but, I'm not sure when and where to DO that, and this thread might be as popular as it is... BECAUSE its "about any subject, anytime". I don't know. I don't have any answers. This is one TALKIE thread, that's for sure. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 Ok next version will allow you to specify a invertY parameter for your video (which natively are down to up) Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 @dk - invertY is boolean? Will you be defaulting it to true? You don't need to decide yet, of course. Just curious. Quote Link to comment Share on other sites More sharing options...
gryff Posted March 19, 2014 Share Posted March 19, 2014 Notice that light.name... and light.id... are BOTH set to be 'name' I guess I picked the wrong object to getByName ;-) Works like a charm when you get the syntax right. TY for the explanation. Cameras on the other hand seem to be getByName as there is no getByID function, but there is a getActiveCameraByID. and not by getActiveCameraByName Shall have to watch what object I am trying to play with. By the way on a minor note - when i unzipped the 9th tutorial (09 - Collisions Gravity) it has a folder named 12 - Collisions Gravity . Confused me initially - thought I was missing something cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 Gryff... https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Cameras/babylon.camera.js Just like lights, cameras have a .name and .id that are the same. So... scene.getCameraByName(name or id); ...will work just fine, right? (as long as you don't manually set a camera.id that is different than its .name) http://doc.babylonjs.com/page.php?p=24646 Why do lights use 'byID' and cameras use 'byName'? Beats me, Gryff. But since cams and lights have identical names and id's... everything is interchangeable. Just look-ups... in scene.cameras and scene.lights arrays. activeCameraByID(cam_id) is a setter, of course. And since ID and name are the same for cameras... activeCameraByID(cam_name) likely works fine as well. It probably could have been named setActiveCamera(id or name) or maybe activateCamera(id or name)... but... as long as it works.... that's what counts. Party on! PS: There is no getActiveCameraByID() Bartender, I'll have what Gryff is having! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 invertY is a boolean false by default to preserve compatibility (as always call me the knight of down compatibility) Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 hehe. Yeah, we need to safeguard all 18 of the projects that have used BJS to date. What a task it would be if we had to update ALL THOSE! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 Do not be mean: bjs is used by some huge projects I cannot share right now but wait i bet you will be surprised Xanmia 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 But yes for videotexture I should pre invert to be sure that by default texture are on the right position Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2014 Author Share Posted March 19, 2014 Sorry. I'm just giving you a little 'razzing', there. But really, though. activeCameraByID - a setter? Really? What... did ya blindfold yourself and bang on the keyboard with a dead chicken... to come up with that func name? hahah. Sorry. But that IS pretty funny, no? Not being mean. Okay, maybe a little. C'mon, laugh along. Your precious little baby is healthy, but it still has plenty of poo in its diaper, Einstein. (I hope you can handle this without pouting). PLEASE handle it without pouting. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 there is no need for getActiveCamera() because it is equal to scene.activeCamera Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 19, 2014 Share Posted March 19, 2014 activeCameraBy() is really simple:BABYLON.Scene.prototype.activeCameraByID = function (id) { for (var index = 0; index < this.cameras.length; index++) { if (this.cameras[index].id === id) { this.activeCamera = this.cameras[index]; return; } } };If you already has a camera just set scene.activeCamera = camera and you're done Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 20, 2014 Author Share Posted March 20, 2014 I was making fun of the NAME of the activeCameraByID() method... not its necessity or functionality. I think it would have been much wiser and logical... to NAME the function.... setActiveCamera(camera_id_or_name). Fix that, will ya? Hurry up. hehe. Fix the docs too, quick, before somebody accidentally calls activeCameraByID()... trying to use it to switch cameras. Don't worry about backward compat... nobody has ever called activeCameraByID() because its the most confusing name for a setter function... known to mankind. (Its beat-up deltakosh day!) haha I'll stop now, I promise. I'm just trying to be goofy and funny... and trying to get you to change the name of that function. Doesn't the train demo... use camera switching? I think it does... if I remember correctly. Yes, I agree. No need for .getActiveCamera(). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 Right I will change the name of this function to setActiveCameraById() and I aill also add a setActivecameraByName Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 20, 2014 Author Share Posted March 20, 2014 no, no, no. Now you are messing with me, right? JUST... setActiveCamera() please. No 'ByName' and no 'ById'. Those are terms used in getters, not setters. Make .setActiveCamera() accept a camera.id (a string or a number) or a camera.name (a string)... please. Search scene.cameras for camera.name first. If not found, search for camera.id. And keep in mind that .id COULD be a number. You are going to give me a nervous breakdown, DK. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 Yes I messing with you. It is unpleasant right? Obviously I only add a SetActiveCamera. it checks its parameter to see if this is a camera or a string/number Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 I love this kind of upgrade to the API sincerely Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 BABYLON.Scene.prototype.setActiveCamera = function (cameraOrIdOrName) { if (cameraOrIdOrName instanceof BABYLON.Camera) { this.activeCamera = cameraOrIdOrName; return; } // By ID ? var camera = this.getCameraByID(cameraOrIdOrName); if (camera) { this.activeCamera = camera; return; } // By Name ? camera = this.getCameraByName(cameraOrIdOrName); if (camera) { this.activeCamera = camera; return; } }; Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 20, 2014 Share Posted March 20, 2014 Feel free to suggest others API improvements: this is the right moment, I'm finalizing the 1.10 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted March 20, 2014 Share Posted March 20, 2014 ... [edite] I said nothing ... Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 20, 2014 Author Share Posted March 20, 2014 @DK... No, it is not unpleasant... not when I know you are doing it because of how much you love me. I am sorry that you felt unpleasant. I won't do that anymore. Ok, changes to the api? Really? Change uAng, vAng, and wAng, to uAngle, vAngle, and ... oh yeah... that was already shot-down. Ok, change wrapU and ... what? Oh yeah, that was already shot-down, too. Ummm... ok, how about... mesh.clearPhysicsState() ? Lets say I used applyImpulse (with a slightly offset contactPoint) to send a box flying and tumbling into the air... but immediately after the applyImpulse... I did a clearPhysicsState(). Could the box continue its flight, continue its tumbling, continue using physicsEngine gravity, but no restitution or physics-active collision anymore? The tumbling box would continue its flight, then come back down via gravity... and then... something else. If a collision-active ground/floor was set and a checkCollsion with the floor/box, it would just land on the floor and stop... and not settle to flatness against the floor (no mass or restitution anymore to make it settle). I don't know HOW the physics engine updates impulsed mesh movements... but I would LOVE to use SOME method to launch tumbling mesh (maybe from a modified particleSystem)... and clearPhysicsState just after mesh/particle launch, or just after an applyImpulse for a non-particleSystem mesh launching. With me? Briefly, allow mesh.clearPhysicsState but if mesh currently has ANY motion (position, rotation, gravitational pull), then let that continue. If that sounds ridiculous, just ignore me. Thanks DK! And thanks for working on 1.10! I look forward to it! Sorry if I hurt your feelings. That was NOT my intent. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 20, 2014 Author Share Posted March 20, 2014 Hi again, gang! After reading my previous post, I realized that I am dreaming of a mesh cannon! A hedra-heaver. A shape-shooter. A polygun. Once upon a time, there was a game called Artillery Duel. http://urbanproductions.com/wingy/babylon/misc/artduel.png The player would check the winds, and then set a powder charge and a cannon angle, and POOM! [ shell.applyImpulse(charge, angle) ] That requires the physics imposter to already be established... shell.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: shellweight, friction: winddrag, restitution: bouncepower }); For those who have launched a mesh with a particleSystem or a physics applyImpulse... its a nice satifsying feeling. The BabylonJS particleSystem is cool (to use and to drool-at/borrow its code). I have done demented experiments with the Babylon particle system, with MANY more to come. I did eachParticle.setPhysicsState... and... well... it was demented. http://urbanproductions.com/wingy/babylon/particlefun/splode/pharticles02.htm (use a fast machine) (.zip is there, too) The particleSystem is emitting slowly (frame rate slow) because... all the boxes are colliding with each other at the emitter 'nozzle'... and the physicsState is set on all the boxes... and and and... cannon.js physics engine is calculatin' a kadillion collision formulas per frame. Also, the smoke trails are thick. There are tons of 'quad' mesh in the scene... used to make those smoke trails. Each particle (each box, in this case) has its very own BABYLON.ParticleSystem running on it... spraying smoke. The cannon.js physics system... makes the boxes do some nice tumbling parabola flights... I love "the arches". A proper mesh-flinging game like Artillery Duel 3D-BJS... must have that same smooth parabolic flight to its projectiles... I think. All that crap aside... applyImpulse is a lot of fun... and... if we could easily do mesh.clearPhysicsState just after a particle or mesh "launch", that might be handy. It might assist in making Artillery Duel 3D-BJS, too. In that game, no bounce is necessary, and no physics-active collisions need to be calculated. We DO still need basic collision detection, though... so we can blow stuff up. Just chewin' the rag, here... trying to get the juices flowing. I hope everyone is well! Party On! Ahiru 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.