Skip to content

Commit

Permalink
fixing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgao committed Feb 7, 2013
1 parent c0d6a6c commit baf570b
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 133 deletions.
193 changes: 99 additions & 94 deletions OpenCTM-1.0.3/lib/openctm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
// _ctmFreeMapList() - Free a float map list.
//-----------------------------------------------------------------------------
static void _ctmFreeMapList(_CTMcontext * self, _CTMfloatmap * aMapList)
{
_CTMfloatmap * map, * nextMap;
{
_CTMfloatmap * map, * nextMap;
map = aMapList;
while(map)
while(map)
{
// Free internally allocated array (if we are in import mode)
// Free internally allocated array (if we are in import mode)
if((self->mMode == CTM_IMPORT) && map->mValues)
free(map->mValues);

Expand All @@ -62,12 +62,12 @@ static void _ctmFreeMapList(_CTMcontext * self, _CTMfloatmap * aMapList)
if(map->mFileName)
free(map->mFileName);

nextMap = map->mNext;
nextMap = map->mNext;
free(map);
map = nextMap;
map = nextMap;
}
}

}

//-----------------------------------------------------------------------------
// _ctmClearMesh() - Clear the mesh in a CTM context.
//-----------------------------------------------------------------------------
Expand All @@ -83,23 +83,23 @@ static void _ctmClearMesh(_CTMcontext * self)
if(self->mNormals)
free(self->mNormals);
}


// Clear externally assigned mesh arrays
self->mVertices = (CTMfloat *) 0;
self->mVertexCount = 0;
self->mIndices = (CTMuint *) 0;
self->mTriangleCount = 0;
self->mNormals = (CTMfloat *) 0;

// Free UV coordinate map list
_ctmFreeMapList(self, self->mUVMaps);
self->mUVMaps = (_CTMfloatmap *) 0;
self->mUVMapCount = 0;

// Free attribute map list
_ctmFreeMapList(self, self->mAttribMaps);
self->mAttribMaps = (_CTMfloatmap *) 0;
self->mAttribMapCount = 0;
self->mTriangleCount = 0;
self->mNormals = (CTMfloat *) 0;

// Free UV coordinate map list
_ctmFreeMapList(self, self->mUVMaps);
self->mUVMaps = (_CTMfloatmap *) 0;
self->mUVMapCount = 0;

// Free attribute map list
_ctmFreeMapList(self, self->mAttribMaps);
self->mAttribMaps = (_CTMfloatmap *) 0;
self->mAttribMapCount = 0;
}

//-----------------------------------------------------------------------------
Expand All @@ -116,6 +116,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
if(!self->mVertices || !self->mIndices || (self->mVertexCount < 1) ||
(self->mTriangleCount < 1))
{
printf("Error in vertex count\n");
return CTM_FALSE;
}

Expand All @@ -124,6 +125,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(self->mIndices[i] >= self->mVertexCount)
{
printf("Index not in vertex length\n");
return CTM_FALSE;
}
}
Expand All @@ -133,6 +135,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(self->mVertices[i]))
{
printf("Vertex is NaN or Inf\n");
return CTM_FALSE;
}
}
Expand All @@ -157,6 +160,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(map->mValues[i]))
{
printf("UVs are NaN or Inf\n");
return CTM_FALSE;
}
}
Expand All @@ -171,6 +175,7 @@ static CTMint _ctmCheckMeshIntegrity(_CTMcontext * self)
{
if(!isfinite(map->mValues[i]))
{
printf("Attribute %s is NaN or Inf at %d\n", map->mName, i);
return CTM_FALSE;
}
}
Expand Down Expand Up @@ -210,12 +215,12 @@ CTMEXPORT void CTMCALL ctmFreeContext(CTMcontext aContext)
_CTMcontext * self = (_CTMcontext *) aContext;
if(!self) return;

// Free all mesh resources
// Free all mesh resources
_ctmClearMesh(self);

// Free the file comment
// Free the file comment
if(self->mFileComment)
free(self->mFileComment);
free(self->mFileComment);

