瀏覽代碼

*** empty log message ***

David Rose 25 年之前
父節點
當前提交
cfc277ba6a

+ 6 - 0
panda/src/egg/Sources.pp

@@ -43,6 +43,10 @@
     eggVertexPool.I eggVertexPool.cxx eggVertexPool.h eggXfmAnimData.I \
     eggXfmAnimData.cxx eggXfmAnimData.h eggXfmSAnim.I eggXfmSAnim.cxx \
     eggXfmSAnim.h parserDefs.h parser.yxx lexerDefs.h lexer.lxx \
+    pt_EggMaterial.cxx pt_EggMaterial.h \
+    vector_PT_EggMaterial.cxx vector_PT_EggMaterial.h \
+    pt_EggTexture.cxx pt_EggTexture.h \
+    vector_PT_EggTexture.cxx vector_PT_EggTexture.h \
     pt_EggVertex.cxx pt_EggVertex.h \
     vector_PT_EggVertex.cxx vector_PT_EggVertex.h
 
@@ -67,6 +71,8 @@
     eggUtilities.I eggUtilities.h eggVertex.I eggVertex.h \
     eggVertexPool.I eggVertexPool.h eggXfmAnimData.I eggXfmAnimData.h \
     eggXfmSAnim.I eggXfmSAnim.h \
+    pt_EggMaterial.h vector_PT_EggMaterial.h \
+    pt_EggTexture.h vector_PT_EggTexture.h \
     pt_EggVertex.h vector_PT_EggVertex.h
 
 

+ 9 - 0
panda/src/egg/eggGroupNode.cxx

