Register  |  FAQ  |  Search  |  Memberlist  |  Usergroups  |  Log in 
Reply to topic
 Practice Physics System 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
The physics system of Awakening is easy to use. In this tutorial, we'll create a sample scene with kinetic balls. Wo do modeling & texturing in Google SketchUp Pro 6.0, lighting in Awakening 2.5 beta, and generate balls by writing script codes.


Last edited by Vincent on Sun Aug 26, 2007 3:47 am; edited 3 times in total
View user's profile Send private message
 Part 1 : Modeling 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Make a scene in Sketch Up like this, just ensure the height of every stairstep is 20 units.

View user's profile Send private message
 Part 2 : Texturing 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Cover textures to surfaces use the Paint Bucket tool.

View user's profile Send private message
 Part 3 : Exporting 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
From Sketch Up's menu, select File > Export > 3D Model...; in the file dialog that appears, select "3DS (*.3ds)" for Export type, then click the "Options" button; in the 3DS Export Options dialog that appears, ensure setting like this:



Now click OK back to the file dialog, choose a folder and type a file name (assume "pp.3ds" below), then click the "Export" button, Sketch Up will show the export progress.
View user's profile Send private message
 Part 4 : Importing 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Launch Awakening 2.5 beta, select File > Import... form menu; in the file dialog that appears, select "3DS Files (*.3DS)" for file type, select the pp.3ds which exported in previous step for file name, in the options dialog that appears, ensure setting like this:



(if this dialog doesn't appear, go to Tools > Plugins... to change options)

Click OK to do importing.
View user's profile Send private message
 Part 5 : Lighting 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Now your scene should like this:



Create two points lights with Dynamic Shadow style, and set Sample Spacing to 8 in Light Map Options dialog, then press F9 to calculate lighting, the scene will belcom realistic:



Now you can press F5 to run the scene, then press Shift + F to walk-thru.
View user's profile Send private message
 Part 6: Generating kinetic balls 
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
We need write some script codes in the User Script File, so first save the scene to file. Because the texture file names in 3DS doesn't contain path infomation, so we should save the scene to the same folder with the pp.3ds; otherwise the texture files cann't be found when you load saved scene file next time.

After finish saving, select View > Edit User Script File... form Awakening's menu, the notepad program will open the .usr file,
edit it follow below steps:

1. Add these codes to the beginning of file:

Code:
local function newstone(pos,fscale)
   local ball=scene.createMobile('\\sphere.tri')
   if (not ball) then return end
   ball.setScale(vec.new(fscale,fscale,fscale))
   ball.setPosition(pos)
   ball.setStyle(MOVS_SHADOW);

   local stone=scene.createMovTar()

   stone.setResistance(0.02)
   stone.setOverBounce(1.5)
   stone.setBounceAtten(0.98)
   stone.setStrideBlock(true)
   stone.setRebound(true)

   stone.setPosition(ball.getPosition())
   local lbb=ball.getLocalBoundingBox()
   ballradius = lbb.getMax().y * ball.getScale().y
   stone.pointed(true)
   stone.setRadius(ballradius)
   stone.setStrideHeight(ballradius)

   stone.framemove = function()
      ball.setPosition(stone.getPosition())
   end

   stone.deletethis = function()
      scene.deleteMobile(ball)
      scene.deleteMovTar(stone)
   end

   return stone
end



local stonelist=array.new()

function newball(pos,vel,size)
   size = size or 1
   local stone=newstone(pos,size)
   if (stone) then
      stone.setVelocity(vel)
      stonelist.add(stone)
   end
end


2. Add a line in the OnLButtonDown() function:

Code:
newball(camera.getPosition(),camera.getFront()*300,math.random()*0.5+0.1)


3. Add below lines in the FrameMove() function:

Code:
   for i=1,stonelist.size() do
      stonelist[i].framemove()
   end



Ok, save the .usr file and run the scene again, try left-click your mouse.

View user's profile Send private message
  
nigec


Joined: 04 Jul 2007
Posts: 212
Reply with quote
I've been messing with this and built a model where the balls collide with pegs as they drop througth a glass fronted box Smile
my questions are.. there just had to be questions!

How do i make the balls one size?
how do i have a set point to place the balls instead of firing from the center


I want to have the balls drop and view the scene at a different angle, the plan is to create a scene where the ball travels through various shaped models, I've already had them going down a spiral slide but you could only see it from the drop zone for the balls..

would it be possible to have a object that spins on its axis if something collided into it?

heres my small scene:
http://files.filefront.com/ballsrar/;12797719;/fileinfo.html
The pin box is just a quick model as i didn't really know if it would work, and its been adjusted a few times to get the balls to run without jamming
View user's profile Send private message
  
Vincent


Joined: 25 Dec 2006
Posts: 296
Reply with quote
Quote:
How do i make the balls one size?
how do i have a set point to place the balls instead of firing from the center


Just new a mobile in scene, define a script variable (named 'spawn_point') for it; then in OnLButtonDown() function, change the code to:

Code:
newball(spawn_point.getPosition(), vec.new(), 0.3)


Quote:
would it be possible to have a object that spins on its axis if something collided into it?

Needs some script code. You can do something in ball's OnCollide function to spin the hited object.

PS:
1.you need copy the Models folder manually when install scene.
2. turn off Dynamic Shadow will highly improve performance
View user's profile Send private message
  
nigec


Joined: 04 Jul 2007
Posts: 212
Reply with quote
Thats awesom thanks vincent.. I was wondering why it was only ran from within Awakening.. i never thought about about the models folder Rolling Eyes
View user's profile Send private message
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic