Dev:Ref/GoogleSummerOfCode/2005/Ode Physics Integration

提供: wiki
移動先: 案内検索

ODE Physics In Animation System

This Project will deal with the integration of a dynamic physics engine with collisions and joints into Blender to enable the animation of liquids.

The goals stated in the proposal were to allow animators to make use of: (a) collision and (b) joint functionality in animation.

Progress Progress so far has been rather limited, and is largely still in the phases of design and pseudo-code. The physics objects have been designed and some work has been done on writing code to convert physics motion into animation IPOs.

Workflow In order to apply the blender physics to an animation, the animator will need to first apply a bounding primitive to the object, much as is currently achieved through the game logic GUI. This will create a corresponding physics object which will later be used to generate a body (with user defined mass and velocity, defaulting to one and zero respectively) and primitive geom (sphere, cube or cylinder, user defined via dropdown menu). Joints will be similarly added by means of an "Add joint" button, which will then introduce options such as joint type, bodies to be joined and axes/anchors associated with the joint. This information will be stored in a blender joint class. When it is time to create the animation, the physics and joint classes will be converted into ODE geoms, bodies and joints.

Implementation

Integration into the Blender code I intend to create a physics object and constraint (joint) object in seperate physobj.h and physjoint.h header files. Instances of the physics object class can then be created for specific blender objects, much as bounding solids are currently created for the game system. This will be managed in a similar way, but the code will be separate. The classes will contain all the data pertinent to the implementation of collisions and joints respectively, and have functions to convert to physics engine data. These will be called from their own UI and contained in their own header files, such that interaction with other blender code will be minimal. The conversion from physics simulation to animation will be a separate function which will be called from the blender animation code.

Physobj.h Pseudo-code Overview

Physics Object Abstract Data Type Variables

    • int Boundtype
    • Real dimensions[3] //e.g. radius, width, height, etc of bounding object
    • Real x
    • Real y
    • Real z
    • Real Mass
    • Real Speed
    • Matrix Rotation
  • dGeomID MyGeom

Methods

  • Constructor (Boundtype, BlendID)
  • Mutators
  • SetPosition(x,y,z)
  • SetX(x)
  • SetY(y)
  • SetZ(z)
  • SetMass(Mass)
  • SetSpeed(Speed)
  • SetRotation(Rotation)
  • SetGeomID(GeomID)
  • SetBlendID(BlendID)
  • ToOde()
  • CreateGeom(Boundtype, dimensions)
  • CreateBody(x,y,z,Mass, Speed, Rotation)
  • Associate
  • Return GeomID
  • FromOde()
  • currBody=dGeomGetBody(MyGeom)
  • dBodyGetPosition(currBody)
  • dBodyGetRotation(currBody)

Physjoint.h Pseudo-code Overview

Joint Abstract Data Type Variables

    • int Type
    • dBodyID Attached[2]
    • Vector3 DOFs[4]

Methods

  • Constructor(type)
  • Mutators
  • SetType(type)
  • SetAttached(Body1,Body2)
  • SetDOFs(Anchor, Anchor2, Axis, Axis2)
  • ignore if not relevant to type
  • default to 0
  • ToOde()
  • switch(type)
  • currJoint=dJointCreateFixed(World, 0)
  • dJointSet<type><DOF>(currJoint, x, y, z)
  • dJointAttach(currJoint, Attached[0], Attached[1])

-- ThomasLewis - 27 Jul 2005