@@ -52,6 +52,15 @@ operator =(const EggGroupNode &copy) {
   return *this;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: EggGroupNode::Destructor
+//       Access: Public, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+EggGroupNode::
+~EggGroupNode() {
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: EggGroupNode::write

+ 1 - 0
panda/src/egg/eggGroupNode.h

@@ -54,6 +54,7 @@ public:
   EggGroupNode(const string &name = "") : EggNode(name) { }
   EggGroupNode(const EggGroupNode &copy);
   EggGroupNode &operator = (const EggGroupNode &copy);
+  virtual ~EggGroupNode();
 
   virtual void write(ostream &out, int indent_level) const;
 

+ 12 - 12
panda/src/egg/eggMaterial.I

@@ -10,7 +10,7 @@
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 INLINE void EggMaterial::
-set_diff(const RGBColorf &diff) {
+set_diff(const Colorf &diff) {
   _diff = diff;
   _flags |= F_diff;
 }
@@ -42,12 +42,12 @@ has_diff() const {
 //               false.  If so, it simply returns the default diff
 //               color.
 ////////////////////////////////////////////////////////////////////
-INLINE RGBColorf EggMaterial::
+INLINE Colorf EggMaterial::
 get_diff() const {
   if (has_diff()) {
     return _diff;
   } else {
-    return RGBColorf(1.0, 1.0, 1.0);
+    return Colorf(1.0, 1.0, 1.0, 1.0);
   }
 }
 
@@ -57,7 +57,7 @@ get_diff() const {
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 INLINE void EggMaterial::
-set_amb(const RGBColorf &amb) {
+set_amb(const Colorf &amb) {
   _amb = amb;
   _flags |= F_amb;
 }
@@ -89,12 +89,12 @@ has_amb() const {
 //               false.  If so, it simply returns the default amb
 //               color.
 ////////////////////////////////////////////////////////////////////
-INLINE RGBColorf EggMaterial::
+INLINE Colorf EggMaterial::
 get_amb() const {
   if (has_amb()) {
     return _amb;
   } else {
-    return RGBColorf(1.0, 1.0, 1.0);
+    return Colorf(1.0, 1.0, 1.0, 1.0);
   }
 }
 
@@ -104,7 +104,7 @@ get_amb() const {
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 INLINE void EggMaterial::
-set_emit(const RGBColorf &emit) {
+set_emit(const Colorf &emit) {
   _emit = emit;
   _flags |= F_emit;
 }
@@ -136,12 +136,12 @@ has_emit() const {
 //               false.  If so, it simply returns the default emit
 //               color.
 ////////////////////////////////////////////////////////////////////
-INLINE RGBColorf EggMaterial::
+INLINE Colorf EggMaterial::
 get_emit() const {
   if (has_emit()) {
     return _emit;
   } else {
-    return RGBColorf(0.0, 0.0, 0.0);
+    return Colorf(0.0, 0.0, 0.0, 1.0);
   }
 }
 
@@ -151,7 +151,7 @@ get_emit() const {
 //  Description: 
 ////////////////////////////////////////////////////////////////////
 INLINE void EggMaterial::
-set_spec(const RGBColorf &spec) {
+set_spec(const Colorf &spec) {
   _spec = spec;
   _flags |= F_spec;
 }
@@ -183,12 +183,12 @@ has_spec() const {
 //               false.  If so, it simply returns the default spec
 //               color.
 ////////////////////////////////////////////////////////////////////
-INLINE RGBColorf EggMaterial::
+INLINE Colorf EggMaterial::
 get_spec() const {
   if (has_spec()) {
     return _spec;
   } else {
-    return RGBColorf(0.0, 0.0, 0.0);
+    return Colorf(0.0, 0.0, 0.0, 1.0);
   }
 }
 

+ 16 - 0
panda/src/egg/eggMaterial.cxx

@@ -53,6 +53,10 @@ write(ostream &out, int indent_level) const {
       << "<Scalar> diffg { " << get_diff()[1] << " }\n";
     indent(out, indent_level + 2)
       << "<Scalar> diffb { " << get_diff()[2] << " }\n";
+    if (get_diff()[3] != 1.0) {
+      indent(out, indent_level + 2)
+	<< "<Scalar> diffa { " << get_diff()[3] << " }\n";
+    }
   }
 
   if (has_amb()) {
@@ -62,6 +66,10 @@ write(ostream &out, int indent_level) const {
       << "<Scalar> ambg { " << get_amb()[1] << " }\n";
     indent(out, indent_level + 2)
       << "<Scalar> ambb { " << get_amb()[2] << " }\n";
+    if (get_amb()[3] != 1.0) {
+      indent(out, indent_level + 2)
+	<< "<Scalar> amba { " << get_amb()[3] << " }\n";
+    }
   }
 
   if (has_emit()) {
@@ -71,6 +79,10 @@ write(ostream &out, int indent_level) const {
       << "<Scalar> emitg { " << get_emit()[1] << " }\n";
     indent(out, indent_level + 2)
       << "<Scalar> emitb { " << get_emit()[2] << " }\n";
+    if (get_emit()[3] != 1.0) {
+      indent(out, indent_level + 2)
+	<< "<Scalar> emita { " << get_emit()[3] << " }\n";
+    }
   }
 
   if (has_spec()) {
@@ -80,6 +92,10 @@ write(ostream &out, int indent_level) const {
       << "<Scalar> specg { " << get_spec()[1] << " }\n";
     indent(out, indent_level + 2)
       << "<Scalar> specb { " << get_spec()[2] << " }\n";
+    if (get_spec()[3] != 1.0) {
+      indent(out, indent_level + 2)
+	<< "<Scalar> speca { " << get_spec()[3] << " }\n";
+    }
   }
 
   if (has_shininess()) {

+ 12 - 12
panda/src/egg/eggMaterial.h

@@ -31,25 +31,25 @@ public:
   bool is_equivalent_to(const EggMaterial &other, int eq) const;
   bool sorts_less_than(const EggMaterial &other, int eq) const;
 
-  INLINE void set_diff(const RGBColorf &diff);
+  INLINE void set_diff(const Colorf &diff);
   INLINE void clear_diff();
   INLINE bool has_diff() const;
-  INLINE RGBColorf get_diff() const;
+  INLINE Colorf get_diff() const;
 
-  INLINE void set_amb(const RGBColorf &amb);
+  INLINE void set_amb(const Colorf &amb);
   INLINE void clear_amb();
   INLINE bool has_amb() const;
-  INLINE RGBColorf get_amb() const;
+  INLINE Colorf get_amb() const;
 
-  INLINE void set_emit(const RGBColorf &emit);
+  INLINE void set_emit(const Colorf &emit);
   INLINE void clear_emit();
   INLINE bool has_emit() const;
-  INLINE RGBColorf get_emit() const;
+  INLINE Colorf get_emit() const;
 
-  INLINE void set_spec(const RGBColorf &spec);
+  INLINE void set_spec(const Colorf &spec);
   INLINE void clear_spec();
   INLINE bool has_spec() const;
-  INLINE RGBColorf get_spec() const;
+  INLINE Colorf get_spec() const;
 
   INLINE void set_shininess(double shininess);
   INLINE void clear_shininess();
@@ -71,10 +71,10 @@ private:
     F_local     = 0x020
   };
 
-  RGBColorf _diff;
-  RGBColorf _amb;
-  RGBColorf _emit;
-  RGBColorf _spec;
+  Colorf _diff;
+  Colorf _amb;
+  Colorf _emit;
+  Colorf _spec;
   double _shininess;
   bool _local;
   int _flags;

+ 2 - 1
panda/src/egg/eggMaterialCollection.h

@@ -10,6 +10,7 @@
 
 #include "eggMaterial.h"
 #include "eggGroupNode.h"
+#include "vector_PT_EggMaterial.h"
 
 #include <string>
 #include <map>
@@ -30,7 +31,7 @@ class EXPCL_PANDAEGG EggMaterialCollection {
 
 private:
   typedef map<PT(EggMaterial), int> Materials;
-  typedef vector< PT(EggMaterial) > OrderedMaterials;
+  typedef vector_PT_EggMaterial OrderedMaterials;
 
 public:
   typedef OrderedMaterials::const_iterator iterator;

+ 5 - 1
panda/src/egg/eggMorph.h

@@ -21,7 +21,7 @@
 //               kinds of morphs are instantiated from this below.
 ////////////////////////////////////////////////////////////////////
 template<class Parameter>
-class EXPCL_PANDAEGG EggMorph : public Namable {
+class EggMorph : public Namable {
 public:
   INLINE EggMorph(const string &name, const Parameter &offset);
   INLINE void set_offset(const Parameter &offset);
@@ -35,6 +35,10 @@ private:
   Parameter _offset;
 };
 
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, EggMorph<LVector3d>);
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, EggMorph<LVector2d>);
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, EggMorph<LVector4f>);
+
 typedef EggMorph<LVector3d> EggMorphVertex;
 typedef EggMorph<LVector3d> EggMorphNormal;
 typedef EggMorph<LVector2d> EggMorphTexCoord;

+ 1 - 5
panda/src/egg/eggMorphList.h

@@ -17,13 +17,9 @@
 // Description : A collection of <Dxyz>'s or <Duv>'s or some such.
 ////////////////////////////////////////////////////////////////////
 template<class MorphType>
-class EXPCL_PANDAEGG EggMorphList : public set<MorphType> {
+class EggMorphList : public set<MorphType> {
 public:
-
   void write(ostream &out, int indent_level) const;
-
-private:
-  typedef set<MorphType> Morphs;
 };
 
 typedef EggMorphList<EggMorphVertex> EggMorphVertexList;

+ 2 - 1
panda/src/egg/eggTextureCollection.h

@@ -10,6 +10,7 @@
 
 #include "eggTexture.h"
 #include "eggGroupNode.h"
+#include "vector_PT_EggTexture.h"
 
 #include <string>
 #include <map>
@@ -30,7 +31,7 @@ class EXPCL_PANDAEGG EggTextureCollection {
 
 private:
   typedef map<PT(EggTexture), int> Textures;
-  typedef vector< PT(EggTexture) > OrderedTextures;
+  typedef vector_PT_EggTexture OrderedTextures;
 
 public:
   typedef OrderedTextures::const_iterator iterator;

+ 28 - 12
panda/src/egg/parser.yxx

@@ -465,56 +465,72 @@ material_body:
   double value = $<_number>5;
 
   if (cmp_nocase_uh(name, "diffr") == 0) {
-    RGBColorf diff = material->get_diff();
+    Colorf diff = material->get_diff();
     diff[0] = value;
     material->set_diff(diff);
   } else if (cmp_nocase_uh(name, "diffg") == 0) {
-    RGBColorf diff = material->get_diff();
+    Colorf diff = material->get_diff();
     diff[1] = value;
     material->set_diff(diff);
   } else if (cmp_nocase_uh(name, "diffb") == 0) {
-    RGBColorf diff = material->get_diff();
+    Colorf diff = material->get_diff();
     diff[2] = value;
     material->set_diff(diff);
+  } else if (cmp_nocase_uh(name, "diffa") == 0) {
+    Colorf diff = material->get_diff();
+    diff[3] = value;
+    material->set_diff(diff);
 
   } else if (cmp_nocase_uh(name, "ambr") == 0) {
-    RGBColorf amb = material->get_amb();
+    Colorf amb = material->get_amb();
     amb[0] = value;
     material->set_amb(amb);
   } else if (cmp_nocase_uh(name, "ambg") == 0) {
-    RGBColorf amb = material->get_amb();
+    Colorf amb = material->get_amb();
     amb[1] = value;
     material->set_amb(amb);
   } else if (cmp_nocase_uh(name, "ambb") == 0) {
-    RGBColorf amb = material->get_amb();
+    Colorf amb = material->get_amb();
     amb[2] = value;
     material->set_amb(amb);
+  } else if (cmp_nocase_uh(name, "amba") == 0) {
+    Colorf amb = material->get_amb();
+    amb[3] = value;
+    material->set_amb(amb);
 
   } else if (cmp_nocase_uh(name, "emitr") == 0) {
-    RGBColorf emit = material->get_emit();
+    Colorf emit = material->get_emit();
     emit[0] = value;
     material->set_emit(emit);
   } else if (cmp_nocase_uh(name, "emitg") == 0) {
-    RGBColorf emit = material->get_emit();
+    Colorf emit = material->get_emit();
     emit[1] = value;
     material->set_emit(emit);
   } else if (cmp_nocase_uh(name, "emitb") == 0) {
-    RGBColorf emit = material->get_emit();
+    Colorf emit = material->get_emit();
     emit[2] = value;
     material->set_emit(emit);
+  } else if (cmp_nocase_uh(name, "emita") == 0) {
+    Colorf emit = material->get_emit();
+    emit[3] = value;
+    material->set_emit(emit);
 
   } else if (cmp_nocase_uh(name, "specr") == 0) {
-    RGBColorf spec = material->get_spec();
+    Colorf spec = material->get_spec();
     spec[0] = value;
     material->set_spec(spec);
   } else if (cmp_nocase_uh(name, "specg") == 0) {
-    RGBColorf spec = material->get_spec();
+    Colorf spec = material->get_spec();
     spec[1] = value;
     material->set_spec(spec);
   } else if (cmp_nocase_uh(name, "specb") == 0) {
-    RGBColorf spec = material->get_spec();
+    Colorf spec = material->get_spec();
     spec[2] = value;
     material->set_spec(spec);
+  } else if (cmp_nocase_uh(name, "speca") == 0) {
+    Colorf spec = material->get_spec();
+    spec[3] = value;
+    material->set_spec(spec);
 
   } else if (cmp_nocase_uh(name, "shininess") == 0) {
     material->set_shininess(value);

+ 11 - 0
panda/src/egg/pt_EggMaterial.cxx

@@ -0,0 +1,11 @@
+// Filename: pt_EggMaterial.cxx
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "pt_EggMaterial.h"
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma implementation
+#endif

+ 33 - 0
panda/src/egg/pt_EggMaterial.h

@@ -0,0 +1,33 @@
+// Filename: pt_EggMaterial.h
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef PT_EGGMATERIAL_H
+#define PT_EGGMATERIAL_H
+
+#include <pandabase.h>
+
+#include "eggMaterial.h"
+#include <pointerTo.h>
+
+////////////////////////////////////////////////////////////////////
+//       Class : PT_EggMaterial
+// Description : A PT(EggMaterial).  This is defined here solely we can
+//               explicitly export the template class.  It's not
+//               strictly necessary, but it doesn't hurt.
+////////////////////////////////////////////////////////////////////
+
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, PointerToBase<EggMaterial>)
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, PointerTo<EggMaterial>)
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, ConstPointerTo<EggMaterial>)
+
+typedef PointerTo<EggMaterial> PT_EggMaterial;
+typedef ConstPointerTo<EggMaterial> CPT_EggMaterial;
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma interface
+#endif
+
+#endif

+ 11 - 0
panda/src/egg/pt_EggTexture.cxx

@@ -0,0 +1,11 @@
+// Filename: pt_EggTexture.cxx
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "pt_EggTexture.h"
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma implementation
+#endif

+ 33 - 0
panda/src/egg/pt_EggTexture.h

@@ -0,0 +1,33 @@
+// Filename: pt_EggTexture.h
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef PT_EGGTEXTURE_H
+#define PT_EGGTEXTURE_H
+
+#include <pandabase.h>
+
+#include "eggTexture.h"
+#include <pointerTo.h>
+
+////////////////////////////////////////////////////////////////////
+//       Class : PT_EggTexture
+// Description : A PT(EggTexture).  This is defined here solely we can
+//               explicitly export the template class.  It's not
+//               strictly necessary, but it doesn't hurt.
+////////////////////////////////////////////////////////////////////
+
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, PointerToBase<EggTexture>)
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, PointerTo<EggTexture>)
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, ConstPointerTo<EggTexture>)
+
+typedef PointerTo<EggTexture> PT_EggTexture;
+typedef ConstPointerTo<EggTexture> CPT_EggTexture;
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma interface
+#endif
+
+#endif

+ 11 - 0
panda/src/egg/vector_PT_EggMaterial.cxx

@@ -0,0 +1,11 @@
+// Filename: vector_PT_EggMaterial.cxx
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "vector_PT_EggMaterial.h"
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma implementation
+#endif

+ 33 - 0
panda/src/egg/vector_PT_EggMaterial.h

@@ -0,0 +1,33 @@
+// Filename: vector_PT_EggMaterial.h
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef VECTOR_PT_EGGMATERIAL_H
+#define VECTOR_PT_EGGMATERIAL_H
+
+#include <pandabase.h>
+
+#include "eggMaterial.h"
+#include "pt_EggMaterial.h"
+
+#include <vector>
+
+////////////////////////////////////////////////////////////////////
+//       Class : vector_PT_EggMaterial
+// Description : A vector of PT(EggMaterial)'s.  This class is defined once
+//               here, and exported to PANDAEGG.DLL; other packages
+//               that want to use a vector of this type (whether they
+//               need to export it or not) should include this header
+//               file, rather than defining the vector again.
+////////////////////////////////////////////////////////////////////
+
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, std::vector<PT_EggMaterial>)
+typedef vector<PT_EggMaterial> vector_PT_EggMaterial;
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma interface
+#endif
+
+#endif

+ 11 - 0
panda/src/egg/vector_PT_EggTexture.cxx

@@ -0,0 +1,11 @@
+// Filename: vector_PT_EggTexture.cxx
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "vector_PT_EggTexture.h"
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma implementation
+#endif

+ 33 - 0
panda/src/egg/vector_PT_EggTexture.h

@@ -0,0 +1,33 @@
+// Filename: vector_PT_EggTexture.h
+// Created by:  drose (01May01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef VECTOR_PT_EGGTEXTURE_H
+#define VECTOR_PT_EGGTEXTURE_H
+
+#include <pandabase.h>
+
+#include "eggTexture.h"
+#include "pt_EggTexture.h"
+
+#include <vector>
+
+////////////////////////////////////////////////////////////////////
+//       Class : vector_PT_EggTexture
+// Description : A vector of PT(EggTexture)'s.  This class is defined once
+//               here, and exported to PANDAEGG.DLL; other packages
+//               that want to use a vector of this type (whether they
+//               need to export it or not) should include this header
+//               file, rather than defining the vector again.
+////////////////////////////////////////////////////////////////////
+
+EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, std::vector<PT_EggTexture>)
+typedef vector<PT_EggTexture> vector_PT_EggTexture;
+
+// Tell GCC that we'll take care of the instantiation explicitly here.
+#ifdef __GNUC__
+#pragma interface
+#endif
+
+#endif

+ 5 - 9
panda/src/egg2sg/eggLoader.cxx

@@ -887,23 +887,19 @@ get_material_transition(const EggMaterial *egg_mat, bool bface) {
   // EggMaterial.  Create a new Material that matches it.
   PT(Material) mat = new Material;
   if (egg_mat->has_diff()) {
-    RGBColorf diff = egg_mat->get_diff();
-    mat->set_diffuse(Colorf(diff[0], diff[1], diff[2], 1.0));
+    mat->set_diffuse(egg_mat->get_diff());
     // By default, ambient is the same as diffuse, if diffuse is
     // specified but ambient is not.
-    mat->set_ambient(Colorf(diff[0], diff[1], diff[2], 1.0));
+    mat->set_ambient(egg_mat->get_diff());
   }
   if (egg_mat->has_amb()) {
-    RGBColorf amb = egg_mat->get_amb();
-    mat->set_ambient(Colorf(amb[0], amb[1], amb[2], 1.0));
+    mat->set_ambient(egg_mat->get_amb());
   }
   if (egg_mat->has_emit()) {
-    RGBColorf emit = egg_mat->get_emit();
-    mat->set_emission(Colorf(emit[0], emit[1], emit[2], 1.0));
+    mat->set_emission(egg_mat->get_emit());
   }
   if (egg_mat->has_spec()) {
-    RGBColorf spec = egg_mat->get_spec();
-    mat->set_specular(Colorf(spec[0], spec[1], spec[2], 1.0));
+    mat->set_specular(egg_mat->get_spec());
   }
   if (egg_mat->has_shininess()) {
     mat->set_shininess(egg_mat->get_shininess());

+ 1 - 1
pandatool/src/lwoegg/cLwoPolygons.cxx

@@ -247,7 +247,7 @@ make_faces() {
 	egg_vertex->set_pos(pos);
 
 	// Does the vertex used named UV's?
-	if (surface->has_named_uvs()) {
+	if (surface != (CLwoSurface *)NULL && surface->has_named_uvs()) {
 	  string uv_name = surface->get_uv_name();
 	  LPoint2f uv;
 	  if (get_uv(uv_name, pindex, vindex, uv)) {

+ 31 - 41
pandatool/src/lwoegg/cLwoSurface.cxx

@@ -29,7 +29,7 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
   _surface(surface)
 {
   _flags = 0;
-  _color.set(1.0, 1.0, 1.0);
+  _rgb.set(1.0, 1.0, 1.0);
   _checked_material = false;
   _checked_texture = false;
   _map_uvs = NULL;
@@ -42,8 +42,8 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
 
     if (chunk->is_of_type(LwoSurfaceColor::get_class_type())) {
       const LwoSurfaceColor *color = DCAST(LwoSurfaceColor, chunk);
-      _flags |= F_color;
-      _color = color->_color;
+      _flags |= F_rgb;
+      _rgb = color->_color;
 
     } else if (chunk->is_of_type(LwoSurfaceParameter::get_class_type())) {
       const LwoSurfaceParameter *param = DCAST(LwoSurfaceParameter, chunk);
@@ -112,6 +112,20 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) :
       }
     }      
   }
+
+  // Now get the four-component color, based on combining the RGB and
+  // the transparency.
+  _color.set(1.0, 1.0, 1.0, 1.0);
+
+  if ((_flags & F_rgb) != 0) {
+    _color[0] = _rgb[0];
+    _color[1] = _rgb[1];
+    _color[2] = _rgb[2];
+  }
+
+  if ((_flags & F_transparency) != 0) {
+    _color[3] = 1.0 - _transparency;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -148,45 +162,22 @@ apply_properties(EggPrimitive *egg_prim, vector_PT_EggVertex &egg_vertices,
     }
   }
 
-  if (check_material()) {
-    egg_prim->set_material(_egg_material);
-  }
-
-  // We treat color and transparency separately, because Lightwave
-  // does, and this will allow us to treat inherited surfaces a little
-  // more robustly.
-  if ((_flags & F_color) != 0) {
-    Colorf color(1.0, 1.0, 1.0, 1.0);
-    if (egg_prim->has_color()) {
-      color = egg_prim->get_color();
-    }
+  bool has_texture = check_texture();
+  bool has_material = check_material();
 
-    color[0] = _color[0];
-    color[1] = _color[1];
-    color[2] = _color[2];
+  egg_prim->set_color(_color);
 
-    egg_prim->set_color(color);
+  if (has_material) {
+    egg_prim->set_material(_egg_material);
   }
 
-  if (check_texture()) {
-    // Texture overrides the primitive's natural color.
+  if (has_texture) {
     egg_prim->set_texture(_egg_texture);
-    egg_prim->clear_color();
 
     // Assign UV's to the vertices.
     generate_uvs(egg_vertices);
   }
 
-  if ((_flags & F_transparency) != 0) {
-    Colorf color(1.0, 1.0, 1.0, 1.0);
-    if (egg_prim->has_color()) {
-      color = egg_prim->get_color();
-    }
-
-    color[3] = 1.0 - _transparency;
-    egg_prim->set_color(color);
-  }
-
   if ((_flags & F_backface) != 0) {
     egg_prim->set_bface_flag(_backface);
   }
@@ -272,6 +263,11 @@ check_texture() {
     break;
   };
 
+  // Texture overrides the primitive's natural color.
+  _color[0] = 1.0;
+  _color[1] = 1.0;
+  _color[2] = 1.0;
+
   return true;
 }
 
@@ -296,22 +292,16 @@ check_material() {
 
   _egg_material = new EggMaterial(get_name());
 
-  RGBColorf color = _color;
-  if (check_texture()) {
-    // Texturing overrides the color.
-    color.set(1.0, 1.0, 1.0);
-  }
-
   if ((_flags & F_diffuse) != 0) {
-    RGBColorf diffuse = color * _diffuse;
+    Colorf diffuse = _color * _diffuse;
     _egg_material->set_diff(diffuse);
   }
   if ((_flags & F_luminosity) != 0) {
-    RGBColorf luminosity = color * _luminosity;
+    Colorf luminosity = _color * _luminosity;
     _egg_material->set_emit(luminosity);
   }
   if ((_flags & F_specular) != 0) {
-    RGBColorf specular = color * _specular;
+    Colorf specular = _color * _specular;
     _egg_material->set_spec(specular);
   }
 

+ 4 - 2
pandatool/src/lwoegg/cLwoSurface.h

@@ -46,7 +46,7 @@ public:
 
 
   enum Flags {
-    F_color        = 0x0001,
+    F_rgb          = 0x0001,
     F_diffuse      = 0x0002,
     F_luminosity   = 0x0004,
     F_specular     = 0x0008,
@@ -58,7 +58,7 @@ public:
   };
   
   int _flags;
-  RGBColorf _color;
+  RGBColorf _rgb;
   float _diffuse;
   float _luminosity;
   float _specular;
@@ -68,6 +68,8 @@ public:
   float _smooth_angle;
   bool _backface;
 
+  Colorf _color;
+
   LwoToEggConverter *_converter;
   CPT(LwoSurface) _surface;