mirror of
https://github.com/aap/librw.git
synced 2025-02-16 17:26:18 +00:00
Small fixes in Geometry.
This commit is contained in:
parent
755bfffccf
commit
c25a7e6f93
@ -18,8 +18,9 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
|
|||||||
{
|
{
|
||||||
this->geoflags = flags & 0xFF00FFFF;
|
this->geoflags = flags & 0xFF00FFFF;
|
||||||
this->numTexCoordSets = (flags & 0xFF0000) >> 16;
|
this->numTexCoordSets = (flags & 0xFF0000) >> 16;
|
||||||
if(this->numTexCoordSets == 0 && (this->geoflags & TEXTURED))
|
if(this->numTexCoordSets == 0)
|
||||||
this->numTexCoordSets = 1;
|
this->numTexCoordSets = (this->geoflags & TEXTURED) ? 1 :
|
||||||
|
(this->geoflags & TEXTURED2) ? 2 : 0;
|
||||||
this->numTriangles = numTris;
|
this->numTriangles = numTris;
|
||||||
this->numVertices = numVerts;
|
this->numVertices = numVerts;
|
||||||
this->numMorphTargets = 1;
|
this->numMorphTargets = 1;
|
||||||
@ -28,7 +29,7 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
|
|||||||
for(int32 i = 0; i < this->numTexCoordSets; i++)
|
for(int32 i = 0; i < this->numTexCoordSets; i++)
|
||||||
this->texCoords[i] = NULL;
|
this->texCoords[i] = NULL;
|
||||||
this->triangles = NULL;
|
this->triangles = NULL;
|
||||||
if(!(this->geoflags & 0xFF000000)){
|
if(!(this->geoflags & NATIVE)){
|
||||||
if(this->geoflags & PRELIT)
|
if(this->geoflags & PRELIT)
|
||||||
this->colors = new uint8[4*this->numVertices];
|
this->colors = new uint8[4*this->numVertices];
|
||||||
if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2))
|
if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2))
|
||||||
@ -41,7 +42,7 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags)
|
|||||||
MorphTarget *m = this->morphTargets;
|
MorphTarget *m = this->morphTargets;
|
||||||
m->vertices = NULL;
|
m->vertices = NULL;
|
||||||
m->normals = NULL;
|
m->normals = NULL;
|
||||||
if(!(this->geoflags & 0xFF000000)){
|
if(!(this->geoflags & NATIVE)){
|
||||||
m->vertices = new float32[3*this->numVertices];
|
m->vertices = new float32[3*this->numVertices];
|
||||||
if(this->geoflags & NORMALS)
|
if(this->geoflags & NORMALS)
|
||||||
m->normals = new float32[3*this->numVertices];
|
m->normals = new float32[3*this->numVertices];
|
||||||
@ -111,13 +112,12 @@ Geometry::streamRead(istream &stream)
|
|||||||
if(version < 0x34000)
|
if(version < 0x34000)
|
||||||
stream.seekg(12, ios::cur);
|
stream.seekg(12, ios::cur);
|
||||||
|
|
||||||
if(!(geo->geoflags & 0xFF000000)){
|
if(!(geo->geoflags & NATIVE)){
|
||||||
if(geo->geoflags & PRELIT)
|
if(geo->geoflags & PRELIT)
|
||||||
stream.read((char*)geo->colors, 4*geo->numVertices);
|
stream.read((char*)geo->colors, 4*geo->numVertices);
|
||||||
if((geo->geoflags & TEXTURED) || (geo->geoflags & TEXTURED2))
|
for(int32 i = 0; i < geo->numTexCoordSets; i++)
|
||||||
for(int32 i = 0; i < geo->numTexCoordSets; i++)
|
stream.read((char*)geo->texCoords[i],
|
||||||
stream.read((char*)geo->texCoords[i],
|
2*geo->numVertices*4);
|
||||||
2*geo->numVertices*4);
|
|
||||||
stream.read((char*)geo->triangles, 4*geo->numTriangles*2);
|
stream.read((char*)geo->triangles, 4*geo->numTriangles*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,10 +157,8 @@ geoStructSize(Geometry *geo)
|
|||||||
if(!(geo->geoflags & 0xFF000000)){
|
if(!(geo->geoflags & 0xFF000000)){
|
||||||
if(geo->geoflags&geo->PRELIT)
|
if(geo->geoflags&geo->PRELIT)
|
||||||
size += 4*geo->numVertices;
|
size += 4*geo->numVertices;
|
||||||
if((geo->geoflags & geo->TEXTURED) ||
|
for(int32 i = 0; i < geo->numTexCoordSets; i++)
|
||||||
(geo->geoflags & geo->TEXTURED2))
|
size += 2*geo->numVertices*4;
|
||||||
for(int32 i = 0; i < geo->numTexCoordSets; i++)
|
|
||||||
size += 2*geo->numVertices*4;
|
|
||||||
size += 4*geo->numTriangles*2;
|
size += 4*geo->numTriangles*2;
|
||||||
}
|
}
|
||||||
for(int32 i = 0; i < geo->numMorphTargets; i++){
|
for(int32 i = 0; i < geo->numMorphTargets; i++){
|
||||||
@ -192,13 +190,12 @@ Geometry::streamWrite(ostream &stream)
|
|||||||
if(Version < 0x34000)
|
if(Version < 0x34000)
|
||||||
stream.write((char*)fbuf, sizeof(fbuf));
|
stream.write((char*)fbuf, sizeof(fbuf));
|
||||||
|
|
||||||
if(!(this->geoflags & 0xFF000000)){
|
if(!(this->geoflags & NATIVE)){
|
||||||
if(this->geoflags & PRELIT)
|
if(this->geoflags & PRELIT)
|
||||||
stream.write((char*)this->colors, 4*this->numVertices);
|
stream.write((char*)this->colors, 4*this->numVertices);
|
||||||
if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2))
|
for(int32 i = 0; i < this->numTexCoordSets; i++)
|
||||||
for(int32 i = 0; i < this->numTexCoordSets; i++)
|
stream.write((char*)this->texCoords[i],
|
||||||
stream.write((char*)this->texCoords[i],
|
2*this->numVertices*4);
|
||||||
2*this->numVertices*4);
|
|
||||||
stream.write((char*)this->triangles, 4*this->numTriangles*2);
|
stream.write((char*)this->triangles, 4*this->numTriangles*2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +251,7 @@ Geometry::addMorphTargets(int32 n)
|
|||||||
MorphTarget *m = &morphTargets[i];
|
MorphTarget *m = &morphTargets[i];
|
||||||
m->vertices = NULL;
|
m->vertices = NULL;
|
||||||
m->normals = NULL;
|
m->normals = NULL;
|
||||||
if(!(this->geoflags & 0xFF000000)){
|
if(!(this->geoflags & NATIVE)){
|
||||||
m->vertices = new float32[3*this->numVertices];
|
m->vertices = new float32[3*this->numVertices];
|
||||||
if(this->geoflags & NORMALS)
|
if(this->geoflags & NORMALS)
|
||||||
m->normals = new float32[3*this->numVertices];
|
m->normals = new float32[3*this->numVertices];
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@ -144,7 +145,8 @@ writeMesh(ostream &stream, int32, void *object, int32, int32)
|
|||||||
geo->numMaterials);
|
geo->numMaterials);
|
||||||
stream.write((char*)buf, 8);
|
stream.write((char*)buf, 8);
|
||||||
if(geo->geoflags & Geometry::NATIVE){
|
if(geo->geoflags & Geometry::NATIVE){
|
||||||
if(mesh->indices)
|
assert(geo->instData != NULL);
|
||||||
|
if(geo->instData->platform == PLATFORM_OGL)
|
||||||
stream.write((char*)mesh->indices,
|
stream.write((char*)mesh->indices,
|
||||||
mesh->numIndices*2);
|
mesh->numIndices*2);
|
||||||
}else{
|
}else{
|
||||||
@ -170,7 +172,8 @@ getSizeMesh(void *object, int32)
|
|||||||
return -1;
|
return -1;
|
||||||
int32 size = 12 + geo->meshHeader->numMeshes*8;
|
int32 size = 12 + geo->meshHeader->numMeshes*8;
|
||||||
if(geo->geoflags & Geometry::NATIVE){
|
if(geo->geoflags & Geometry::NATIVE){
|
||||||
if(geo->meshHeader[0].mesh->indices)
|
assert(geo->instData != NULL);
|
||||||
|
if(geo->instData->platform == PLATFORM_OGL)
|
||||||
size += geo->meshHeader->totalIndices*2;
|
size += geo->meshHeader->totalIndices*2;
|
||||||
}else{
|
}else{
|
||||||
size += geo->meshHeader->totalIndices*4;
|
size += geo->meshHeader->totalIndices*4;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user