flattening qpgeom

This commit is contained in:
David Rose 2005-03-31 18:28:01 +00:00
parent 08241a99ea
commit c6bcbe88f5
7 changed files with 343 additions and 117 deletions

View File

@ -87,12 +87,12 @@ munge_data_impl(const qpGeomVertexData *data) {
_contents);
}
qpGeomVertexAnimationSpec animation = data->get_format()->get_animation();
qpGeomVertexAnimationSpec animation = new_data->get_format()->get_animation();
if (hardware_animated_vertices &&
animation.get_animation_type() == qpGeomVertexAnimationSpec::AT_panda &&
data->get_slider_table() == (SliderTable *)NULL) {
new_data->get_slider_table() == (SliderTable *)NULL) {
// Maybe we can animate the vertices with hardware.
const TransformBlendPalette *palette = data->get_transform_blend_palette();
const TransformBlendPalette *palette = new_data->get_transform_blend_palette();
if (palette != (TransformBlendPalette *)NULL &&
palette->get_max_simultaneous_transforms() <=
_gsg->get_max_vertex_transforms()) {
@ -121,15 +121,15 @@ munge_data_impl(const qpGeomVertexData *data) {
}
}
CPT(qpGeomVertexFormat) orig_format = data->get_format();
CPT(qpGeomVertexFormat) orig_format = new_data->get_format();
CPT(qpGeomVertexFormat) new_format = munge_format(orig_format, animation);
if (new_format == orig_format) {
// Trivial case.
return data;
return new_data;
}
return data->convert_to(new_format);
return new_data->convert_to(new_format);
}
////////////////////////////////////////////////////////////////////

View File

