Skip to content

Commit

Permalink
propagating precision requirments into operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Russ committed Jul 16, 2016
1 parent 5adb0e8 commit fa1d6d8
Show file tree
Hide file tree
Showing 36 changed files with 444 additions and 418 deletions.
16 changes: 8 additions & 8 deletions code/3DSConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void CopyTexture(aiMaterial& mat, D3DS::Texture& texture, aiTextureType type)

// Setup the texture blend factor
if (is_not_qnan(texture.mTextureBlend))
mat.AddProperty<float>( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0));
mat.AddProperty<ai_real>( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0));

// Setup the texture mapping mode
mat.AddProperty<int>((int*)&texture.mMapMode,1,AI_MATKEY_MAPPINGMODE_U(type,0));
Expand All @@ -207,14 +207,14 @@ void CopyTexture(aiMaterial& mat, D3DS::Texture& texture, aiTextureType type)
// FIXME: this is not really correct ...
if (texture.mMapMode == aiTextureMapMode_Mirror)
{
texture.mScaleU *= 2.f;
texture.mScaleV *= 2.f;
texture.mOffsetU /= 2.f;
texture.mOffsetV /= 2.f;
texture.mScaleU *= 2.0;
texture.mScaleV *= 2.0;
texture.mOffsetU /= 2.0;
texture.mOffsetV /= 2.0;
}

// Setup texture UV transformations
mat.AddProperty<float>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
mat.AddProperty<ai_real>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -265,10 +265,10 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material& oldMat,
}

// Opacity
mat.AddProperty<float>( &oldMat.mTransparency,1,AI_MATKEY_OPACITY);
mat.AddProperty<ai_real>( &oldMat.mTransparency,1,AI_MATKEY_OPACITY);

// Bump height scaling
mat.AddProperty<float>( &oldMat.mBumpHeight,1,AI_MATKEY_BUMPSCALING);
mat.AddProperty<ai_real>( &oldMat.mBumpHeight,1,AI_MATKEY_BUMPSCALING);

// Two sided rendering?
if (oldMat.mTwoSided)
Expand Down
42 changes: 21 additions & 21 deletions code/3DSHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ struct Texture
{
//! Default constructor
Texture()
: mOffsetU (0.0f)
, mOffsetV (0.0f)
, mScaleU (1.0f)
, mScaleV (1.0f)
, mRotation (0.0f)
: mOffsetU (0.0)
, mOffsetV (0.0)
, mScaleU (1.0)
, mScaleV (1.0)
, mRotation (0.0)
, mMapMode (aiTextureMapMode_Wrap)
, bPrivate()
, iUVSrc (0)
Expand All @@ -340,17 +340,17 @@ struct Texture
}

//! Specifies the blend factor for the texture
float mTextureBlend;
ai_real mTextureBlend;

//! Specifies the filename of the texture
std::string mMapName;

//! Specifies texture coordinate offsets/scaling/rotations
float mOffsetU;
float mOffsetV;
float mScaleU;
float mScaleV;
float mRotation;
ai_real mOffsetU;
ai_real mOffsetV;
ai_real mScaleU;
ai_real mScaleV;
ai_real mRotation;

