From 1e6729a1e7694731ac4733941193395980781c86 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 13 Feb 2007 19:10:51 +0000 Subject: [PATCH] fix combining animated with unanimated vertices --- panda/src/pgraph/geomTransformer.I | 3 ++ panda/src/pgraph/geomTransformer.cxx | 41 ++++++++++++++++++++++++---- panda/src/pgraph/geomTransformer.h | 1 + panda/src/pgraph/sceneGraphReducer.h | 12 ++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/panda/src/pgraph/geomTransformer.I b/panda/src/pgraph/geomTransformer.I index d4ebe45349..c111c50cfe 100644 --- a/panda/src/pgraph/geomTransformer.I +++ b/panda/src/pgraph/geomTransformer.I @@ -99,5 +99,8 @@ operator < (const GeomTransformer::NewCollectedKey &other) const { if (_usage_hint != other._usage_hint) { return (int)_usage_hint < (int)other._usage_hint; } + if (_animation_type != other._animation_type) { + return (int)_animation_type < (int)other._animation_type; + } return _name < other._name; } diff --git a/panda/src/pgraph/geomTransformer.cxx b/panda/src/pgraph/geomTransformer.cxx index 90746a0a43..f7873dd018 100644 --- a/panda/src/pgraph/geomTransformer.cxx +++ b/panda/src/pgraph/geomTransformer.cxx @@ -28,6 +28,7 @@ #include "pStatCollector.h" #include "pStatTimer.h" #include "vector_int.h" +#include "userVertexTransform.h" static PStatCollector apply_vertex_collector("*:Flatten:apply:vertex"); static PStatCollector apply_texcoord_collector("*:Flatten:apply:texcoord"); @@ -414,7 +415,16 @@ collect_vertex_data(Geom *geom, int collect_bits) { if ((collect_bits & SceneGraphReducer::CVD_format) != 0) { key._format = format; } - key._usage_hint = vdata->get_usage_hint(); + if ((collect_bits & SceneGraphReducer::CVD_usage_hint) != 0) { + key._usage_hint = vdata->get_usage_hint(); + } else { + key._usage_hint = Geom::UH_unspecified; + } + if ((collect_bits & SceneGraphReducer::CVD_animation_type) != 0) { + key._animation_type = format->get_animation().get_animation_type(); + } else { + key._animation_type = Geom::AT_none; + } AlreadyCollected::const_iterator ai; ai = _already_collected.find(vdata); @@ -492,9 +502,20 @@ collect_vertex_data(Geom *geom, int collect_bits) { // slightly different kinds of data. typedef vector_int IndexMap; - if (vdata->get_transform_table() != (TransformTable *)NULL) { + if (vdata->get_transform_table() != (TransformTable *)NULL || + new_data->get_transform_table() != (TransformTable *)NULL) { // The TransformTable. - const TransformTable *old_table = vdata->get_transform_table(); + CPT(TransformTable) old_table; + if (vdata->get_transform_table() != (TransformTable *)NULL) { + old_table = vdata->get_transform_table(); + } else { + PT(TransformTable) temp_table = new TransformTable; + // There's an implicit identity transform for all nodes. + PT(VertexTransform) identity_transform = new UserVertexTransform("identity"); + temp_table->add_transform(identity_transform); + old_table = TransformTable::register_table(temp_table); + } + // First, build a mapping of the transforms we already have in the // current table. We must do this because the TransformTable // doesn't automatically unquify index numbers for us (it doesn't @@ -560,11 +581,21 @@ collect_vertex_data(Geom *geom, int collect_bits) { } } - if (vdata->get_transform_blend_table() != (TransformBlendTable *)NULL) { + if (vdata->get_transform_blend_table() != (TransformBlendTable *)NULL || + new_data->get_transform_blend_table() != (TransformBlendTable *)NULL) { // The TransformBlendTable. This one is the easiest, because we // can modify it directly, and it will uniquify blend objects for // us. - const TransformBlendTable *old_btable = vdata->get_transform_blend_table(); + CPT(TransformBlendTable) old_btable; + if (vdata->get_transform_blend_table() != (TransformBlendTable *)NULL) { + old_btable = vdata->get_transform_blend_table(); + } else { + PT(TransformBlendTable) temp_btable; + temp_btable = new TransformBlendTable; + temp_btable->add_blend(TransformBlend()); + old_btable = temp_btable; + } + PT(TransformBlendTable) new_btable; if (new_data->get_transform_blend_table() != (TransformBlendTable *)NULL) { new_btable = new_data->modify_transform_blend_table(); diff --git a/panda/src/pgraph/geomTransformer.h b/panda/src/pgraph/geomTransformer.h index ea21b311c4..cb70abd90c 100644 --- a/panda/src/pgraph/geomTransformer.h +++ b/panda/src/pgraph/geomTransformer.h @@ -128,6 +128,7 @@ private: string _name; CPT(GeomVertexFormat) _format; Geom::UsageHint _usage_hint; + Geom::AnimationType _animation_type; }; typedef pmap< NewCollectedKey, PT(GeomVertexData) > NewCollectedData; NewCollectedData _new_collected_data; diff --git a/panda/src/pgraph/sceneGraphReducer.h b/panda/src/pgraph/sceneGraphReducer.h index 76fa88f848..5c04433a50 100644 --- a/panda/src/pgraph/sceneGraphReducer.h +++ b/panda/src/pgraph/sceneGraphReducer.h @@ -93,6 +93,18 @@ PUBLISHED: // formats may be combined by expanding all GeomVertexDatas to the // union of all defined columns. CVD_format = 0x020, + + // If set, two GeomVertexDatas with different usage hints (for + // instance, UH_static vs. UH_dynamic) will not be collected + // together. + CVD_usage_hint = 0x040, + + // If set, GeomVertexDatas with unanimated vertices will not be + // combined with GeomVertexDatas with animated vertices. Although + // it is legal to mix unanimated and animated vertex datas, doing + // so will convert the unanimated vertices to animated vertices, + // which can result in additional processing requirements. + CVD_animation_type = 0x080, }; enum MakeNonindexed {