Panda3D

bulletTriangleMesh.h
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file bulletTriangleMesh.h
10 * @author enn0x
11 * @date 2010-02-09
12 */
13
14 #ifndef __BULLET_TRIANGLE_MESH_H__
15 #define __BULLET_TRIANGLE_MESH_H__
16
17 #include "pandabase.h"
18
19 #include "bullet_includes.h"
20 #include "bullet_utils.h"
21
22 #include "typedWritableReferenceCount.h"
23 #include "nodePath.h"
24 #include "luse.h"
25 #include "geom.h"
26 #include "pta_LVecBase3.h"
27 #include "pta_int.h"
28
29 /**
30 *
31 */
32 class EXPCL_PANDABULLET BulletTriangleMesh : public TypedWritableReferenceCount {
33 PUBLISHED:
34 BulletTriangleMesh();
35 ~BulletTriangleMesh() = default;
36
37 void add_triangle(const LPoint3 &p0,
38 const LPoint3 &p1,
39 const LPoint3 &p2,
40 bool remove_duplicate_vertices=false);
41 void add_array(const PTA_LVecBase3 &points,
42 const PTA_int &indices,
43 bool remove_duplicate_vertices=false);
44 void add_geom(const Geom *geom,
45 bool remove_duplicate_vertices=false,
46 const TransformState *ts=TransformState::make_identity());
47
48 void set_welding_distance(PN_stdfloat distance);
49 void preallocate(int num_verts, int num_indices);
50
51 size_t get_num_triangles() const;
52 PN_stdfloat get_welding_distance() const;
53
54 virtual void output(std::ostream &out) const;
55 virtual void write(std::ostream &out, int indent_level) const;
56
57 public:
58 size_t get_num_vertices() const;
59 LPoint3 get_vertex(size_t index) const;
60
61 LVecBase3i get_triangle(size_t index) const;
62
63 size_t do_get_num_triangles() const;
64 void do_add_triangle(const LPoint3 &p0,
65 const LPoint3 &p1,
66 const LPoint3 &p2,
67 bool remove_duplicate_vertices=false);
68
69 PUBLISHED:
70 MAKE_PROPERTY(welding_distance, get_welding_distance, set_welding_distance);
71
72 MAKE_SEQ_PROPERTY(vertices, get_num_vertices, get_vertex);
73 MAKE_SEQ_PROPERTY(triangles, get_num_triangles, get_triangle);
74
75 public:
76 INLINE btStridingMeshInterface *ptr() const;
77
78 private:
79 unsigned int find_or_add_vertex(const LVecBase3 &p);
80
81 btTriangleIndexVertexArray _mesh;
82 btAlignedObjectArray<btVector3> _vertices;
83 btAlignedObjectArray<unsigned int> _indices;
84 PN_stdfloat _welding_distance;
85
86 public:
87 static void register_with_read_factory();
88 virtual void write_datagram(BamWriter *manager, Datagram &dg);
89
90 protected:
91 static TypedWritable *make_from_bam(const FactoryParams &params);
92 void fillin(DatagramIterator &scan, BamReader *manager);
93
94 public:
95 static TypeHandle get_class_type() {
96 return _type_handle;
97 }
98 static void init_type() {
99 TypedWritableReferenceCount::init_type();
100 register_type(_type_handle, "BulletTriangleMesh",
101 TypedWritableReferenceCount::get_class_type());
102 }
103 virtual TypeHandle get_type() const {
104 return get_class_type();
105 }
106 virtual TypeHandle force_init_type() {
107 init_type();
108 return get_class_type();
109 }
110
111 private:
112 static TypeHandle _type_handle;
113 };
114
115 INLINE std::ostream &operator << (std::ostream &out, const BulletTriangleMesh &obj);
116
117 #include "bulletTriangleMesh.I"
118
119 #endif // __BULLET_TRIANGLE_MESH_H__
bulletTriangleMesh.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bullet_includes.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bullet_utils.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
BulletTriangleMesh
Definition: bulletTriangleMesh.h:32
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
Geom
A container for geometry primitives.
Definition: geom.h:54
TransformState
Indicates a coordinate-system transform on vertices.
Definition: transformState.h:54
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedWritableReferenceCount
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Definition: typedWritableReferenceCount.h:31
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
TypedWritable::fillin
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
Definition: typedWritable.cxx:103
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: typedWritable.cxx:54
geom.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LVecBase3.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_int.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
typedWritableReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.