@ -74,6 +74,18 @@ get_usage_hint() const {
return _usage_hint;
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexData::has_column
// Access: Published
// Description: Returns true if the data has the named column,
// false otherwise. This is really just a shortcut for
// asking the same thing from the format.
////////////////////////////////////////////////////////////////////
INLINE bool qpGeomVertexData::
has_column(const InternalName *name) const {
return _format->has_column(name);
}
////////////////////////////////////////////////////////////////////
// Function: qpGeomVertexData::set_num_vertices
// Access: Published

View File

@ -85,6 +85,7 @@ qpGeomVertexData(const qpGeomVertexData &copy) :
TypedWritableReferenceCount(copy),
_name(copy._name),
_format(copy._format),
_usage_hint(copy._usage_hint),
_cycler(copy._cycler),
_app_char_pcollector(copy._app_char_pcollector),
_cull_char_pcollector(copy._cull_char_pcollector)
@ -101,6 +102,10 @@ operator = (const qpGeomVertexData &copy) {
TypedWritableReferenceCount::operator = (copy);
_name = copy._name;
_format = copy._format;
// The assignment operator does not copy the usage_hint, which is
// not supposed to change over the lifetime of a GeomVertexData.
_cycler = copy._cycler;
_app_char_pcollector = copy._app_char_pcollector;
_cull_char_pcollector = copy._cull_char_pcollector;
@ -818,7 +823,7 @@ output(ostream &out) const {
if (!get_name().empty()) {
out << get_name() << " ";
}
out << get_num_vertices() << ": " << *get_format();
out << get_num_vertices() << " vertices: " << *get_format();
}
////////////////////////////////////////////////////////////////////
@ -831,7 +836,7 @@ write(ostream &out, int indent_level) const {
if (!get_name().empty()) {
indent(out, indent_level) << get_name() << "\n";
}
_format->write_with_data(out, indent_level, this);
_format->write_with_data(out, indent_level + 2, this);
if (get_transform_blend_palette() != (TransformBlendPalette *)NULL) {
indent(out, indent_level)
<< "Transform blend palette:\n";

View File

@ -83,6 +83,8 @@ PUBLISHED:
INLINE const qpGeomVertexFormat *get_format() const;
INLINE qpGeomUsageHint::UsageHint get_usage_hint() const;
INLINE bool has_column(const InternalName *name) const;
int get_num_vertices() const;
INLINE bool set_num_vertices(int n);
void clear_vertices();

View File

@ -17,6 +17,51 @@
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::qpSourceVertices::Ordering Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool GeomTransformer::qpSourceVertices::
operator < (const GeomTransformer::qpSourceVertices &other) const {
if (_vertex_data != other._vertex_data) {
return _vertex_data < other._vertex_data;
}
return (_mat.compare_to(other._mat) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::qpSourceTexCoords::Ordering Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool GeomTransformer::qpSourceTexCoords::
operator < (const GeomTransformer::qpSourceTexCoords &other) const {
if (_vertex_data != other._vertex_data) {
return _vertex_data < other._vertex_data;
}
if (_from != other._from) {
return _from < other._from;
}
if (_to != other._to) {
return _to < other._to;
}
return (_mat.compare_to(other._mat) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::qpSourceColors::Ordering Operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool GeomTransformer::qpSourceColors::
operator < (const GeomTransformer::qpSourceColors &other) const {
if (_vertex_data != other._vertex_data) {
return _vertex_data < other._vertex_data;
}
return (_color.compare_to(other._color) < 0);
}
////////////////////////////////////////////////////////////////////
// Function: GeomTransformer::SourceVertices::Ordering Operator
// Access: Public

View File

@ -18,6 +18,8 @@
#include "geomTransformer.h"
#include "geomNode.h"
#include "qpgeom.h"
#include "qpgeomVertexRewriter.h"
#include "renderState.h"
////////////////////////////////////////////////////////////////////
@ -51,6 +53,42 @@ transform_vertices(Geom *geom, const LMatrix4f &mat) {
nassertr(geom != (Geom *)NULL, false);
if (geom->is_exact_type(qpGeom::get_class_type())) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceVertices sv;
sv._mat = mat;
sv._vertex_data = qpgeom->get_vertex_data();
PT(qpGeomVertexData) &new_data = _qpvertices[sv];
if (new_data.is_null()) {
// We have not yet converted these vertices. Do so now.
new_data = new qpGeomVertexData(*sv._vertex_data);
CPT(qpGeomVertexFormat) format = new_data->get_format();
int ci;
for (ci = 0; ci < format->get_num_points(); ci++) {
qpGeomVertexRewriter data(new_data, format->get_point(ci));
while (!data.is_at_end()) {
const LPoint3f &point = data.get_data3f();
data.set_data3f(point * mat);
}
}
for (ci = 0; ci < format->get_num_vectors(); ci++) {
qpGeomVertexRewriter data(new_data, format->get_vector(ci));
while (!data.is_at_end()) {
const LVector3f &vector = data.get_data3f();
data.set_data3f(normalize(vector * mat));
}
}
}
qpgeom->set_vertex_data(new_data);
transformed = true;
} else {
PTA_Vertexf coords;
PTA_ushort index;
@ -107,6 +145,7 @@ transform_vertices(Geom *geom, const LMatrix4f &mat) {
geom->set_normals(new_norms, bind, index);
transformed = true;
}
}
return transformed;
}
@ -155,7 +194,50 @@ transform_texcoords(Geom *geom, const InternalName *from_name,
bool transformed = false;
nassertr(geom != (Geom *)NULL, false);
if (geom->is_exact_type(qpGeom::get_class_type())) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceTexCoords st;
st._mat = mat;
st._from = from_name;
st._to = to_name;
st._vertex_data = qpgeom->get_vertex_data();
PT(qpGeomVertexData) &new_data = _qptexcoords[st];
if (new_data.is_null()) {
if (!st._vertex_data->has_column(from_name)) {
// No from_name column; no change.
return false;
}
// We have not yet converted these texcoords. Do so now.
if (st._vertex_data->has_column(to_name)) {
new_data = new qpGeomVertexData(*st._vertex_data);
} else {
const qpGeomVertexColumn *old_column =
st._vertex_data->get_format()->get_column(from_name);
new_data = st._vertex_data->replace_column
(to_name, old_column->get_num_components(),
old_column->get_numeric_type(),
old_column->get_contents(), st._vertex_data->get_usage_hint(),
false);
}
CPT(qpGeomVertexFormat) format = new_data->get_format();
qpGeomVertexWriter tdata(new_data, to_name);
qpGeomVertexReader fdata(new_data, from_name);
while (!fdata.is_at_end()) {
const LPoint4f &coord = fdata.get_data4f();
tdata.set_data4f(coord * mat);
}
}
qpgeom->set_vertex_data(new_data);
transformed = true;
} else {
PTA_TexCoordf texcoords = geom->get_texcoords_array(from_name);
PTA_ushort index = geom->get_texcoords_index(from_name);
@ -184,6 +266,7 @@ transform_texcoords(Geom *geom, const InternalName *from_name,
geom->set_texcoords(to_name, new_texcoords, index);
transformed = true;
}
}
return transformed;
}
@ -229,6 +312,25 @@ transform_texcoords(GeomNode *node, const InternalName *from_name,
////////////////////////////////////////////////////////////////////
bool GeomTransformer::
set_color(Geom *geom, const Colorf &color) {
bool transformed = false;
if (geom->is_exact_type(qpGeom::get_class_type())) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceColors sc;
sc._color = color;
sc._vertex_data = qpgeom->get_vertex_data();
CPT(qpGeomVertexData) &new_data = _qpfcolors[sc];
if (new_data.is_null()) {
// We have not yet converted these colors. Do so now.
new_data = sc._vertex_data->set_color(color);
}
qpgeom->set_vertex_data(new_data);
transformed = true;
} else {
// In this case, we always replace whatever color array was there
// with a new color array containing just this color.
@ -241,7 +343,10 @@ set_color(Geom *geom, const Colorf &color) {
}
geom->set_colors(new_colors, G_OVERALL);
return true;
transformed = true;
}
return transformed;
}
@ -284,6 +389,23 @@ transform_colors(Geom *geom, const LVecBase4f &scale) {
nassertr(geom != (Geom *)NULL, false);
if (geom->is_exact_type(qpGeom::get_class_type())) {
qpGeom *qpgeom = DCAST(qpGeom, geom);
qpSourceColors sc;
sc._color = scale;
sc._vertex_data = qpgeom->get_vertex_data();
CPT(qpGeomVertexData) &new_data = _qptcolors[sc];
if (new_data.is_null()) {
// We have not yet converted these colors. Do so now.
new_data = sc._vertex_data->scale_color(scale);
}
qpgeom->set_vertex_data(new_data);
transformed = true;
} else {
PTA_Colorf colors;
GeomBindType bind;
PTA_ushort index;
@ -317,6 +439,7 @@ transform_colors(Geom *geom, const LVecBase4f &scale) {
geom->set_colors(new_colors, bind, index);
transformed = true;
}
}
return transformed;
}

View File

@ -23,6 +23,7 @@
#include "geom.h"
#include "luse.h"
#include "qpgeomVertexData.h"
class GeomNode;
class RenderState;
@ -68,6 +69,44 @@ public:
bool apply_state(GeomNode *node, const RenderState *state);
private:
class qpSourceVertices {
public:
INLINE bool operator < (const qpSourceVertices &other) const;
LMatrix4f _mat;
CPT(qpGeomVertexData) _vertex_data;
};
typedef pmap<qpSourceVertices, PT(qpGeomVertexData) > NewVertices;
NewVertices _qpvertices;
class qpSourceTexCoords {
public:
INLINE bool operator < (const qpSourceTexCoords &other) const;
LMatrix4f _mat;
CPT(InternalName) _from;
CPT(InternalName) _to;
CPT(qpGeomVertexData) _vertex_data;
};
typedef pmap<qpSourceTexCoords, PT(qpGeomVertexData) > NewTexCoords;
NewTexCoords _qptexcoords;
class qpSourceColors {
public:
INLINE bool operator < (const qpSourceColors &other) const;
LVecBase4f _color;
CPT(qpGeomVertexData) _vertex_data;
};
typedef pmap<qpSourceColors, CPT(qpGeomVertexData) > NewColors;
// We have two concepts of colors: the "fixed" colors, which are
// slapped in complete replacement of the original colors (e.g. via
// a ColorAttrib), and the "transformed" colors, which are modified
// from the original colors (e.g. via a ColorScaleAttrib).
NewColors _qpfcolors, _qptcolors;
class SourceVertices {
public:
INLINE bool operator < (const SourceVertices &other) const;