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
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 */
32class 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
57public:
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
75public:
76 INLINE btStridingMeshInterface *ptr() const;
77
78private:
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
86public:
87 static void register_with_read_factory();
88 virtual void write_datagram(BamWriter *manager, Datagram &dg);
89
90protected:
91 static TypedWritable *make_from_bam(const FactoryParams &params);
92 void fillin(DatagramIterator &scan, BamReader *manager);
93
94public:
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
111private:
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__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
void add_triangle(const LPoint3 &p0, const LPoint3 &p1, const LPoint3 &p2, bool remove_duplicate_vertices=false)
Adds a triangle with the indicated coordinates.
size_t do_get_num_triangles() const
Returns the number of triangles in this triangle mesh.
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.
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.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BulletTriangleMesh.
get_vertex
Returns the vertex at the given vertex index.
get_num_triangles
Returns the number of triangles in this triangle mesh.
get_welding_distance
Returns the value previously set with set_welding_distance(), or the value of 0 if none was set.
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...
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.
set_welding_distance
Sets the square of the distance at which vertices will be merged together when adding geometry with r...
get_triangle
Returns the vertex indices making up the given triangle index.
get_num_vertices
Returns the number of vertices in this triangle mesh.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
A container for geometry primitives.
Definition geom.h:54
Indicates a coordinate-system transform on vertices.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
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...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.