createRigidBodyFromProxy()

Usage

world.createRigidBodyFromProxy(string rigidbodyname, string 3Dmodelname,symbol  bodyType,ProxyTemplate,symbol flipNormals)

Description

This method creates a rigid body with the specified proxy shape.

Add the #meshdeform modifier to the model before creating a rigid body. You can create a rigid body from a proxy using one of the following procedures:
  • Create a proxy template and use it directly to create the rigid body at runtime.

  • Create proxy template of the model resource and save it to 3D world (w3d) at author time, and use this template to create the actual rigid body at runtime. This is the recommended approach for creation of concave and convex rigid bodies. Other proxy types are not supported by this method.

    The scaling and model transforms are automatically applied during the creation of the rigid body. You can reuse the proxy template when creating rigid bodies that are modeled from the same model resource.

    Creating a proxy and saving it as a 3D member for later use during authoring results in a performance improvement.

    A -30 error is thrown if the proxy template is invalid, or a #concave proxy template is passed when creating a dynamic concave rigid body.

Parameters

Parameter

Description

3dModelName

Required. String that specifies the name of the 3d Model on which the rigid body is created.

rigidBodyName

Required. String that specifies the name of the rigid body.

bodyType

Required.

#static - If a static or immovable body needs to be created.
Note: When you move a static body by changing its position, the position of the rigid body changes but the position of the 3D model is unaltered.

#dynamic - If a movable body needs to be created.

ProxyTemplate

Required. A proxy template object got from the method createProxyTemplate() .

Note: See createProxyTemplate() , addProxyTemplate() and loadProxyTemplate() methods for the creation and saving of proxy.

flipNormals

Optional.

This parameter inverts the face normals.

For bodies using #concaveshape proxy, collisions are detected in the positive direction of the face normals. Penetration is observed from the opposite side. To invert this behavior, use FlipNormals.

This parameter works only with #convexshape and #concaveshape proxies. It throws an error for other proxies.

A reference to the rigid body is returned. If the creation fails, void is returned.

Note: Specifying #concave type proxy template for dynamic concave rigid body results in an error. createProxyTemplate() and addProxyTemplate() should be ideally used with the message window and should not be part of the runtime code. This approach would help avoid the overhead of Convex Decomposition of dynamic concave rigid bodies. Also saving the proxy in a separate 3d world would be ideal to avoid cluttering of model resources.

Example

--Lingo syntax 
--During Author time save the proxy template to a 3D world using steps 1 to 3 
--Step1: Create a proxy template from a model resource 
ProxyTemplate = member("PhysicsWorld").createProxyTemplate(modelResource Reference ,#convexDecomposed,[#concavity:2, #depth:8,#mergeVolume:2]) 
--Step2: Add the proxy template to the 3D world 
member("PhysicsWorld").addProxyTemplate(member("3DproxyWorld"), ProxyTemplate, "proxyName") 
--Step3: Save the 3D world 
member("3DproxyWorld").saveWorld() 
--At runtime load the saved proxy template and create the rigid body. 
--Load the proxy template from the saved 3D world 
Saved_proxy = member("PhysicsWorld").loadProxyTemplate("proxyName",member("3DproxyWorld")) 
--Create the rigid body from proxy template 
objRB = member("PhysicsWorld").createRigidBodyFromProxy("RigidBodyA","ModelA", #dynamic, Saved_proxy) 
//Javascript syntax 
Var objRB = member("PhysicsWorld").createRigidBodyFromProxy("RigidBodyA"," ModelA", symbol("dynamic"), Saved_proxy) ;