Panda3D Manual: Tweaking an Existing Model
<<prev | top | next>> |
NOTE: This API is changing in Panda 1.1 I'll hold off explaining till it comes out. If you want to change part of an existing model you have to get the |NodePath of the part you want to change. This `NodePath` will be holding a `GeomNode`, which are used to represent onscreen geometry. Every object that gets render in the scene graph eventually has `GeomNode` objects at its leaf. Note: For examples, the teapot included in the `.../models` directory will be used. `GeomNode` objects are actually wrappers around object from the `Geom` class. These object hold the primitives that actually get drawn to the screen. However, `Geom` objects can only be created when loading a model. See Creating Geometry from Scratch if you want to generate primitives. ## Geom Class Since the `Geom` is what actually defines drawable geometry, we will discuss it first. There are a number of subclasses that represent specific primitive (`GeomQuad`, `GeomTri`,...) but none of them have add meaningful functionality on top of the `Geom`. Therefore, just looking at the `Geom` will be enough. As stated above this class and its subclasses do not have public constructors defined. They are only made when loading model. To actually get a `Geom` object look below at the `GeomNode` class. However, for the purpose of exapmle code assume we already have `myGeom` setup. FINISHME ## GeomNode Class To get a specific `Geom` from a `GeomNode` you use the `getGeom(index)` where `index` is the number of the `Geom` you want. You must be careful though, since (just like Instancing) `Geom` objects can be shared between many `GeomNode` objects. If you want to alter a `Geom`, you should use `getUniqueGeom(index)` which returns a copy of the `Geom` object if it is used in more than one place.
teapot=loader.loadModel('teapot') body=teapot.find('**/body') #remeber the difference between a Node and a NodePath bodyGeomNode=body.node() #just use 0 to get the "first" Geom fstGeom=bodyGeomNode.getGeom(0) sndGeom=bodyGeomNode.getUniqueGeom(1)
If you want to add `Geom` to a `GeomNode` you can use the function `addGeom(newGeom, renderState)`. EXPLAINME: renderState. If renderState is not given, the `newGeom` completely inherits the `renderState` of it's parent. There is also `addGeomsFrom(otherGeomNode)` which effectively calls `addGeom` to all the `Geom` objects from `otherGeomNode`. There are also `removeGeom(index)` and `removeAllGeoms()` which repectively remove a certain piece of geometry and remove all pieces of geometry.
handle=teapot.find('**/handle') handleGeomNode=handle.node() spout=teapot.find('**/spout') spoutGeomNode=spout.node() bodyGeomNode.addGeom(spoutGeomNode.getGeom(0)) bodyGeomNode.addGeomsFrom(handleGeomNode) #after this, a call to bodyGeomNode.reomve(0) will remove the node that used # to be indexed at 1 bodyGeomNode.remove(0) bodyGeomNode.removeAllGeoms()
You can also get the `RenderState` of a certain `Geome` using `getGeomState(index)`. You can also get the number of `Geom` objects in a `GeomNode` by using `getNumGeoms()`. See API Reference for advanced functionality.
<<prev | top | next>> |