Panda3D

Loading...
Searching...
No Matches
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 {
33PUBLISHED:
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
69PUBLISHED:
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
115INLINE 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
BulletTriangleMesh
Definition bulletTriangleMesh.h:32
BulletTriangleMesh::add_triangle
void add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices=false)
Adds a triangle with the indicated coordinates.
Definition bulletTriangleMesh.cxx:163
BulletTriangleMesh::do_get_num_triangles
size_t do_get_num_triangles() const
Returns the number of triangles in this triangle mesh.
Definition bulletTriangleMesh.cxx:83
BulletTriangleMesh::add_array
void add_array(const PTA_LVecBase3 &points, const PTA_int &indices, bool remove_duplicate_vertices=false)
Adds triangle information from an array of points and indices referring to these points.
Definition bulletTriangleMesh.cxx:319
BulletTriangleMesh::do_add_triangle
void do_add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices=false)
Adds a triangle with the indicated coordinates.
Definition bulletTriangleMesh.cxx:125
BulletTriangleMesh::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletTriangleMesh.
Definition bulletTriangleMesh.cxx:407
BulletTriangleMesh::get_vertex
get_vertex
Returns the vertex at the given vertex index.
Definition bulletTriangleMesh.h:72
BulletTriangleMesh::get_num_triangles
get_num_triangles
Returns the number of triangles in this triangle mesh.
Definition bulletTriangleMesh.h:73
BulletTriangleMesh::get_welding_distance
get_welding_distance
Returns the value previously set with set_welding_distance(), or the value of 0 if none was set.
Definition bulletTriangleMesh.h:70
BulletTriangleMesh::preallocate
void preallocate(int num_verts, int num_indices)
Used to reserve memory in anticipation of the given amount of vertices and indices being added to the...
Definition bulletTriangleMesh.cxx:104
BulletTriangleMesh::add_geom
void add_geom(const Geom *geom, bool remove_duplicate_vertices=false, const TransformState *ts=TransformState::make_identity())
Adds the geometry from the indicated Geom from the triangle mesh.
Definition bulletTriangleMesh.cxx:205
BulletTriangleMesh::set_welding_distance
set_welding_distance
Sets the square of the distance at which vertices will be merged together when adding geometry with r...
Definition bulletTriangleMesh.h:70
BulletTriangleMesh::get_triangle
get_triangle
Returns the vertex indices making up the given triangle index.
Definition bulletTriangleMesh.h:73
BulletTriangleMesh::get_num_vertices
get_num_vertices
Returns the number of vertices in this triangle mesh.
Definition bulletTriangleMesh.h:72
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
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
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.