mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
bring parametrics to pgraph
This commit is contained in:
parent
83400f5f7f
commit
b44aa6c4dd
@ -1,6 +1,8 @@
|
||||
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
|
||||
dtoolutil:c dtoolbase:c dtool:m
|
||||
|
||||
#define USE_NURBSPP yes
|
||||
|
||||
#begin lib_target
|
||||
#define TARGET egg2pg
|
||||
#define LOCAL_LIBS \
|
||||
|
@ -60,6 +60,10 @@
|
||||
#include "collisionSphere.h"
|
||||
#include "collisionPlane.h"
|
||||
#include "collisionPolygon.h"
|
||||
#include "parametricCurve.h"
|
||||
#include "nurbsCurve.h"
|
||||
#include "classicNurbsCurve.h"
|
||||
#include "nurbsCurveInterface.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
@ -1090,10 +1094,8 @@ make_node(EggNode *egg_node, PandaNode *parent) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PandaNode *qpEggLoader::
|
||||
make_node(EggNurbsCurve *egg_curve, PandaNode *parent) {
|
||||
return (PandaNode *)NULL;
|
||||
/*
|
||||
assert(parent != NULL);
|
||||
assert(!parent->is_of_type(GeomNode::get_class_type()));
|
||||
assert(!parent->is_geom_node());
|
||||
|
||||
PT(ParametricCurve) curve;
|
||||
|
||||
@ -1160,8 +1162,8 @@ make_node(EggNurbsCurve *egg_curve, PandaNode *parent) {
|
||||
return (PandaNode *)NULL;
|
||||
}
|
||||
|
||||
return new PandaNode(parent, curve);
|
||||
*/
|
||||
parent->add_child(curve);
|
||||
return curve;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -1162,6 +1162,8 @@ make_node(EggNode *egg_node, NamedNode *parent) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
RenderRelation *EggLoader::
|
||||
make_node(EggNurbsCurve *egg_curve, NamedNode *parent) {
|
||||
return (RenderRelation *)NULL;
|
||||
/*
|
||||
assert(parent != NULL);
|
||||
assert(!parent->is_of_type(GeomNode::get_class_type()));
|
||||
|
||||
@ -1231,6 +1233,7 @@ make_node(EggNurbsCurve *egg_curve, NamedNode *parent) {
|
||||
}
|
||||
|
||||
return new RenderRelation(parent, curve);
|
||||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -6,7 +6,7 @@
|
||||
#begin lib_target
|
||||
#define TARGET parametrics
|
||||
#define LOCAL_LIBS \
|
||||
grutil sgattrib linmath express putil pandabase
|
||||
pgraph grutil sgattrib linmath express putil pandabase
|
||||
|
||||
#define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx
|
||||
|
||||
|
@ -49,6 +49,7 @@ ConfigureFn(config_parametrics) {
|
||||
|
||||
#ifdef HAVE_NURBSPP
|
||||
NurbsPPCurve::init_type();
|
||||
NurbsPPCurve::register_with_read_factory();
|
||||
#endif
|
||||
|
||||
ClassicNurbsCurve::register_with_read_factory();
|
||||
|
@ -39,20 +39,9 @@ TypeHandle ParametricCurve::_type_handle;
|
||||
// one from Scheme.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ParametricCurve::
|
||||
ParametricCurve() {
|
||||
ParametricCurve() : PandaNode("curve") {
|
||||
_curve_type = PCT_NONE;
|
||||
_num_dimensions = 3;
|
||||
|
||||
// This CurveDrawer object is used to draw the curve implicitly if
|
||||
// it happens to get parented to render, but only if the curve_type
|
||||
// is set to PCT_XYZ or PCT_NONE.
|
||||
_implicit_drawer = (ParametricCurveDrawer *)NULL;
|
||||
|
||||
// And until we attempt to draw it, we set our bounding volume to be
|
||||
// infinitely large (since we don't know). Once we draw it the
|
||||
// first time, we'll recompute the bounding volume according to the
|
||||
// geometry of what we just drew.
|
||||
set_bound(OmniBoundingVolume());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -62,10 +51,6 @@ ParametricCurve() {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ParametricCurve::
|
||||
~ParametricCurve() {
|
||||
if (_implicit_drawer != (ParametricCurveDrawer *)NULL) {
|
||||
delete _implicit_drawer;
|
||||
}
|
||||
|
||||
// Our drawer list must be empty by the time we destruct, since our
|
||||
// drawers all maintain reference-counting pointers to us! If this
|
||||
// is not so, we have lost a reference count somewhere, or we have
|
||||
@ -73,6 +58,33 @@ ParametricCurve::
|
||||
nassertv(_drawers.empty());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::safe_to_flatten
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if it is generally safe to flatten out
|
||||
// this particular kind of PandaNode by duplicating
|
||||
// instances, false otherwise (for instance, a Camera
|
||||
// cannot be safely flattened, because the Camera
|
||||
// pointer itself is meaningful).
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool ParametricCurve::
|
||||
safe_to_flatten() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::safe_to_transform
|
||||
// Access: Public, Virtual
|
||||
// Description: Returns true if it is generally safe to transform
|
||||
// this particular kind of PandaNode by calling the
|
||||
// xform() method, false otherwise. For instance, it's
|
||||
// usually a bad idea to attempt to xform a Character.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool ParametricCurve::
|
||||
safe_to_transform() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::is_valid
|
||||
// Access: Published, Virtual
|
||||
@ -613,32 +625,6 @@ convert_to_nurbs(ParametricCurve *nc) const {
|
||||
return nc->recompute();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::draw_traverse
|
||||
// Access: Public, Virtual
|
||||
// Description: This is called by the Draw traversal by virtue of the
|
||||
// node's being present in the scene graph. Its job is
|
||||
// to make sure the visualization of the collideable
|
||||
// geometry is up-to-date.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ParametricCurve::
|
||||
draw_traverse(const ArcChain &) {
|
||||
if (_implicit_drawer == (ParametricCurveDrawer *)NULL) {
|
||||
_implicit_drawer = new ParametricCurveDrawer();
|
||||
_implicit_drawer->set_curve(this);
|
||||
_implicit_drawer->draw();
|
||||
_viz_arc = new RenderRelation(this, _implicit_drawer->detach_geom_node());
|
||||
|
||||
// We must then tell the drawer to forget about us, so we don't
|
||||
// maintain a circular reference count.
|
||||
_implicit_drawer->clear_curves();
|
||||
|
||||
// Set our bounding type to accurately reflect the new geometry
|
||||
// beneath this node.
|
||||
set_bound(BVT_dynamic_sphere);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ParametricCurve::register_drawer
|
||||
@ -699,26 +685,6 @@ invalidate_all() {
|
||||
++n) {
|
||||
(*n)->redraw();
|
||||
}
|
||||
|
||||
// Also update the implicit representation.
|
||||
if (_implicit_drawer != (ParametricCurveDrawer *)NULL) {
|
||||
if (_viz_arc->get_parent() != this) {
|
||||
// Hey, someone has moved the visualization. In that case,
|
||||
// forget about it.
|
||||
_viz_arc = (NodeRelation *)NULL;
|
||||
delete _implicit_drawer;
|
||||
_implicit_drawer = (ParametricCurveDrawer *)NULL;
|
||||
set_bound(OmniBoundingVolume());
|
||||
|
||||
} else {
|
||||
// Ok, the visualization is still there. Regenerate it.
|
||||
remove_arc(_viz_arc);
|
||||
_implicit_drawer->set_curve(this);
|
||||
_implicit_drawer->draw();
|
||||
_viz_arc = new RenderRelation(this, _implicit_drawer->detach_geom_node());
|
||||
_implicit_drawer->clear_curves();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -856,7 +822,7 @@ r_find_length(float target_length, float &found_t,
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ParametricCurve::
|
||||
write_datagram(BamWriter *manager, Datagram &me) {
|
||||
NamedNode::write_datagram(manager, me);
|
||||
PandaNode::write_datagram(manager, me);
|
||||
|
||||
me.add_int8(_curve_type);
|
||||
me.add_int8(_num_dimensions);
|
||||
@ -872,7 +838,7 @@ write_datagram(BamWriter *manager, Datagram &me) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ParametricCurve::
|
||||
fillin(DatagramIterator &scan, BamReader *manager) {
|
||||
NamedNode::fillin(scan, manager);
|
||||
PandaNode::fillin(scan, manager);
|
||||
|
||||
_curve_type = scan.get_int8();
|
||||
_num_dimensions = scan.get_int8();
|
||||
|
@ -19,13 +19,12 @@
|
||||
#ifndef PARAMETRICCURVE_H
|
||||
#define PARAMETRICCURVE_H
|
||||
|
||||
#include <pandabase.h>
|
||||
#include "pandabase.h"
|
||||
|
||||
#include <namedNode.h>
|
||||
#include <pt_NodeRelation.h>
|
||||
#include <luse.h>
|
||||
#include "pandaNode.h"
|
||||
#include "luse.h"
|
||||
|
||||
#include <typedef.h>
|
||||
#include "typedef.h"
|
||||
#include "plist.h"
|
||||
#include "pvector.h"
|
||||
|
||||
@ -62,11 +61,16 @@ class NurbsCurveInterface;
|
||||
// This encapsulates all curves in 3-d space defined
|
||||
// for a single parameter t in the range [0,get_max_t()].
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class EXPCL_PANDA ParametricCurve : public NamedNode {
|
||||
class EXPCL_PANDA ParametricCurve : public PandaNode {
|
||||
PUBLISHED:
|
||||
ParametricCurve();
|
||||
virtual ~ParametricCurve();
|
||||
|
||||
public:
|
||||
virtual bool safe_to_flatten() const;
|
||||
virtual bool safe_to_transform() const;
|
||||
|
||||
PUBLISHED:
|
||||
virtual bool is_valid() const;
|
||||
|
||||
virtual float get_max_t() const;
|
||||
@ -114,8 +118,6 @@ public:
|
||||
virtual bool convert_to_hermite(HermiteCurve *hc) const;
|
||||
virtual bool convert_to_nurbs(ParametricCurve *nc) const;
|
||||
|
||||
virtual void draw_traverse(const ArcChain &chain);
|
||||
|
||||
void register_drawer(ParametricCurveDrawer *drawer);
|
||||
void unregister_drawer(ParametricCurveDrawer *drawer);
|
||||
|
||||
@ -142,8 +144,6 @@ protected:
|
||||
private:
|
||||
typedef plist<ParametricCurveDrawer *> DrawerList;
|
||||
DrawerList _drawers;
|
||||
ParametricCurveDrawer *_implicit_drawer;
|
||||
PT_NodeRelation _viz_arc;
|
||||
|
||||
// TypedWritable stuff
|
||||
protected:
|
||||
@ -155,9 +155,9 @@ public:
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
NamedNode::init_type();
|
||||
PandaNode::init_type();
|
||||
register_type(_type_handle, "ParametricCurve",
|
||||
NamedNode::get_class_type());
|
||||
PandaNode::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
|
@ -71,7 +71,7 @@ add_curve(ParametricCurve *curve, int index) {
|
||||
// found.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int ParametricCurveCollection::
|
||||
add_curves(Node *node) {
|
||||
add_curves(PandaNode *node) {
|
||||
int num_curves = r_add_curves(node);
|
||||
|
||||
if (num_curves > 0) {
|
||||
@ -853,7 +853,7 @@ write_egg(ostream &out, const Filename &filename, CoordinateSystem cs) {
|
||||
// Description: The recursive implementation of add_curves().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int ParametricCurveCollection::
|
||||
r_add_curves(Node *node) {
|
||||
r_add_curves(PandaNode *node) {
|
||||
int num_curves = 0;
|
||||
|
||||
if (node->is_of_type(ParametricCurve::get_class_type())) {
|
||||
@ -863,10 +863,10 @@ r_add_curves(Node *node) {
|
||||
num_curves++;
|
||||
}
|
||||
|
||||
int num_children = node->get_num_children(RenderRelation::get_class_type());
|
||||
int num_children = node->get_num_children();
|
||||
for (int i = 0; i < num_children; i++) {
|
||||
NodeRelation *arc = node->get_child(RenderRelation::get_class_type(), i);
|
||||
num_curves += r_add_curves(arc->get_child());
|
||||
PandaNode *child = node->get_child(i);
|
||||
num_curves += r_add_curves(child);
|
||||
}
|
||||
|
||||
return num_curves;
|
||||
|
@ -49,7 +49,7 @@ PUBLISHED:
|
||||
|
||||
void add_curve(ParametricCurve *curve);
|
||||
void add_curve(ParametricCurve *curve, int index);
|
||||
int add_curves(Node *node);
|
||||
int add_curves(PandaNode *node);
|
||||
bool remove_curve(ParametricCurve *curve);
|
||||
void remove_curve(int index);
|
||||
bool has_curve(ParametricCurve *curve) const;
|
||||
@ -95,7 +95,7 @@ PUBLISHED:
|
||||
bool write_egg(ostream &out, const Filename &filename, CoordinateSystem cs);
|
||||
|
||||
public:
|
||||
int r_add_curves(Node *node);
|
||||
int r_add_curves(PandaNode *node);
|
||||
void register_drawer(ParametricCurveDrawer *drawer);
|
||||
void unregister_drawer(ParametricCurveDrawer *drawer);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user