23 if (odetrimeshdata_cat.is_debug()) {
24 odetrimeshdata_cat.debug() << get_class_type() <<
"::link_data(" <<
id <<
"->" << data <<
")" <<
"\n";
26 get_tri_mesh_data_map()[id] = data;
31 const TriMeshDataMap &data_map = get_tri_mesh_data_map();
32 TriMeshDataMap::const_iterator iter = data_map.find(
id);
33 if (iter != data_map.end()) {
40unlink_data(dGeomID
id) {
41 if (odetrimeshdata_cat.is_debug()) {
42 odetrimeshdata_cat.debug() << get_class_type() <<
"::unlink_data(" <<
id <<
")" <<
"\n";
44 nassertv(_tri_mesh_data_map !=
nullptr);
45 TriMeshDataMap::iterator iter = _tri_mesh_data_map->find(
id);
46 if (iter != _tri_mesh_data_map->end()) {
47 _tri_mesh_data_map->erase(iter);
52print_data(
const std::string &marker) {
53 if (odetrimeshdata_cat.is_debug()) {
54 odetrimeshdata_cat.debug() << get_class_type() <<
"::print_data(" << marker <<
")\n";
55 const TriMeshDataMap &data_map = get_tri_mesh_data_map();
56 TriMeshDataMap::const_iterator iter = data_map.begin();
57 for (;iter != data_map.end(); ++iter) {
58 odetrimeshdata_cat.debug() <<
"\t" << iter->first <<
" : " << iter->second <<
"\n";
65 if (odetrimeshdata_cat.is_debug()) {
66 odetrimeshdata_cat.debug()
67 << get_class_type() <<
"::remove_data(" << data->get_id() <<
")" <<
"\n";
69 if (_tri_mesh_data_map ==
nullptr) {
73 TriMeshDataMap::iterator iter;
74 for (iter = _tri_mesh_data_map->begin();
75 iter != _tri_mesh_data_map->end();
77 if (iter->second == data) {
82 while (iter != _tri_mesh_data_map->end()) {
83 _tri_mesh_data_map->erase(iter);
85 for (iter = _tri_mesh_data_map->begin();
86 iter != _tri_mesh_data_map->end();
88 if (iter->second == data) {
97OdeTriMeshData(
const NodePath& model,
bool use_normals) :
98 _id(dGeomTriMeshDataCreate()),
104 if (odetrimeshdata_cat.is_debug()) {
105 odetrimeshdata_cat.debug() << get_type() <<
"(" << _id <<
")" <<
"\n";
108 process_model(model, use_normals);
110 if (odetrimeshdata_cat.is_debug()) {
111 write_faces(odetrimeshdata_cat.debug());
116 build_single(_vertices,
sizeof(StridedVertex), _num_vertices,
117 _faces, _num_faces * 3,
sizeof(StridedTri));
119 build_single1(_vertices,
sizeof(StridedVertex), _num_vertices,
120 _faces, _num_faces * 3,
sizeof(StridedTri),
125 build_double(_vertices,
sizeof(StridedVertex), _num_vertices,
126 _faces, _num_faces * 3,
sizeof(StridedTri));
128 build_double1(_vertices,
sizeof(StridedVertex), _num_vertices,
129 _faces, _num_faces * 3,
sizeof(StridedTri),
144 if (odetrimeshdata_cat.is_debug()) {
145 odetrimeshdata_cat.debug() <<
"~" << get_type() <<
"(" << _id <<
")" <<
"\n";
148 if (_vertices !=
nullptr) {
149 PANDA_FREE_ARRAY(_vertices);
153 if (_faces !=
nullptr) {
154 PANDA_FREE_ARRAY(_faces);
157 if (_normals !=
nullptr) {
161 PANDA_FREE_ARRAY(_normals);
167 if (odetrimeshdata_cat.is_debug()) {
168 odetrimeshdata_cat.debug() << get_type() <<
"::destroy(" << _id <<
")" <<
"\n";
170 if (_id !=
nullptr) {
171 dGeomTriMeshDataDestroy(_id);
183process_model(
const NodePath& model,
bool &use_normals) {
185 if (odetrimeshdata_cat.is_debug()) {
186 odetrimeshdata_cat.debug()
187 <<
"process_model(" << model <<
")" <<
"\n";
194 if (model.
node()->get_type() == GeomNode::get_class_type()) {
199 analyze((
GeomNode*)geomNodePaths[i].node());
202 if (odetrimeshdata_cat.is_debug()) {
203 odetrimeshdata_cat.debug() <<
"Found " << _num_vertices <<
" vertices.\n";
204 odetrimeshdata_cat.debug() <<
"Found " << _num_faces <<
" faces.\n";
207 _vertices = (StridedVertex *)PANDA_MALLOC_ARRAY(_num_vertices *
sizeof(StridedVertex));
208 _faces = (StridedTri *)PANDA_MALLOC_ARRAY(_num_faces *
sizeof(StridedTri));
210 _num_vertices = 0, _num_faces = 0;
213 process_geom_node((
GeomNode*)geomNodePaths[i].node());
214 if (odetrimeshdata_cat.is_debug()) {
215 odetrimeshdata_cat.debug() <<
"_num_vertices now at " << _num_vertices <<
"\n";
219 if (odetrimeshdata_cat.is_debug()) {
220 odetrimeshdata_cat.debug()
221 <<
"Filled " << _num_faces <<
" triangles(" << _num_vertices <<
" vertices)\n";
226process_geom_node(
const GeomNode *geomNode) {
227 if (odetrimeshdata_cat.is_debug()) {
228 ostream &out = odetrimeshdata_cat.debug();
229 out.width(2); out <<
"" <<
"process_geom_node(" << *geomNode <<
")" <<
"\n";
232 process_geom(geomNode->get_geom(i));
237process_geom(
const Geom *geom) {
238 if (odetrimeshdata_cat.is_debug()) {
239 ostream &out = odetrimeshdata_cat.debug();
240 out.width(4); out <<
"" <<
"process_geom(" << *geom <<
")" <<
"\n";
248 for (
size_t i = 0; i < geom->get_num_primitives(); ++i) {
249 process_primitive(geom->get_primitive(i), vData);
261 ostream &out = odetrimeshdata_cat.debug();
262 out.width(6); out <<
"" <<
"process_primitive(" << *dPrimitive <<
")" <<
"\n";
265 if (dPrimitive->get_type() == GeomTriangles::get_class_type()) {
266 for (
int i = 0; i < dPrimitive->get_num_primitives(); i++, _num_faces++) {
267 int s = dPrimitive->get_primitive_start(i);
268 int e = dPrimitive->get_primitive_end(i);
269 out.width(8); out <<
"" <<
"primitive " << i <<
":" <<
"\n";
270 for (
int j = s, m = 0; j < e; j++, m++, _num_vertices++) {
271 int vRowIndex = dPrimitive->get_vertex(j);
272 vReader.set_row_unsafe(vRowIndex);
273 nReader.set_row_unsafe(vRowIndex);
274 vertex = vReader.get_data3f();
276 _faces[_num_faces].Indices[m] = _num_vertices;
278 _vertices[_num_vertices].Vertex[0] = vertex[0];
279 _vertices[_num_vertices].Vertex[1] = vertex[1];
280 _vertices[_num_vertices].Vertex[2] = vertex[2];
282 out.width(10); out <<
"" <<
"vertex " << j <<
" has: pos(" \
283 << vertex <<
") normal(" <<
"normal" <<
")" <<
"\n";
286 }
else if (dPrimitive->get_type() == GeomTristrips::get_class_type()){
287 for (
int i = 0; i < dPrimitive->get_num_primitives(); i++, _num_faces++) {
288 int s = dPrimitive->get_primitive_start(i);
289 int e = dPrimitive->get_primitive_end(i);
290 out.width(8); out <<
"" <<
"primitive " << i <<
":" <<
"\n";
291 for (
int j = s, m = 0; j < e; j++, m++, _num_vertices++) {
292 int vRowIndex = dPrimitive->get_vertex(j);
293 vReader.set_row_unsafe(vRowIndex);
294 nReader.set_row_unsafe(vRowIndex);
295 vertex = vReader.get_data3f();
298 _vertices[_num_vertices].Vertex[0] = vertex[0];
299 _vertices[_num_vertices].Vertex[1] = vertex[1];
300 _vertices[_num_vertices].Vertex[2] = vertex[2];
301 out.width(10); out <<
"" <<
"vertex " << j <<
" has: pos(" \
302 << vertex <<
") normal(" <<
"normal" <<
")" <<
"\n";
304 _faces[_num_faces].Indices[m] = _num_vertices;
308 _faces[_num_faces].Indices[0] = _num_vertices-1;
309 _faces[_num_faces].Indices[1] = _num_vertices-2;
310 _faces[_num_faces].Indices[2] = _num_vertices;
312 _faces[_num_faces].Indices[0] = _num_vertices-2;
313 _faces[_num_faces].Indices[1] = _num_vertices-1;
314 _faces[_num_faces].Indices[2] = _num_vertices;
325 analyze(geomNode->get_geom(i));
330analyze(
const Geom *geom) {
335 for (
size_t i = 0; i < geom->get_num_primitives(); ++i) {
336 analyze(geom->get_primitive(i));
349write_faces(ostream &out)
const {
351 for (
unsigned int i = 0; i < _num_faces; ++i) {
352 out.width(2); out <<
"Face " << i <<
":\n";
353 for (
int j = 0; j < 3; ++j) {
355 out <<
"(" << _vertices[_faces[i].Indices[j]].Vertex[0] \
356 <<
", " << _vertices[_faces[i].Indices[j]].Vertex[1] \
357 <<
", " << _vertices[_faces[i].Indices[j]].Vertex[2] <<
")\n" ;
363write(ostream &out,
unsigned int indent)
const {
364 out.width(
indent); out <<
"" << get_type() <<
"(id = " << _id <<
") : " \
365 <<
"" <<
"Vertices: " << (_id ? _num_vertices : 0) <<
", " \
366 <<
"" <<
"Triangles: " << (_id ? _num_faces : 0);
A node that holds Geom objects, renderable pieces of geometry.
get_num_geoms
Returns the number of geoms in the node.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
int get_primitive_num_faces(int n) const
Returns the number of triangles or other fundamental type (such as line segments) represented by the ...
int get_num_primitives() const
Returns the number of individual primitives stored within this object.
int get_primitive_num_vertices(int n) const
Returns the number of vertices used by the nth primitive.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
A container for geometry primitives.
get_primitive_type
Returns the fundamental primitive type that is common to all GeomPrimitives added within the Geom.
This is a set of zero or more NodePaths.
void add_path(const NodePath &node_path)
Adds a new NodePath to the collection.
get_num_paths
Returns the number of NodePaths in the collection.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
bool is_empty() const
Returns true if the NodePath contains no nodes.
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.
PandaNode * node() const
Returns the referenced node of the path.
TypeHandle is the identifier used to differentiate C++ class types.
This is our own Panda specialization on the default STL map.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.