include points and lines in bam2egg

This commit is contained in:
David Rose 2012-01-31 00:17:27 +00:00
parent 6d32be8a1d
commit e26b9f4c92
2 changed files with 81 additions and 32 deletions

View File

@ -39,6 +39,8 @@
#include "geomNode.h" #include "geomNode.h"
#include "geom.h" #include "geom.h"
#include "geomTriangles.h" #include "geomTriangles.h"
#include "geomPoints.h"
#include "geomLines.h"
#include "geomVertexReader.h" #include "geomVertexReader.h"
#include "transformTable.h" #include "transformTable.h"
#include "modelNode.h" #include "modelNode.h"
@ -57,6 +59,8 @@
#include "eggVertex.h" #include "eggVertex.h"
#include "eggPrimitive.h" #include "eggPrimitive.h"
#include "eggPolygon.h" #include "eggPolygon.h"
#include "eggPoint.h"
#include "eggLine.h"
#include "eggTexture.h" #include "eggTexture.h"
#include "eggMaterial.h" #include "eggMaterial.h"
#include "eggRenderMode.h" #include "eggRenderMode.h"
@ -578,27 +582,24 @@ convert_geom_node(GeomNode *node, const WorkingNodePath &node_path,
for (int j = 0; j < num_primitives; ++j) { for (int j = 0; j < num_primitives; ++j) {
const GeomPrimitive *primitive = geom->get_primitive(j); const GeomPrimitive *primitive = geom->get_primitive(j);
CPT(GeomPrimitive) simple = primitive->decompose(); CPT(GeomPrimitive) simple = primitive->decompose();
if (simple->is_of_type(GeomTriangles::get_class_type())) {
CPT(GeomVertexData) vdata = geom->get_vertex_data(); CPT(GeomVertexData) vdata = geom->get_vertex_data();
// vdata = vdata->animate_vertices(true, Thread::get_current_thread()); // vdata = vdata->animate_vertices(true, Thread::get_current_thread());
convert_triangles(vdata, convert_primitive(vdata, simple, geom_state,
DCAST(GeomTriangles, simple), geom_state,
net_mat, egg_parent, jointMap); net_mat, egg_parent, jointMap);
} }
} }
}
recurse_nodes(node_path, egg_parent, has_decal); recurse_nodes(node_path, egg_parent, has_decal);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: BamToEgg::convert_triangles // Function: BamToEgg::convert_primitive
// Access: Private // Access: Private
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void BamToEgg:: void BamToEgg::
convert_triangles(const GeomVertexData *vertex_data, convert_primitive(const GeomVertexData *vertex_data,
const GeomTriangles *primitive, const GeomPrimitive *primitive,
const RenderState *net_state, const RenderState *net_state,
const LMatrix4 &net_mat, EggGroupNode *egg_parent, const LMatrix4 &net_mat, EggGroupNode *egg_parent,
CharacterJointMap *jointMap) { CharacterJointMap *jointMap) {
@ -739,23 +740,39 @@ convert_triangles(const GeomVertexData *vertex_data,
LColor color; LColor color;
CPT(TransformBlendTable) transformBlendTable = vertex_data->get_transform_blend_table(); CPT(TransformBlendTable) transformBlendTable = vertex_data->get_transform_blend_table();
int nprims = primitive->get_num_primitives(); int num_primitives = primitive->get_num_primitives();
for (int i = 0; i < nprims; ++i) { int num_vertices = primitive->get_num_vertices_per_primitive();
EggPolygon *egg_poly = new EggPolygon;
egg_parent->add_child(egg_poly); EggPrimitive *(*make_func)(void);
if (primitive->is_of_type(GeomTriangles::get_class_type())) {
make_func = make_egg_polygon;
} else if (primitive->is_of_type(GeomPoints::get_class_type())) {
make_func = make_egg_point;
} else if (primitive->is_of_type(GeomLines::get_class_type())) {
make_func = make_egg_line;
} else {
// Huh, an unknown geometry type.
return;
}
for (int i = 0; i < num_primitives; ++i) {
PT(EggPrimitive) egg_prim = (*make_func)();
egg_parent->add_child(egg_prim);
if (egg_tex != (EggTexture *)NULL) { if (egg_tex != (EggTexture *)NULL) {
egg_poly->set_texture(egg_tex); egg_prim->set_texture(egg_tex);
} }
if (bface) { if (bface) {
egg_poly->set_bface_flag(true); egg_prim->set_bface_flag(true);
} }
for (int j = 0; j < 3; j++) { for (int j = 0; j < num_vertices; j++) {
EggVertex egg_vert; EggVertex egg_vert;
// Get per-vertex properties. // Get per-vertex properties.
reader.set_row(primitive->get_vertex(i * 3 + j)); reader.set_row(primitive->get_vertex(i * num_vertices + j));
reader.set_column(InternalName::get_vertex()); reader.set_column(InternalName::get_vertex());
LVertex vertex = reader.get_data3(); LVertex vertex = reader.get_data3();
@ -813,7 +830,7 @@ convert_triangles(const GeomVertexData *vertex_data,
} }
} }
egg_poly->add_vertex(new_egg_vert); egg_prim->add_vertex(new_egg_vert);
} }
} }
} }
@ -1129,6 +1146,35 @@ get_egg_texture(Texture *tex) {
return NULL; return NULL;
} }
////////////////////////////////////////////////////////////////////
// Function: BamToEgg::make_egg_polygon
// Access: Public, Static
// Description: A factory function to make a new EggPolygon instance.
////////////////////////////////////////////////////////////////////
EggPrimitive *BamToEgg::
make_egg_polygon() {
return new EggPolygon;
}
////////////////////////////////////////////////////////////////////
// Function: BamToEgg::make_egg_point
// Access: Public, Static
// Description: A factory function to make a new EggPoint instance.
////////////////////////////////////////////////////////////////////
EggPrimitive *BamToEgg::
make_egg_point() {
return new EggPoint;
}
////////////////////////////////////////////////////////////////////
// Function: BamToEgg::make_egg_line
// Access: Public, Static
// Description: A factory function to make a new EggLine instance.
////////////////////////////////////////////////////////////////////
EggPrimitive *BamToEgg::
make_egg_line() {
return new EggLine;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// A call to pystub() to force libpystub.so to be linked in. // A call to pystub() to force libpystub.so to be linked in.

View File

@ -36,9 +36,8 @@ class Character;
class PartGroup; class PartGroup;
class CollisionNode; class CollisionNode;
class GeomNode; class GeomNode;
class GeomTri;
class GeomVertexData; class GeomVertexData;
class GeomTriangles; class GeomPrimitive;
class PandaNode; class PandaNode;
class RenderState; class RenderState;
class Texture; class Texture;
@ -78,8 +77,8 @@ private:
EggGroupNode *egg_parent, bool has_decal); EggGroupNode *egg_parent, bool has_decal);
void convert_geom_node(GeomNode *node, const WorkingNodePath &node_path, void convert_geom_node(GeomNode *node, const WorkingNodePath &node_path,
EggGroupNode *egg_parent, bool has_decal, CharacterJointMap *jointMap=NULL); EggGroupNode *egg_parent, bool has_decal, CharacterJointMap *jointMap=NULL);
void convert_triangles(const GeomVertexData *vertex_data, void convert_primitive(const GeomVertexData *vertex_data,
const GeomTriangles *primitive, const GeomPrimitive *primitive,
const RenderState *net_state, const RenderState *net_state,
const LMatrix4 &net_mat, EggGroupNode *egg_parent, const LMatrix4 &net_mat, EggGroupNode *egg_parent,
CharacterJointMap *jointMap); CharacterJointMap *jointMap);
@ -92,6 +91,10 @@ private:
EggTexture *get_egg_texture(Texture *tex); EggTexture *get_egg_texture(Texture *tex);
static EggPrimitive *make_egg_polygon();
static EggPrimitive *make_egg_point();
static EggPrimitive *make_egg_line();
EggVertexPool *_vpool; EggVertexPool *_vpool;
EggTextureCollection _textures; EggTextureCollection _textures;
EggMaterialCollection _materials; EggMaterialCollection _materials;