A CC3Node that draws a 3D mesh model. More...
#import <CC3MeshNode.h>
Public Member Functions | |
(void) | - drawLocalContentWithVisitor: |
(void) | - populateAsCenteredRectangleWithSize:andTexture:invertTexture: |
(void) | - populateAsRectangleWithSize:andPivot:andTexture:invertTexture: |
Properties | |
ccColor4F | ambientColor |
ccColor3B | color |
ccColor4F | diffuseColor |
ccColor4F | emissionColor |
BOOL | isOpaque |
CC3Material * | material |
CC3MeshModel * | meshModel |
GLubyte | opacity |
ccColor4F | specularColor |
A CC3Node that draws a 3D mesh model.
This class forms the base of all visible 3D mesh models in the 3D world.
CC3MeshNode is a type of CC3Node, and will often participate in a structural node assembly. An instance can be the child of another node, and the mesh node itself can have child nodes.
CC3MeshNodes encapsulate both a CC3Material instance and a CC3MeshModel instance. The CC3Material instance describes the material and texture properties covering the mesh, and the CC3MeshModel instance contains the mesh vertex data. When this node is drawn, it delegates to both the material and mesh model instances.
Each CC3MeshNode can have only one material. For large, complicated meshes that are covered by more than one material, the mesh must be broken into smaller meshes, each of which are covered by a single material. These smaller sub-meshes are sometimes referred to as "vertex groups". Each such sub-mesh is then wrapped in its own CC3MeshNode instance, along with the material that covers that sub-mesh.
These CC3MeshNode instances can then be added as child nodes to a single parent CC3Node instance. This parent CC3Node can then be moved, rotated and scaled, and all of its child nodes will transform in sync. The assembly will behave and be seen as a single object.
When the mesh model is set in the meshModel property, the CC3MeshNode instance creates and builds a CC3NodeBoundingVolume instance from the mesh data, and sets it into its boundingVolume property.
When a copy is made of a CC3MeshNode instance using the copy method, a copy is made of the material, but the mesh model is simply assigned by reference, and is not copied. The result is that the the new and original nodes will have different materials, but will share the same mesh model. This design avoids creating multiple copies of volumnious and static mesh data when creating copies of nodes.
- (void) drawLocalContentWithVisitor: | (CC3NodeDrawingVisitor *) | visitor |
Draws the local content of this mesh node by following these steps:
Otherwise, invokes the CC3Material class-side unbind method.
This method is called automatically from the transformAndDrawWithVisitor: method of this node. Usually, the application never needs to invoke this method directly.
- (void) populateAsCenteredRectangleWithSize: | (CGSize) | rectSize | |
andTexture: | (CC3Texture *) | texture | |
invertTexture: | (BOOL) | shouldInvert | |
Populates this instance as a simple textured rectangular mesh of the specified size, centered at the origin, and laid out on the X-Y plane.
The shouldInvert flag indicates whether the texture should be inverted when laid out on the mesh. Some textures appear inverted after loading under iOS. This flag can be used to compensate for that by reinverting the texture to the correct orientation.
As this node is translated, rotate and scaled, the textured rectangle will be re-oriented in 3D space.
This is a convenience method for creating a simple, but useful shape, which can be used to create walls, floors, etc.
- (void) populateAsRectangleWithSize: | (CGSize) | rectSize | |
andPivot: | (CGPoint) | pivot | |
andTexture: | (CC3Texture *) | texture | |
invertTexture: | (BOOL) | shouldInvert | |
Populates this instance as a simple textured rectangular mesh of the specified size, with the specified pivot point at the origin, and laid out on the X-Y plane.
The pivot point can be any point within the rectangle's size. For example, if the pivot point is {0, 0}, the rectangle will be laid out so that the bottom-left corner is at the origin. Or, if the pivot point is in the center of the rectangle's size, the rectangle will be laid out centered on the origin, as in the populateAsCenteredRectangleWithSize:andTexture: method.
The shouldInvert flag indicates whether the texture should be inverted when laid out on the mesh. Some textures appear inverted after loading under iOS. This flag can be used to compensate for that by reinverting the texture to the correct orientation.
As this node is translated, rotate and scaled, the textured rectangle will be re-oriented in 3D space.
This is a convenience method for creating a simple, but useful shape, which can be used to create walls, floors, etc.
- (ccColor4F) ambientColor [read, write, assign] |
The ambient color of the material of this mesh node.
Material color is initially set to kCC3DefaultMaterialColorAmbient. If this instance has no material, this property will return kCCC4FBlackTransparent.
Implements CC3Node.
- (ccColor3B) color [read, write, assign] |
Implementation of the CCRGBAProtocol color property.
When setting this property, the RGB values are each converted to a floating point number between 0 and 1, and are set into both the ambientColor and diffuseColor properties of this node's material. The alpha of each of those properties remains unchanged.
Querying this property returns the RGB components of the material's diffuseColor property, converted from the floating point range (0 to 1), to the byte range (0 to 255).
Implements CC3Node.
- (ccColor4F) diffuseColor [read, write, assign] |
The diffuse color of the material of this mesh node.
Material color is initially set to kCC3DefaultMaterialColorDiffuse. If this instance has no material, this property will return kCCC4FBlackTransparent.
Implements CC3Node.
- (ccColor4F) emissionColor [read, write, assign] |
The emission color of the material of this mesh node.
Material color is initially set to kCC3DefaultMaterialColorEmission. If this instance has no material, this property will return kCCC4FBlackTransparent.
Implements CC3Node.
- (BOOL) isOpaque [read, write, assign] |
Indicates whether the material of this mesh node is opaque.
Returns NO if either the material is not opaque, or at least one descendant is not opaque, as determined by its isOpaque property. Returns YES if the material is opaque and all descendants return YES from their isOpaque property.
Setting this property sets the same property in the material and in all descendants.
Setting this property changes the sourceBlend and destinationBlend properties on the material of this node. Setting this property to YES sets the value of the sourceBlend property to GL_ONE and the value of the destinationBlend to GL_ZERO. Setting this property to NO sets the value of the sourceBlend property to GL_SRC_ALPHA and the value of the destinationBlend to GL_ONE_MINUS_SRC_ALPHA.
Implements CC3Node.
- (CC3Material *) material [read, write, retain] |
The material covering this mesh node.
- (CC3MeshModel *) meshModel [read, write, retain] |
The mesh model that holds the vertex data for this mesh node.
When this property is set, if this node has a boundingVolume, it is forced to rebuild itself, otherwise, if this node does not have a boundingVolume, a default bounding volume is created from the mesh model.
- (GLubyte) opacity [read, write, assign] |
Implementation of the CCRGBAProtocol opacity property.
When setting this property, the value is converted to a floating point number between 0 and 1, and is set into all of the ambientColor, diffuseColor, specularColor, and emissionColor properties of this node's material. The RGB components of each of those properties remains unchanged.
In order to use this property effectively, alpha-blending must be turned on for the material. The easiest way to do this at the node level is to set the isOpaque property to NO. For finer control of material alpha-blending, you can manipulate the sourceBlend and destinationBlend properties of the material itself.
Querying this property returns the alpha component of the material's diffuseColor property, converted from the floating point range (0 to 1), to the byte range (0 to 255).
Implements CC3Node.
- (ccColor4F) specularColor [read, write, assign] |
The specular color of the material of this mesh node.
Material color is initially set to kCC3DefaultMaterialColorSpecular. If this instance has no material, this property will return kCCC4FBlackTransparent.
Implements CC3Node.