From: curt Date: Tue, 26 Feb 2002 20:05:20 +0000 (+0000) Subject: Add initial support for per vertex or per object colors. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=520124c1be9d8089af9efdea7a6170bac3c86938;p=simgear.git Add initial support for per vertex or per object colors. --- diff --git a/simgear/io/sg_binobj.cxx b/simgear/io/sg_binobj.cxx index 404bf101..4e7d2b26 100644 --- a/simgear/io/sg_binobj.cxx +++ b/simgear/io/sg_binobj.cxx @@ -49,6 +49,7 @@ enum { SG_BOUNDING_SPHERE = 0, SG_VERTEX_LIST = 1, + SG_COLOR_LIST = 4, SG_NORMAL_LIST = 2, SG_TEXCOORD_LIST = 3, @@ -312,6 +313,41 @@ bool SGBinObject::read_bin( const string& file ) { 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 ) { @@ -600,6 +636,7 @@ bool SGBinObject::write_bin( const string& base, const string& name, Point3D p; sgVec2 t; sgVec3 pt; + sgVec4 color; 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 << "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 @@ -645,6 +684,7 @@ bool SGBinObject::write_bin( const string& base, const string& name, short nobjects = 0; nobjects++; // for gbs nobjects++; // for vertices + nobjects++; // for colors nobjects++; // for normals nobjects++; // for texcoords @@ -729,6 +769,20 @@ bool SGBinObject::write_bin( const string& base, const string& name, 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 diff --git a/simgear/io/sg_binobj.hxx b/simgear/io/sg_binobj.hxx index bd76ac6a..b8f181ad 100644 --- a/simgear/io/sg_binobj.hxx +++ b/simgear/io/sg_binobj.hxx @@ -92,6 +92,7 @@ class SGBinObject { Point3D gbs_center; float gbs_radius; point_list wgs84_nodes; + point_list colors; 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_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; }