Jump to content

Add the feature on car


minhhuy_it
 Share

Recommended Posts

Hi again minhhuy_it!   I remember this topic from before.  Sorry that you didn't get the help you needed, back then.

 

I have some questions.

 

Do you have the demo running on your server?  Worded another way, do you have the car scene working now... in a way that you can modify MainScene.js?

 

Have you tried any modifications to MainScene.js?  See the function in there called MainScene.prototype.setUpCar?  That would be a place to add your head lights (and maybe tail lights and brake lights, too).

 

See the first line in that function?  this.car = BABYLON.Mesh.CreateBox("box", 20, this.scene);

 

This is the PARENT box for the car_m model.  this.car_m.parent = this.car;   (a bit further down)

 

Immediately after that parenting line... is ONE place where you COULD add two spotlights to be used as head lights for the car.

 

Maybe you would add...

this.leftHeadLight = new BABYLON.SpotLight("lhl", new BABYLON.Vector3(-5, 1, 15), new BABYLON.Vector3(-1, 0, -1), 0.8, 2, scene);this.rightHeadLight = new BABYLON.SpotLight("rhl", new BABYLON.Vector3(5, 1, 15), new BABYLON.Vector3(-1, 0, -1), 0.8, 2, scene);this.leftHeadLight.position = new BABYLON.Vector3(?, ?, ?);  // position the light to the front of car somehowthis.rightHeadLight.position = new BABYLON.Vector3(?, ?, ?);  // position the light to the front of car somehowthis.leftHeadLight.parent = this.car;  // make the light be parented to the car's parentthis.rightHeadLight.parent = this.car;  // make the light be parented to the car's parent

You might also need to adjust new BABYLON.Vector3(-1, 0, -1) (the direction of the lights).  Direction vectors like these... are interesting, and sometimes difficult to set.  The values are most-often set between -1 and +1.  There are some helpers nearby that can be used to set head light directions easier.  It involves positioning a temporary box FAR AWAY in front of the car, then using the spotlight.setDirectionToTarget(box.position).  Once that is done... do console.log(spotlight.direction.normalize());  Then use THOSE values in the spotlight constructors (the first two lines in the code above).  We can talk about direction-setting later, or maybe you are already a pro at setting light direction vectors.  :)

 

And you will certainly need to adjust the new BABYLON.Vector3(?, ?, ?) (the position of the lights upon the car)

 

Now keep doing adjustments and running the scene... until you get your head lights placed correctly inside the head light lens covers.

 

Tail lights and brake lights should be easier, maybe.  It would be very helpful if you can find the NAMES of the three circles inside each tail light assembly.  Then, when the brakes are applied, you could set a BRIGHT RED .emissiveColor on those 6 circles, and it will look like brake lights.  For tail lights, set a MEDIUM RED .emissiveColor on them.

 

Of course, you willl need to find WHERE in the code... that the brakes are applied, and do the right thing there.

 

And, you might need a lights on/off switch.  See how Sam uses the 'd' key to turn drift mode on/off?  Well your "L" key to turn lights on/off will be placed near that, and its eventListener will be coded similar.  This "L" switch will call a function (that you write) to change the .intensity of this.leftHeadLight and this.rightHeadLight . 

 

And you will need a boolean flag such as... this.car.lightsAreOn = (true/false).  That way, you will know what to do with the lights when the user presses "L" (turn them ON or turn them OFF).

 

Ok, this should get you started.  Good luck, and keep us posted.  Forum readers:  Please proofread this and correct stupid/wrong things I might have said, and also post other/better ideas.  thanks!

Link to comment
Share on other sites

  • 4 weeks later...

Hi minhhuy_it... sorry to hear about this.  Can you please tell us many details about HOW and WHERE it failed?  Can we see your failed attempts on a server near you? 

 

(Drift Car is a .babylon-file model and it needs a web server.  Also, the webserver needs some .babylon mime type adjustments... to make the .babylon file be considered an "allowed" mime type. ).

 

Were you able to get the original demo running on your server?

 

I'll reply more, soon.  Meantime, please... you talk talk talk. We need lots of details about where things succeeded and where things failed.  Thanks!  Be well.

Link to comment
Share on other sites

No, sorry.  Also, my schedule is continuously changing and unpredictable right now.  It's not that I'm working very hard, it just seems I'm scheduled to be many different places at many different times... to sit around and do nothing.  :)

 

Plus, we want to tell everyone, not just me, right?  (thx)

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