23 odetrimeshdata_cat.debug() << get_class_type() <<
"::link_data(" <<
id <<
"->" << data <<
")" <<
"\n";
24 get_tri_mesh_data_map()[id] = data;
28 get_data(dGeomID
id) {
29 const TriMeshDataMap &data_map = get_tri_mesh_data_map();
30 TriMeshDataMap::const_iterator iter = data_map.find(
id);
31 if (iter != data_map.end()) {
38 unlink_data(dGeomID
id) {
39 odetrimeshdata_cat.debug() << get_class_type() <<
"::unlink_data(" <<
id <<
")" <<
"\n";
40 nassertv(_tri_mesh_data_map !=
nullptr);
41 TriMeshDataMap::iterator iter = _tri_mesh_data_map->find(
id);
42 if (iter != _tri_mesh_data_map->end()) {
43 _tri_mesh_data_map->erase(iter);
48 print_data(
const std::string &marker) {
49 odetrimeshdata_cat.debug() << get_class_type() <<
"::print_data(" << marker <<
")\n";
50 const TriMeshDataMap &data_map = get_tri_mesh_data_map();
51 TriMeshDataMap::const_iterator iter = data_map.begin();
52 for (;iter != data_map.end(); ++iter) {
53 odetrimeshdata_cat.debug() <<
"\t" << iter->first <<
" : " << iter->second <<
"\n";
59 if (odetrimeshdata_cat.is_debug()) {
60 odetrimeshdata_cat.debug()
61 << get_class_type() <<
"::remove_data(" << data->get_id() <<
")" <<
"\n";
63 if (_tri_mesh_data_map ==
nullptr) {
67 TriMeshDataMap::iterator iter;
68 for (iter = _tri_mesh_data_map->begin();
69 iter != _tri_mesh_data_map->end();
71 if (iter->second == data) {
76 while (iter != _tri_mesh_data_map->end()) {
77 _tri_mesh_data_map->erase(iter);
79 for (iter = _tri_mesh_data_map->begin();
80 iter != _tri_mesh_data_map->end();
82 if (iter->second == data) {
91 OdeTriMeshData(
const NodePath& model,
bool use_normals) :
92 _id(dGeomTriMeshDataCreate()),
98 odetrimeshdata_cat.debug() << get_type() <<
"(" << _id <<
")" <<
"\n";
100 process_model(model, use_normals);
102 write_faces(odetrimeshdata_cat.debug());
106 build_single(_vertices,
sizeof(StridedVertex), _num_vertices,
107 _faces, _num_faces * 3,
sizeof(StridedTri));
109 build_single1(_vertices,
sizeof(StridedVertex), _num_vertices,
110 _faces, _num_faces * 3,
sizeof(StridedTri),
115 build_double(_vertices,
sizeof(StridedVertex), _num_vertices,
116 _faces, _num_faces * 3,
sizeof(StridedTri));
118 build_double1(_vertices,
sizeof(StridedVertex), _num_vertices,
119 _faces, _num_faces * 3,
sizeof(StridedTri),
134 odetrimeshdata_cat.debug() <<
"~" << get_type() <<
"(" << _id <<
")" <<
"\n";
136 if (_vertices !=
nullptr) {
137 PANDA_FREE_ARRAY(_vertices);
141 if (_faces !=
nullptr) {
142 PANDA_FREE_ARRAY(_faces);
145 if (_normals !=
nullptr) {
149 PANDA_FREE_ARRAY(_normals);
153 void OdeTriMeshData::
155 odetrimeshdata_cat.debug() << get_type() <<
"::destroy(" << _id <<
")" <<
"\n";
156 if (_id !=
nullptr) {
157 dGeomTriMeshDataDestroy(_id);
164 void OdeTriMeshData::
168 void OdeTriMeshData::
169 process_model(
const NodePath& model,
bool &use_normals) {
171 if (odetrimeshdata_cat.is_debug()) {
172 odetrimeshdata_cat.debug()
173 <<
"process_model(" << model <<
")" <<
"\n";
180 if (model.
node()->get_type() == GeomNode::get_class_type()) {
185 analyze((
GeomNode*)geomNodePaths[i].node());
188 odetrimeshdata_cat.debug() <<
"Found " << _num_vertices <<
" vertices.\n";
189 odetrimeshdata_cat.debug() <<
"Found " << _num_faces <<
" faces.\n";
191 _vertices = (StridedVertex *)PANDA_MALLOC_ARRAY(_num_vertices *
sizeof(StridedVertex));
192 _faces = (StridedTri *)PANDA_MALLOC_ARRAY(_num_faces *
sizeof(StridedTri));
194 _num_vertices = 0, _num_faces = 0;
197 process_geom_node((
GeomNode*)geomNodePaths[i].node());
198 odetrimeshdata_cat.debug() <<
"_num_vertices now at " << _num_vertices <<
"\n";
201 odetrimeshdata_cat.debug() <<
"Filled " << _num_faces <<
" triangles(" \
202 << _num_vertices <<
" vertices)\n";
205 void OdeTriMeshData::
206 process_geom_node(
const GeomNode *geomNode) {
207 ostream &out = odetrimeshdata_cat.debug();
208 out.width(2); out <<
"" <<
"process_geom_node(" << *geomNode <<
")" <<
"\n";
209 for (
int i = 0; i < geomNode->get_num_geoms(); ++i) {
210 process_geom(geomNode->get_geom(i));
214 void OdeTriMeshData::
215 process_geom(
const Geom *geom) {
216 ostream &out = odetrimeshdata_cat.debug();
217 out.width(4); out <<
"" <<
"process_geom(" << *geom <<
")" <<
"\n";
218 if (geom->get_primitive_type() != Geom::PT_polygons) {
224 for (
size_t i = 0; i < geom->get_num_primitives(); ++i) {
225 process_primitive(geom->get_primitive(i), vData);
229 void OdeTriMeshData::
237 ostream &out = odetrimeshdata_cat.debug();
238 out.width(6); out <<
"" <<
"process_primitive(" << *dPrimitive <<
")" <<
"\n";
241 if (dPrimitive->get_type() == GeomTriangles::get_class_type()) {
242 for (
int i = 0; i < dPrimitive->get_num_primitives(); i++, _num_faces++) {
244 int e = dPrimitive->get_primitive_end(i);
245 out.width(8); out <<
"" <<
"primitive " << i <<
":" <<
"\n";
246 for (
int j = s, m = 0; j < e; j++, m++, _num_vertices++) {
247 int vRowIndex = dPrimitive->get_vertex(j);
248 vReader.set_row_unsafe(vRowIndex);
249 nReader.set_row_unsafe(vRowIndex);
250 vertex = vReader.get_data3f();
252 _faces[_num_faces].Indices[m] = _num_vertices;
254 _vertices[_num_vertices].Vertex[0] = vertex[0];
255 _vertices[_num_vertices].Vertex[1] = vertex[1];
256 _vertices[_num_vertices].Vertex[2] = vertex[2];
258 out.width(10); out <<
"" <<
"vertex " << j <<
" has: pos(" \
259 << vertex <<
") normal(" <<
"normal" <<
")" <<
"\n";
262 }
else if (dPrimitive->get_type() == GeomTristrips::get_class_type()){
263 for (
int i = 0; i < dPrimitive->get_num_primitives(); i++, _num_faces++) {
264 int s = dPrimitive->get_primitive_start(i);
265 int e = dPrimitive->get_primitive_end(i);
266 out.width(8); out <<
"" <<
"primitive " << i <<
":" <<
"\n";
267 for (
int j = s, m = 0; j < e; j++, m++, _num_vertices++) {
268 int vRowIndex = dPrimitive->get_vertex(j);
269 vReader.set_row_unsafe(vRowIndex);
270 nReader.set_row_unsafe(vRowIndex);
271 vertex = vReader.get_data3f();
274 _vertices[_num_vertices].Vertex[0] = vertex[0];
275 _vertices[_num_vertices].Vertex[1] = vertex[1];
276 _vertices[_num_vertices].Vertex[2] = vertex[2];
277 out.width(10); out <<
"" <<
"vertex " << j <<
" has: pos(" \
278 << vertex <<
") normal(" <<
"normal" <<
")" <<
"\n";
280 _faces[_num_faces].Indices[m] = _num_vertices;
284 _faces[_num_faces].Indices[0] = _num_vertices-1;
285 _faces[_num_faces].Indices[1] = _num_vertices-2;
286 _faces[_num_faces].Indices[2] = _num_vertices;
288 _faces[_num_faces].Indices[0] = _num_vertices-2;
289 _faces[_num_faces].Indices[1] = _num_vertices-1;
290 _faces[_num_faces].Indices[2] = _num_vertices;
298 void OdeTriMeshData::
301 analyze(geomNode->get_geom(i));
305 void OdeTriMeshData::
306 analyze(
const Geom *geom) {
311 for (
size_t i = 0; i < geom->get_num_primitives(); ++i) {
312 analyze(geom->get_primitive(i));
316 void OdeTriMeshData::
324 void OdeTriMeshData::
325 write_faces(ostream &out)
const {
327 for (
unsigned int i = 0; i < _num_faces; ++i) {
328 out.width(2); out <<
"Face " << i <<
":\n";
329 for (
int j = 0; j < 3; ++j) {
331 out <<
"(" << _vertices[_faces[i].Indices[j]].Vertex[0] \
332 <<
", " << _vertices[_faces[i].Indices[j]].Vertex[1] \
333 <<
", " << _vertices[_faces[i].Indices[j]].Vertex[2] <<
")\n" ;
338 void OdeTriMeshData::
339 write(ostream &out,
unsigned int indent)
const {
340 out.width(
indent); out <<
"" << get_type() <<
"(id = " << _id <<
") : " \
341 <<
"" <<
"Vertices: " << (_id ? _num_vertices : 0) <<
", " \
342 <<
"" <<
"Triangles: " << (_id ? _num_faces : 0);
NodePathCollection find_all_matches(const std::string &path) const
Returns the complete set of all NodePaths that begin with this NodePath and can be extended by path.
int get_primitive_num_faces(int n) const
Returns the number of triangles or other fundamental type (such as line segments) represented by the ...
This is our own Panda specialization on the default STL map.
void add_path(const NodePath &node_path)
Adds a new NodePath to the collection.
int get_primitive_num_vertices(int n) const
Returns the number of vertices used by the nth primitive.
bool is_empty() const
Returns true if the NodePath contains no nodes.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_primitive_start(int n) const
Returns the element within the _vertices list at which the nth primitive starts.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
get_primitive_type
Returns the fundamental primitive type that is common to all GeomPrimitives added within the Geom.
int get_num_primitives() const
Returns the number of individual primitives stored within this object.
PandaNode * node() const
Returns the referenced node of the path.
get_num_geoms
Returns the number of geoms in the node.
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
get_num_paths
Returns the number of NodePaths in the collection.
TypeHandle is the identifier used to differentiate C++ class types.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
A node that holds Geom objects, renderable pieces of geometry.
This is a set of zero or more NodePaths.