//! Specifies the mapping mode to be used for the texture
aiTextureMapMode mMapMode;
Expand All @@ -369,12 +369,12 @@ struct Material
//! Default constructor. Builds a default name for the material
Material()
:
mDiffuse (0.6f,0.6f,0.6f), // FIX ... we won't want object to be black
mSpecularExponent (0.0f),
mShininessStrength (1.0f),
mDiffuse (0.6,0.6,0.6), // FIX ... we won't want object to be black
mSpecularExponent (0.0),
mShininessStrength (1.0),
mShading(Discreet3DS::Gouraud),
mTransparency (1.0f),
mBumpHeight (1.0f),
mTransparency (1.0),
mBumpHeight (1.0),
mTwoSided (false)
{
static int iCnt = 0;
Expand All @@ -389,17 +389,17 @@ struct Material
//! Diffuse color of the material
aiColor3D mDiffuse;
//! Specular exponent
float mSpecularExponent;
ai_real mSpecularExponent;
//! Shininess strength, in percent
float mShininessStrength;
ai_real mShininessStrength;
//! Specular color of the material
aiColor3D mSpecular;
//! Ambient color of the material
aiColor3D mAmbient;
//! Shading type to be used
Discreet3DS::shadetype3ds mShading;
//! Opacity of the material
float mTransparency;
ai_real mTransparency;
//! Diffuse texture channel
Texture sTexDiffuse;
//! Opacity texture channel
Expand All @@ -415,7 +415,7 @@ struct Material
//! Shininess texture channel
Texture sTexShininess;
//! Scaling factor for the bump values
float mBumpHeight;
ai_real mBumpHeight;
//! Emissive color
aiColor3D mEmissive;
//! Ambient texture channel
Expand Down Expand Up @@ -459,7 +459,7 @@ struct Mesh : public MeshWithSmoothingGroups<D3DS::Face>
struct aiFloatKey
{
double mTime; ///< The time of this key
float mValue; ///< The value of this key
ai_real mValue; ///< The value of this key

#ifdef __cplusplus

Expand Down
52 changes: 26 additions & 26 deletions code/3DSLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,20 @@ void Discreet3DSImporter::ParseChunk(const char* name, unsigned int num)
camera->mLookAt.x = stream->GetF4() - camera->mPosition.x;
camera->mLookAt.y = stream->GetF4() - camera->mPosition.y;
camera->mLookAt.z = stream->GetF4() - camera->mPosition.z;
float len = camera->mLookAt.Length();
if (len < 1e-5f) {
ai_real len = camera->mLookAt.Length();
if (len < 1e-5) {

// There are some files with lookat == position. Don't know why or whether it's ok or not.
DefaultLogger::get()->error("3DS: Unable to read proper camera look-at vector");
camera->mLookAt = aiVector3D(0.f,1.f,0.f);
camera->mLookAt = aiVector3D(0.0,1.0,0.0);

}
else camera->mLookAt /= len;

// And finally - the camera rotation angle, in counter clockwise direction
const float angle = AI_DEG_TO_RAD( stream->GetF4() );
const ai_real angle = AI_DEG_TO_RAD( stream->GetF4() );
aiQuaternion quat(camera->mLookAt,angle);
camera->mUp = quat.GetMatrix() * aiVector3D(0.f,1.f,0.f);
camera->mUp = quat.GetMatrix() * aiVector3D(0.0,1.0,0.0);

// Read the lense angle
camera->mHorizontalFOV = AI_DEG_TO_RAD ( stream->GetF4() );
Expand Down Expand Up @@ -1167,13 +1167,13 @@ void Discreet3DSImporter::ParseMaterialChunk()
case Discreet3DS::CHUNK_MAT_TRANSPARENCY:
{
// This is the material's transparency
float* pcf = &mScene->mMaterials.back().mTransparency;
ai_real* pcf = &mScene->mMaterials.back().mTransparency;
*pcf = ParsePercentageChunk();

// NOTE: transparency, not opacity
if (is_qnan(*pcf))
*pcf = 1.0f;
else *pcf = 1.0f - *pcf * (float)0xFFFF / 100.0f;
*pcf = 1.0;
else *pcf = 1.0 - *pcf * (ai_real)0xFFFF / 100.0;
}
break;

Expand All @@ -1189,30 +1189,30 @@ void Discreet3DSImporter::ParseMaterialChunk()

case Discreet3DS::CHUNK_MAT_SHININESS:
{ // This is the shininess of the material
float* pcf = &mScene->mMaterials.back().mSpecularExponent;
ai_real* pcf = &mScene->mMaterials.back().mSpecularExponent;
*pcf = ParsePercentageChunk();
if (is_qnan(*pcf))
*pcf = 0.0f;
else *pcf *= (float)0xFFFF;
*pcf = 0.0;
else *pcf *= (ai_real)0xFFFF;
}
break;

case Discreet3DS::CHUNK_MAT_SHININESS_PERCENT:
{ // This is the shininess strength of the material
float* pcf = &mScene->mMaterials.back().mShininessStrength;
ai_real* pcf = &mScene->mMaterials.back().mShininessStrength;
*pcf = ParsePercentageChunk();
if (is_qnan(*pcf))
*pcf = 0.0f;
else *pcf *= (float)0xffff / 100.0f;
*pcf = 0.0;
else *pcf *= (ai_real)0xffff / 100.0;
}
break;

case Discreet3DS::CHUNK_MAT_SELF_ILPCT:
{ // This is the self illumination strength of the material
float f = ParsePercentageChunk();
ai_real f = ParsePercentageChunk();
if (is_qnan(f))
f = 0.0f;
else f *= (float)0xFFFF / 100.0f;
f = 0.0;
else f *= (ai_real)0xFFFF / 100.0;
mScene->mMaterials.back().mEmissive = aiColor3D(f,f,f);
}
break;
Expand Down Expand Up @@ -1277,7 +1277,7 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)

case Discreet3DS::CHUNK_PERCENTW:
// Manually parse the blend factor
pcOut->mTextureBlend = (float)((uint16_t)stream->GetI2()) / 100.0f;
pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / 100.0;
break;

case Discreet3DS::CHUNK_MAT_MAP_USCALE:
Expand Down Expand Up @@ -1336,15 +1336,15 @@ void Discreet3DSImporter::ParseTextureChunk(D3DS::Texture* pcOut)

// ------------------------------------------------------------------------------------------------
// Read a percentage chunk
float Discreet3DSImporter::ParsePercentageChunk()
ai_real Discreet3DSImporter::ParsePercentageChunk()
{
Discreet3DS::Chunk chunk;
ReadChunk(&chunk);

if (Discreet3DS::CHUNK_PERCENTF == chunk.Flag)
return stream->GetF4();
else if (Discreet3DS::CHUNK_PERCENTW == chunk.Flag)
return (float)((uint16_t)stream->GetI2()) / (float)0xFFFF;
return (ai_real)((uint16_t)stream->GetI2()) / (ai_real)0xFFFF;
return get_qnan();
}

Expand All @@ -1356,7 +1356,7 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,
ai_assert(out != NULL);

// error return value
const float qnan = get_qnan();
const ai_real qnan = get_qnan();
static const aiColor3D clrError = aiColor3D(qnan,qnan,qnan);

Discreet3DS::Chunk chunk;
Expand All @@ -1372,7 +1372,7 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,
bGamma = true;

case Discreet3DS::CHUNK_RGBF:
if (sizeof(float) * 3 > diff) {
if (sizeof(ai_real) * 3 > diff) {
*out = clrError;
return;
}
Expand All @@ -1388,9 +1388,9 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,
*out = clrError;
return;
}
out->r = (float)(uint8_t)stream->GetI1() / 255.0f;
out->g = (float)(uint8_t)stream->GetI1() / 255.0f;
out->b = (float)(uint8_t)stream->GetI1() / 255.0f;
out->r = (ai_real)(uint8_t)stream->GetI1() / 255.0;
out->g = (ai_real)(uint8_t)stream->GetI1() / 255.0;
out->b = (ai_real)(uint8_t)stream->GetI1() / 255.0;
break;

// Percentage chunks are accepted, too.
Expand All @@ -1404,7 +1404,7 @@ void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,

case Discreet3DS::CHUNK_PERCENTW:
if (acceptPercent && 1 <= diff) {
out->g = out->b = out->r = (float)(uint8_t)stream->GetI1() / 255.0f;
out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / 255.0;
break;
}
*out = clrError;
Expand Down
4 changes: 2 additions & 2 deletions code/3DSLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Discreet3DSImporter : public BaseImporter
* chunk behind afterwards. If no percentage chunk is found
* QNAN is returned.
*/
float ParsePercentageChunk();
ai_real ParsePercentageChunk();

// -------------------------------------------------------------------
/** Parse a color chunk. mCurrent will point to the next
Expand Down Expand Up @@ -265,7 +265,7 @@ class Discreet3DSImporter : public BaseImporter
aiColor3D mClrAmbient;

/** Master scaling factor of the scene */
float mMasterScale;
ai_real mMasterScale;

/** Path to the background image of the scene */
std::string mBackgroundImage;
Expand Down
6 changes: 3 additions & 3 deletions code/ASELoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,10 @@ void CopyASETexture(aiMaterial& mat, ASE::Texture& texture, aiTextureType type)

// Setup the texture blend factor
if (is_not_qnan(texture.mTextureBlend))
mat.AddProperty<float>( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0));
mat.AddProperty<ai_real>( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0));

// Setup texture UV transformations
mat.AddProperty<float>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
mat.AddProperty<ai_real>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
}

// ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -865,7 +865,7 @@ void ASEImporter::ConvertMaterial(ASE::Material& mat)
}

// opacity
mat.pcInstance->AddProperty<float>( &mat.mTransparency,1,AI_MATKEY_OPACITY);
mat.pcInstance->AddProperty<ai_real>( &mat.mTransparency,1,AI_MATKEY_OPACITY);

// Two sided rendering?
if (mat.mTwoSided)
Expand Down
Loading

0 comments on commit fa1d6d8

Please sign in to comment.