]> git.mxchange.org Git - simgear.git/commitdiff
Add initial support for per vertex or per object colors.
authorcurt <curt>
Tue, 26 Feb 2002 20:05:20 +0000 (20:05 +0000)
committercurt <curt>
Tue, 26 Feb 2002 20:05:20 +0000 (20:05 +0000)
simgear/io/sg_binobj.cxx
simgear/io/sg_binobj.hxx

index 404bf10126108dbce4d421c5fa10c0d9cb652c5a..4e7d2b266689e85537dd907a97c64bb4002b28ba 100644 (file)
@@ -49,6 +49,7 @@ enum {
     SG_BOUNDING_SPHERE = 0,
 
     SG_VERTEX_LIST = 1,
     SG_BOUNDING_SPHERE = 0,
 
     SG_VERTEX_LIST = 1,
+    SG_COLOR_LIST = 4,
     SG_NORMAL_LIST = 2,
     SG_TEXCOORD_LIST = 3,
 
     SG_NORMAL_LIST = 2,
     SG_TEXCOORD_LIST = 3,
 
@@ -312,6 +313,41 @@ bool SGBinObject::read_bin( const string& file ) {
                    fptr += 3;
                }
            }
                    fptr += 3;
                }
            }
+       } else if ( obj_type == SG_COLOR_LIST ) {
+           // read color list properties
+           for ( j = 0; j < nproperties; ++j ) {
+               char prop_type;
+               sgReadChar( fp, &prop_type );
+
+               sgReadUInt( fp, &nbytes );
+               // cout << "property size = " << nbytes << endl;
+               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
+               char *ptr = buf.get_ptr();
+               sgReadBytes( fp, nbytes, ptr );
+           }
+
+           // read color list elements
+           for ( j = 0; j < nelements; ++j ) {
+               sgReadUInt( fp, &nbytes );
+               // cout << "element size = " << nbytes << endl;
+               if ( nbytes > buf.get_size() ) { buf.resize( nbytes ); }
+               char *ptr = buf.get_ptr();
+               sgReadBytes( fp, nbytes, ptr );
+               int count = nbytes / (sizeof(float) * 4);
+               float *fptr = (float *)ptr;
+               for ( k = 0; k < count; ++k ) {
+                   if ( sgIsBigEndian() ) {
+                       sgEndianSwap( (unsigned int *)&(fptr[0]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[1]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[2]) );
+                       sgEndianSwap( (unsigned int *)&(fptr[3]) );
+                   }
+                   p = Point3D( fptr[0], fptr[1], fptr[2] );
+                   // cout << "node = " << p << endl;
+                   colors.push_back( p );
+                   fptr += 4;
+               }
+           }
        } else if ( obj_type == SG_NORMAL_LIST ) {
            // read normal list properties
            for ( j = 0; j < nproperties; ++j ) {
        } else if ( obj_type == SG_NORMAL_LIST ) {
            // read normal list properties
            for ( j = 0; j < nproperties; ++j ) {
@@ -600,6 +636,7 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     Point3D p;
     sgVec2 t;
     sgVec3 pt;
     Point3D p;
     sgVec2 t;
     sgVec3 pt;
+    sgVec4 color;
     int i, j;
 
     string dir = base + "/" + b.gen_base_path();
     int i, j;
 
     string dir = base + "/" + b.gen_base_path();
@@ -630,7 +667,9 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     cout << "fans size = " << fans_v.size() << "  fan_materials = " 
         << fan_materials.size() << endl;
 
     cout << "fans size = " << fans_v.size() << "  fan_materials = " 
         << fan_materials.size() << endl;
 
-    cout << "points = " << wgs84_nodes.size() << endl;
+    cout << "nodes = " << wgs84_nodes.size() << endl;
+    cout << "colors = " << colors.size() << endl;
+    cout << "normals = " << normals.size() << endl;
     cout << "tex coords = " << texcoords.size() << endl;
 
     // write header magic
     cout << "tex coords = " << texcoords.size() << endl;
 
     // write header magic
@@ -645,6 +684,7 @@ bool SGBinObject::write_bin( const string& base, const string& name,
     short nobjects = 0;
     nobjects++;                        // for gbs
     nobjects++;                        // for vertices
     short nobjects = 0;
     nobjects++;                        // for gbs
     nobjects++;                        // for vertices
+    nobjects++;                        // for colors
     nobjects++;                        // for normals
     nobjects++;                        // for texcoords
 
     nobjects++;                        // for normals
     nobjects++;                        // for texcoords
 
@@ -729,6 +769,20 @@ bool SGBinObject::write_bin( const string& base, const string& name,
        sgWriteVec3( fp, pt );
     }
 
        sgWriteVec3( fp, pt );
     }
 
+    // dump vertex color list
+    sgWriteChar( fp, (char)SG_COLOR_LIST );             // type
+    sgWriteShort( fp, 0 );                              // nproperties
+    sgWriteShort( fp, 1 );                              // nelements
+    sgWriteUInt( fp, colors.size() * sizeof(float) * 4 ); // nbytes
+    for ( i = 0; i < (int)colors.size(); ++i ) {
+       p = colors[i];
+        // Right now we have a place holder for color alpha but we
+        // need to update the interface so the calling program can
+        // provide the info.
+       sgSetVec4( color, p.x(), p.y(), p.z(), 1.0 );
+       sgWriteVec4( fp, color );
+    }
+
     // dump vertex normal list
     sgWriteChar( fp, (char)SG_NORMAL_LIST );            // type
     sgWriteShort( fp, 0 );                             // nproperties
     // dump vertex normal list
     sgWriteChar( fp, (char)SG_NORMAL_LIST );            // type
     sgWriteShort( fp, 0 );                             // nproperties
index bd76ac6a3f54cdb73447fc47c6bd41960682fd07..b8f181ad6d9efe0ea982963d626b41b3984dcc1e 100644 (file)
@@ -92,6 +92,7 @@ class SGBinObject {
     Point3D gbs_center;
     float gbs_radius;
     point_list wgs84_nodes;
     Point3D gbs_center;
     float gbs_radius;
     point_list wgs84_nodes;
+    point_list colors;
     point_list normals;
     point_list texcoords;
     group_list pts_v;
     point_list normals;
     point_list texcoords;
     group_list pts_v;
@@ -119,6 +120,9 @@ public:
     inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
     inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
 
     inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
     inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
 
+    inline point_list get_colors() const { return colors; }
+    inline void set_colors( point_list c ) { colors = c; }
+
     inline point_list get_normals() const { return normals; }
     inline void set_normals( point_list n ) { normals = n; }
 
     inline point_list get_normals() const { return normals; }
     inline void set_normals( point_list n ) { normals = n; }