Visual proxy

April 12th, 2009

With Director 11.5 one can visualize the created proxy using the rb.properties property of the rigid body.

Have a look at the help file for details on the same. the following code snippet will allow you to see the created proxy shaped in wireframe mode :).

--Function takes a rigid body object, rigidBody = physx.getrigidbody("name")
on visualize_proxy rigidBody
  p3dmember = member("my3dWorld")
  physX = member("physX")
  if rigidBody <> void then
    --rb.properties returns a list containing: numFaces,numVertices,vertexList,face
    proxy_list = rigidBody.properties
    --Note that the mesh details are vailable only for rigidbody of shape
    --#convex and #concave
    if rigidBody.shape = #convex or rigidBody.shape = #concave then
      numFaces = proxy_list.numFaces
      numVertices = proxy_list.numVertices
      newMesh_res = p3dmember.newMesh(rigidBody.name & "_proxy_res",numFaces , numVertices, 0, 3)
      --the mesh color would be gray, change the values if needed
      newMesh_res.colorList = [rgb(150,150,150),rgb(150, 150, 150),rgb(150,150,150)]
      vertex_list = proxy_list.vertexList
      repeat with i=1 to numVertices then
        newMesh_res.vertexList[i]  = vector(vertex_list[i][1],vertex_list[i][2],vertex_list[i][3])
      end repeat
      repeat with f=1 to numFaces then
        newMesh_res.face[f].vertices = proxy_list.face[f].vertices
      end repeat
      newMesh_res.generateNormals(#smooth)
 
      --build the mesh using the above defined mesh resource
      newMesh_res.build()
      nm = p3dmember.newModel(rigidBody.name & "_visualize", newMesh_res)
      nm.transform.position = rigidBody.position
    else
      if rigidBody.shape = #box then
        newMesh_res = p3Dmember.newModelResource(rigidBody.name & "_proxy_res",#box)
        newMesh_res.width = proxy_list.width
        newMesh_res.height = proxy_list.height
        newMesh_res.length = proxy_list.length
      else
        --would be #sphere shape
        newMesh_res = p3Dmember.newModelResource(rigidBody.name & "_proxy_res",#sphere)
        newMesh_res.radius = proxy_list.radius
        newMesh_res.resolution = 10
      end if
      nm = p3dmember.newModel(rigidBody.name & "_visualize", newMesh_res)
      --.center is a new property , helps make sure that the
      --centers of the model and visualize_proxy match
      nm.transform.position = rigidBody.position + proxy_list.center
    end if
    --Add the newly created mesh as a child to the 3d model.
    p3dmember.model(rigidBody.name).addChild(p3dmember.model(rigidBody.name & "_visualize"))
    --render the proxy/hull in wireframe
    nm.shader.renderstyle = #wire
  end if
end

This will not only help understand rigid body proxy shapes better, but also allow one to tweak it for performance !
Have fun visualizing ;) !!

Buy us a coffee mug !

  • Share/Save/Bookmark

Rigid Body creation - part2

March 27th, 2009

The previous post talked about creation of rigid body from models/mesh. This process can sometimes take time due to the complexity of the mesh. Also the createRigidBody( ) method would not allow one to create dynamic concave rigid bodies.

Before going into the details we need to understand what a proxy template is…

A proxy template allows a user to create pre-calculated proxy/hull for a given model and then use it.

This has several advantages:

1. It can be saved and used later , hence avoids over head during run time.
2. The proxy template can be used to create rigid bodies for models of varying size. Say you have a Robot of different sizes ( scaled ), once you have created a proxy template for the robot , you can use the same proxy template to create rigid body for the different variation of sizes of Robot model. The scale and transforms are not stored in the proxy template and picked up from the model.
3. You can use the created proxy template for convex, concave all being dynamic or static.

There are basically 2 workflows that can be followed with the new set of methods provided.

Proxy Template Workflow

Out of the 2 workflows, we recommend using the authoring one to avoid the overhead of creation of proxy templates each time.

The blocks in blue are the newly added methods for creating proxy temlates in Director 11.5. For more info on each of the methods refer the help doc.

NOTE: In workflow-1 ,steps from createproxyTemplate() to saveW3d() , can be performed once for creating the required proxy templates for all the models in the 3d world. During runtime, only loadProxyTemplate() and createRigidBodyFromProxy() methods need to be used as the proxy templates are already saved in the specified 3d member. Use of message window or running through all the models with a loop and creating the required proxy templates and save them into a 3d member using saveWorld() or saveW3d() methods would be ideal.

Some tips while using these methods:

createProxyTemplate(ModelResourceRef, #proxyTemplateSymbol, decompositionlist)
--the decompositionlist is valid only for #convexDecomposed proxy template type.

ModelResourceRef - model resource cannot be Director primitive(like #box,#sphere etc..) except #mesh type. All other w3d modelresource are allowed.

#proxyTemplateSymbol - #concave ( for static concave rigid body :RB), #convex ( for dynamic/static convex RB), #convexDecomposed ( for static/dynamic concave RB)

decomposition parameter list - #depth ( number of cross sectional planes running through a model , lesser the faster, range:0-10 , ideal:4-8) , #concavity ( value that defines what %age of concavity compared to the whole body should be considered, range:0-100, ideal:4-60), #mergeVolume ( %age of a broken mesh compared the whole body which needs to be discarded or kept , range: 0-100,ideal:4-60)

addProxyTemplate(3dmember, proxyTemplate, string proxyname)

3dmember - a 3d world , ideally would be nice to have one 3d world dedicated to proxy templates to avoid all the confusion.

proxyTemplate - this is the template returned by createproxyTemlate() method.

proxyname - a unique name for the proxy template, use conventions like cdx_name, ccv_name,cvx_name for #convexdecomposed, #concave and #convex proxy templates respectively.

One can visualize the proxy/hull created using the rb.properties property of the rigid body.

Shall try and give more info in the next post…

Buy us a coffee mug !

  • Share/Save/Bookmark