15 #include "bulletHelper.h"
16 #include "bulletRigidBodyNode.h"
17 #include "bulletGhostNode.h"
19 #include "geomLines.h"
20 #include "geomTriangles.h"
21 #include "geomVertexRewriter.h"
32 from_collision_solids(
NodePath &np,
bool clear) {
47 if (is_tangible(cnode)) {
51 body->add_shapes_from_collision_solids(cnode);
52 body->set_transform(cnp.get_transform(np));
53 body->set_into_collide_mask(cnode->get_into_collide_mask());
55 body->set_name(cnode->get_name());
63 ghost->add_shapes_from_collision_solids(cnode);
64 ghost->set_transform(cnp.get_transform(np));
65 ghost->set_into_collide_mask(cnode->get_into_collide_mask());
66 ghost->set_name(cnode->get_name());
92 for (
int j=0; j<cnode->get_num_solids(); j++) {
94 if (solid->is_tangible()) {
108 add_sb_index_column(const GeomVertexFormat *format) {
112 if (format->has_column(name)) return format;
114 PT(GeomVertexArrayFormat) array;
115 PT(GeomVertexFormat) unregistered_format;
116 CPT(GeomVertexFormat) registered_format;
118 array = new GeomVertexArrayFormat();
119 array->add_column(name, 1,
Geom::NT_uint16,
Geom::C_index);
121 unregistered_format = new GeomVertexFormat(*format);
122 unregistered_format->add_array(array);
124 registered_format = GeomVertexFormat::register_format(unregistered_format);
126 return registered_format;
135 add_sb_flip_column(const GeomVertexFormat *format) {
139 if (format->has_column(name)) return format;
141 PT(GeomVertexArrayFormat) array;
142 PT(GeomVertexFormat) unregistered_format;
143 CPT(GeomVertexFormat) registered_format;
145 array = new GeomVertexArrayFormat();
146 array->add_column(name, 1,
Geom::NT_uint8,
Geom::C_other);
148 unregistered_format = new GeomVertexFormat(*format);
149 unregistered_format->add_array(array);
151 registered_format = GeomVertexFormat::register_format(unregistered_format);
153 return registered_format;
162 make_geom_from_faces(
BulletSoftBodyNode *node, const GeomVertexFormat *format,
bool two_sided) {
164 return make_geom(node, format, two_sided,
true);
175 return make_geom(node, format,
false,
false);
184 make_geom(
BulletSoftBodyNode *node, const GeomVertexFormat *format,
bool two_sided,
bool use_faces) {
186 btTransform trans = btTransform::getIdentity();
187 get_node_transform(trans, node);
189 btSoftBody *body = (btSoftBody *)node->get_object();
195 CPT(GeomVertexFormat) fmt = (format) ? format : GeomVertexFormat::get_v3n3t2();
198 nassertr(fmt->has_column(InternalName::get_vertex()), NULL);
199 nassertr(fmt->has_column(InternalName::get_normal()), NULL);
201 btSoftBody::tNodeArray &nodes(body->m_nodes);
210 for (
int j=0; j<nodes.size(); ++j) {
211 btVector3 v = nodes[j].m_x;
212 btVector3 &n = nodes[j].m_n;
214 v = trans.invXform(v);
216 vwriter.add_data3((PN_stdfloat)v.getX(), (PN_stdfloat)v.getY(), (PN_stdfloat)v.getZ());
217 nwriter.add_data3((PN_stdfloat)n.getX(), (PN_stdfloat)n.getY(), (PN_stdfloat)n.getZ());
218 fwriter.add_data1i(0);
222 for (
int j=0; j<nodes.size(); ++j) {
223 btVector3 v = nodes[j].m_x;
224 btVector3 &n = nodes[j].m_n;
226 v = trans.invXform(v);
228 vwriter.add_data3((PN_stdfloat)v.getX(), (PN_stdfloat)v.getY(), (PN_stdfloat)v.getZ());
229 nwriter.add_data3((PN_stdfloat)n.getX(), (PN_stdfloat)n.getY(), (PN_stdfloat)n.getZ());
230 fwriter.add_data1i(1);
235 btSoftBody::Node *node0 = &nodes[0];
240 btSoftBody::tFaceArray &faces(body->m_faces);
243 prim->set_shade_model(Geom::SM_uniform);
245 for (
int j=0; j<faces.size(); ++j) {
246 i0 = int(faces[j].m_n[0] - node0);
247 i1 = int(faces[j].m_n[1] - node0);
248 i2 = int(faces[j].m_n[2] - node0);
250 prim->add_vertices(i0, i1, i2);
251 prim->close_primitive();
254 i0 = nodes.size() + int(faces[j].m_n[0] - node0);
255 i1 = nodes.size() + int(faces[j].m_n[2] - node0);
256 i2 = nodes.size() + int(faces[j].m_n[1] - node0);
258 prim->add_vertices(i0, i1, i2);
259 prim->close_primitive();
264 btSoftBody::tLinkArray &links(body->m_links);
267 prim->set_shade_model(Geom::SM_uniform);
269 for (
int j=0; j<links.size(); ++j) {
270 i0 = int(links[j].m_n[0] - node0);
271 i1 = int(links[j].m_n[1] - node0);
273 prim->add_vertices(i0, i1);
274 prim->close_primitive();
279 geom =
new Geom(vdata);
291 make_texcoords_for_patch(
Geom *geom,
int resx,
int resy) {
293 PT(GeomVertexData) vdata = geom->modify_vertex_data();
295 nassertv(vdata->has_column(InternalName::get_texcoord()));
306 while (!texcoords.is_at_end()) {
312 u = (float)ix/(
float)(resx - 1);
313 v = (float)iy/(
float)(resy - 1);
A basic node of the scene graph or data graph.
This object provides a high-level interface for quickly writing a sequence of numeric values from a v...
void add_path(const NodePath &node_path)
Adds a new NodePath to the collection.
The abstract base class for all things that can collide with other things in the world, and all the things they can collide with (except geometry).
NodePath get_path(int index) const
Returns the nth NodePath in the collection.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
PandaNode * node() const
Returns the referenced node of the path.
void add_primitive(const GeomPrimitive *primitive)
Adds a new GeomPrimitive structure to the Geom object.
int get_num_paths() const
Returns the number of NodePaths in the collection.
static NodePath any_path(PandaNode *node, Thread *current_thread=Thread::get_current_thread())
Returns a new NodePath that represents any arbitrary path from the root to the indicated node...
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Defines a series of disconnected line segments.
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
A node in the scene graph that can hold any number of CollisionSolids.
Defines a series of disconnected triangles.
void set_data2f(float x, float y)
Sets the write row to a particular 2-component value, and advances the write row. ...
NodePathCollection find_all_matches(const string &path) const
Returns the complete set of all NodePaths that begin with any NodePath in this collection and can be ...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
This object provides the functionality of both a GeomVertexReader and a GeomVertexWriter, combined together into one convenient package.
This is a set of zero or more NodePaths.