Jump to content

The Wingnut Chronicles


Wingnut
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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!  :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

}

};

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

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