From bc56b6467bd120b5831d342f4183ff29f5dff792 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 28 Mar 2005 19:13:52 +0000 Subject: [PATCH] animate properly in dx --- panda/src/dxgsg8/dxGeomMunger8.cxx | 15 ++++++++++++++- panda/src/gobj/qpgeomVertexData.cxx | 7 +++++++ panda/src/gobj/qpgeomVertexFormat.cxx | 19 +++++++++++++++++++ panda/src/gobj/qpgeomVertexFormat.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/panda/src/dxgsg8/dxGeomMunger8.cxx b/panda/src/dxgsg8/dxGeomMunger8.cxx index c37417a14f..b5af94f843 100644 --- a/panda/src/dxgsg8/dxGeomMunger8.cxx +++ b/panda/src/dxgsg8/dxGeomMunger8.cxx @@ -32,6 +32,7 @@ munge_format_impl(const qpGeomVertexFormat *orig) { // We have to build a completely new format that includes only the // appropriate components, in the appropriate order, in just one // array. + PT(qpGeomVertexFormat) new_format = new qpGeomVertexFormat(*orig); PT(qpGeomVertexArrayFormat) new_array_format = new qpGeomVertexArrayFormat; const qpGeomVertexDataType *vertex_type = @@ -47,6 +48,7 @@ munge_format_impl(const qpGeomVertexFormat *orig) { new_array_format->add_data_type (InternalName::get_vertex(), 3, qpGeomVertexDataType::NT_float32, qpGeomVertexDataType::C_point); + new_format->remove_data_type(vertex_type->get_name()); } else { // If we don't have a vertex type, not much we can do. return orig; @@ -56,12 +58,14 @@ munge_format_impl(const qpGeomVertexFormat *orig) { new_array_format->add_data_type (InternalName::get_normal(), 3, qpGeomVertexDataType::NT_float32, qpGeomVertexDataType::C_vector); + new_format->remove_data_type(normal_type->get_name()); } if (color_type != (const qpGeomVertexDataType *)NULL) { new_array_format->add_data_type (InternalName::get_color(), 1, qpGeomVertexDataType::NT_packed_8888, qpGeomVertexDataType::C_argb); + new_format->remove_data_type(color_type->get_name()); } // To support multitexture, we will need to add all of the relevant @@ -71,9 +75,18 @@ munge_format_impl(const qpGeomVertexFormat *orig) { new_array_format->add_data_type (InternalName::get_texcoord(), texcoord_type->get_num_values(), qpGeomVertexDataType::NT_float32, qpGeomVertexDataType::C_texcoord); + new_format->remove_data_type(texcoord_type->get_name()); } - PT(qpGeomVertexFormat) new_format = new qpGeomVertexFormat(new_array_format); + if (new_array_format->is_data_subset_of(*orig->get_array(0))) { + // If the new array format we have built is essentially the same + // as the first data array anyway, go ahead and keep the original. + return orig; + } + + // Use the new format; make sure the DX8-friendly array is first in + // the list. + new_format->insert_array(0, new_array_format); return qpGeomVertexFormat::register_format(new_format); } diff --git a/panda/src/gobj/qpgeomVertexData.cxx b/panda/src/gobj/qpgeomVertexData.cxx index d49935634a..14c5505a4b 100644 --- a/panda/src/gobj/qpgeomVertexData.cxx +++ b/panda/src/gobj/qpgeomVertexData.cxx @@ -843,6 +843,13 @@ update_animated_vertices(qpGeomVertexData::CDWriter &cdata, bool from_app) { qpGeomVertexReader from(this, InternalName::get_vertex()); qpGeomVertexReader blendi(this, InternalName::get_transform_blend()); + if (!blendi.has_data_type()) { + gobj_cat.warning() + << "Vertex data " << get_name() + << " has a transform_blend_palette, but no transform_blend data.\n"; + return; + } + if (from.get_data_type()->get_num_values() == 4) { for (int i = 0; i < num_vertices; i++) { LPoint4f vertex = from.get_data4f(); diff --git a/panda/src/gobj/qpgeomVertexFormat.cxx b/panda/src/gobj/qpgeomVertexFormat.cxx index 09b973b828..47710b84ca 100644 --- a/panda/src/gobj/qpgeomVertexFormat.cxx +++ b/panda/src/gobj/qpgeomVertexFormat.cxx @@ -162,6 +162,25 @@ add_array(qpGeomVertexArrayFormat *array_format) { return new_array; } +//////////////////////////////////////////////////////////////////// +// Function: qpGeomVertexFormat::insert_array +// Access: Published +// Description: Adds the indicated array definition to the list of +// arrays at the indicated position. This works just +// like add_array(), except that you can specify which +// array index the new array should have. +// +// This may not be called once the format has been +// registered. +//////////////////////////////////////////////////////////////////// +void qpGeomVertexFormat:: +insert_array(int array, qpGeomVertexArrayFormat *array_format) { + nassertv(!_is_registered); + nassertv(array >= 0 && array <= (int)_arrays.size()); + + _arrays.insert(_arrays.begin() + array, array_format); +} + //////////////////////////////////////////////////////////////////// // Function: qpGeomVertexFormat::clear_arrays // Access: Published diff --git a/panda/src/gobj/qpgeomVertexFormat.h b/panda/src/gobj/qpgeomVertexFormat.h index e0ddf84216..0fd961f2bb 100644 --- a/panda/src/gobj/qpgeomVertexFormat.h +++ b/panda/src/gobj/qpgeomVertexFormat.h @@ -72,6 +72,7 @@ PUBLISHED: void set_array(int array, qpGeomVertexArrayFormat *format); void remove_array(int array); int add_array(qpGeomVertexArrayFormat *array_format); + void insert_array(int array, qpGeomVertexArrayFormat *array_format); void clear_arrays(); int get_num_data_types() const;