// Free the context
free(self);
Expand Down Expand Up @@ -354,48 +359,48 @@ CTMEXPORT const CTMuint * CTMCALL ctmGetIntegerArray(CTMcontext aContext,
CTMEXPORT const CTMfloat * CTMCALL ctmGetFloatArray(CTMcontext aContext,
CTMenum aProperty)
{
_CTMcontext * self = (_CTMcontext *) aContext;
_CTMfloatmap * map;
_CTMcontext * self = (_CTMcontext *) aContext;
_CTMfloatmap * map;
CTMuint i;
if(!self) return (CTMfloat *) 0;

// Did the user request a UV map?
if((aProperty >= CTM_UV_MAP_1) &&
((CTMuint)(aProperty - CTM_UV_MAP_1) < self->mUVMapCount))
{
map = self->mUVMaps;
i = CTM_UV_MAP_1;
while(map && (i != aProperty))
{
map = map->mNext;
++ i;
}
if(!map)
{
self->mError = CTM_INTERNAL_ERROR;

// Did the user request a UV map?
if((aProperty >= CTM_UV_MAP_1) &&
((CTMuint)(aProperty - CTM_UV_MAP_1) < self->mUVMapCount))
{
map = self->mUVMaps;
i = CTM_UV_MAP_1;
while(map && (i != aProperty))
{
map = map->mNext;
++ i;
}
if(!map)
{
self->mError = CTM_INTERNAL_ERROR;
return (CTMfloat *) 0;
}
}
return map->mValues;
}

// Did the user request an attribute map?
if((aProperty >= CTM_ATTRIB_MAP_1) &&
((CTMuint)(aProperty - CTM_ATTRIB_MAP_1) < self->mAttribMapCount))
{
map = self->mAttribMaps;
i = CTM_ATTRIB_MAP_1;
while(map && (i != aProperty))
{
map = map->mNext;
++ i;
}
if(!map)
{
self->mError = CTM_INTERNAL_ERROR;
}

// Did the user request an attribute map?
if((aProperty >= CTM_ATTRIB_MAP_1) &&
((CTMuint)(aProperty - CTM_ATTRIB_MAP_1) < self->mAttribMapCount))
{
map = self->mAttribMaps;
i = CTM_ATTRIB_MAP_1;
while(map && (i != aProperty))
{
map = map->mNext;
++ i;
}
if(!map)
{
self->mError = CTM_INTERNAL_ERROR;
return (CTMfloat *) 0;
}
}
return map->mValues;
}
}

switch(aProperty)
{
Expand All @@ -416,26 +421,26 @@ CTMEXPORT const CTMfloat * CTMCALL ctmGetFloatArray(CTMcontext aContext,
// ctmGetNamedUVMap()
//-----------------------------------------------------------------------------
CTMEXPORT CTMenum CTMCALL ctmGetNamedUVMap(CTMcontext aContext,
const char * aName)
{
const char * aName)
{
_CTMcontext * self = (_CTMcontext *) aContext;
_CTMfloatmap * map;
_CTMfloatmap * map;
CTMuint result;
if(!self) return CTM_NONE;

map = self->mUVMaps;
result = CTM_UV_MAP_1;
while(map && (strcmp(aName, map->mName) != 0))
{
map = map->mNext;
++ result;
}
if(!map)
{

map = self->mUVMaps;
result = CTM_UV_MAP_1;
while(map && (strcmp(aName, map->mName) != 0))
{
map = map->mNext;
++ result;
}
if(!map)
{
return CTM_NONE;
}
}
return result;
}
}

//-----------------------------------------------------------------------------
// ctmGetUVMapString()
Expand Down Expand Up @@ -596,27 +601,27 @@ CTMEXPORT CTMfloat CTMCALL ctmGetAttribMapFloat(CTMcontext aContext,
// ctmGetNamedAttribMap()
//-----------------------------------------------------------------------------
CTMEXPORT CTMenum CTMCALL ctmGetNamedAttribMap(CTMcontext aContext,
const char * aName)
{
const char * aName)
{
_CTMcontext * self = (_CTMcontext *) aContext;
_CTMfloatmap * map;
_CTMfloatmap * map;
CTMuint result;
if(!self) return CTM_NONE;

map = self->mAttribMaps;
result = CTM_ATTRIB_MAP_1;
while(map && (strcmp(aName, map->mName) != 0))
{
map = map->mNext;
++ result;
}
if(!map)
{

map = self->mAttribMaps;
result = CTM_ATTRIB_MAP_1;
while(map && (strcmp(aName, map->mName) != 0))
{
map = map->mNext;
++ result;
}
if(!map)
{
return CTM_NONE;
}
return result;
}

}
return result;
}

//-----------------------------------------------------------------------------
// ctmGetString()
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1059,7 +1064,7 @@ CTMEXPORT CTMenum CTMCALL ctmAddUVMap(CTMcontext aContext,
if(!map)
return CTM_NONE;
else
{
{
// The default UV coordinate precision is 2^-12
map->mPrecision = 1.0f / 4096.0f;
++ self->mUVMapCount;
Expand Down Expand Up @@ -1152,7 +1157,7 @@ static CTMuint _ctmAllocateFloatMaps(_CTMcontext * self,
}
memset(*mapListPtr, 0, sizeof(_CTMfloatmap));

// Allocate & clear memory for the float array
// Allocate & clear memory for the float array
size = aChannels * sizeof(CTMfloat) * self->mVertexCount;
(*mapListPtr)->mValues = (CTMfloat *) malloc(size);
if(!(*mapListPtr)->mValues)
Expand Down
Loading

0 comments on commit baf570b

Please sign in to comment.