{
//! Default constructor. Builds a default name for the material
Material()
- :
- 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.0),
- mBumpHeight (1.0),
- mTwoSided (false)
+ : mDiffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) // FIX ... we won't want object to be black
+ , mSpecularExponent ( ai_real( 0.0 ) )
+ , mShininessStrength ( ai_real( 1.0 ) )
+ , mShading(Discreet3DS::Gouraud)
+ , mTransparency ( ai_real( 1.0 ) )
+ , mBumpHeight ( ai_real( 1.0 ) )
+ , mTwoSided (false)
{
static int iCnt = 0;
case Discreet3DS::CHUNK_MAT_TRANSPARENCY:
{
- // This is the material's transparency
- ai_real* pcf = &mScene->mMaterials.back().mTransparency;
- *pcf = ParsePercentageChunk();
-
- // NOTE: transparency, not opacity
- if (is_qnan(*pcf))
- *pcf = 1.0;
- else *pcf = 1.0 - *pcf * (ai_real)0xFFFF / 100.0;
+ // This is the material's transparency
+ ai_real* pcf = &mScene->mMaterials.back().mTransparency;
+ *pcf = ParsePercentageChunk();
+
+ // NOTE: transparency, not opacity
+ if (is_qnan(*pcf))
+ *pcf = ai_real( 1.0 );
+ else
+ *pcf = ai_real( 1.0 ) - *pcf * (ai_real)0xFFFF / ai_real( 100.0 );
}
break;
case Discreet3DS::CHUNK_MAT_SHININESS_PERCENT:
{ // This is the shininess strength of the material
- ai_real* pcf = &mScene->mMaterials.back().mShininessStrength;
- *pcf = ParsePercentageChunk();
- if (is_qnan(*pcf))
- *pcf = 0.0;
- else *pcf *= (ai_real)0xffff / 100.0;
+ ai_real* pcf = &mScene->mMaterials.back().mShininessStrength;
+ *pcf = ParsePercentageChunk();
+ if (is_qnan(*pcf))
+ *pcf = ai_real( 0.0 );
+ else
+ *pcf *= (ai_real)0xffff / ai_real( 100.0 );
}
break;
case Discreet3DS::CHUNK_MAT_SELF_ILPCT:
{ // This is the self illumination strength of the material
- ai_real f = ParsePercentageChunk();
- if (is_qnan(f))
- f = 0.0;
- else f *= (ai_real)0xFFFF / 100.0;
- mScene->mMaterials.back().mEmissive = aiColor3D(f,f,f);
+ ai_real f = ParsePercentageChunk();
+ if (is_qnan(f))
+ f = ai_real( 0.0 );
+ else
+ f *= (ai_real)0xFFFF / ai_real( 100.0 );
+ mScene->mMaterials.back().mEmissive = aiColor3D(f,f,f);
}
break;
case Discreet3DS::CHUNK_PERCENTD:
// Manually parse the blend factor
- pcOut->mTextureBlend = stream->GetF8();
+ pcOut->mTextureBlend = ai_real( stream->GetF8() );
break;
case Discreet3DS::CHUNK_PERCENTF:
case Discreet3DS::CHUNK_PERCENTW:
// Manually parse the blend factor
- pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / 100.0;
+ pcOut->mTextureBlend = (ai_real)((uint16_t)stream->GetI2()) / ai_real( 100.0 );
break;
case Discreet3DS::CHUNK_MAT_MAP_USCALE:
// ------------------------------------------------------------------------------------------------
// Read a color chunk. If a percentage chunk is found instead it is read as a grayscale color
-void Discreet3DSImporter::ParseColorChunk(aiColor3D* out,
- bool acceptPercent)
+void Discreet3DSImporter::ParseColorChunk( aiColor3D* out, bool acceptPercent )
{
ai_assert(out != NULL);
case Discreet3DS::CHUNK_LINRGBB:
bGamma = true;
case Discreet3DS::CHUNK_RGBB:
- if (sizeof(char) * 3 > diff) {
- *out = clrError;
- return;
+ {
+ if ( sizeof( char ) * 3 > diff ) {
+ *out = clrError;
+ return;
+ }
+ const ai_real invVal = ai_real( 1.0 ) / ai_real( 255.0 );
+ out->r = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal;
+ out->g = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal;
+ out->b = ( ai_real ) ( uint8_t ) stream->GetI1() * invVal;
}
- 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.
case Discreet3DS::CHUNK_PERCENTW:
if (acceptPercent && 1 <= diff) {
- out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / 255.0;
+ out->g = out->b = out->r = (ai_real)(uint8_t)stream->GetI1() / ai_real( 255.0 );
break;
}
*out = clrError;
// check that all textures has same size
if(src_texture_4check.size() > 1)
{
- for(uint8_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++)
+ for (size_t i = 0, i_e = (src_texture_4check.size() - 1); i < i_e; i++)
{
if((src_texture_4check[i]->Width != src_texture_4check[i + 1]->Width) || (src_texture_4check[i]->Height != src_texture_4check[i + 1]->Height) ||
(src_texture_4check[i]->Depth != src_texture_4check[i + 1]->Depth))
if (TokenMatch(filePtr,"MATERIAL_TRANSPARENCY",21))
{
ParseLV4MeshFloat(mat.mTransparency);
- mat.mTransparency = 1.0 - mat.mTransparency;continue;
+ mat.mTransparency = ai_real( 1.0 ) - mat.mTransparency;
+ continue;
}
// material self illumination
if (TokenMatch(filePtr,"MATERIAL_SELFILLUM",18))
// Writes the asset header
void ColladaExporter::WriteHeader()
{
- static const ai_real epsilon = 0.00001;
+ static const ai_real epsilon = ai_real( 0.00001 );
static const aiQuaternion x_rot(aiMatrix3x3(
0, -1, 0,
1, 0, 0,
continue;
// resolve the data pointers for all anim channels. Find the minimum time while we're at it
- ai_real startTime = 1e20, endTime = -1e20;
+ ai_real startTime = ai_real( 1e20 ), endTime = ai_real( -1e20 );
for( std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
{
Collada::ChannelEntry& e = *it;
resultTrafos.push_back( mat);
// find next point in time to evaluate. That's the closest frame larger than the current in any channel
- ai_real nextTime = 1e20;
+ ai_real nextTime = ai_real( 1e20 );
for( std::vector<Collada::ChannelEntry>::iterator it = entries.begin(); it != entries.end(); ++it)
{
Collada::ChannelEntry& channelElement = *it;
case TF_ROTATE:
{
aiMatrix4x4 rot;
- ai_real angle = tf.f[3] * ai_real( AI_MATH_PI) / 180.0;
+ ai_real angle = tf.f[3] * ai_real( AI_MATH_PI) / ai_real( 180.0 );
aiVector3D axis( tf.f[0], tf.f[1], tf.f[2]);
aiMatrix4x4::Rotation( angle, axis, rot);
res *= rot;
const static aiVector3D base_axis_y(0.0,1.0,0.0);
const static aiVector3D base_axis_x(1.0,0.0,0.0);
const static aiVector3D base_axis_z(0.0,0.0,1.0);
- const static ai_real angle_epsilon = 0.95;
+ const static ai_real angle_epsilon = ai_real( 0.95 );
}
// ------------------------------------------------------------------------------------------------
// much easier, but I don't know how and am currently too tired to
// to think about a better solution.
- const static ai_real LOWER_LIMIT = 0.1;
- const static ai_real UPPER_LIMIT = 0.9;
+ const static ai_real LOWER_LIMIT = ai_real( 0.1 );
+ const static ai_real UPPER_LIMIT = ai_real( 0.9 );
- const static ai_real LOWER_EPSILON = 10e-3;
- const static ai_real UPPER_EPSILON = 1.0-10e-3;
+ const static ai_real LOWER_EPSILON = ai_real( 10e-3 );
+ const static ai_real UPPER_EPSILON = ai_real( 1.0-10e-3 );
for (unsigned int fidx = 0; fidx < mesh->mNumFaces;++fidx)
{
// check whether we can reuse the SpatialSort of a previous step.
SpatialSort* vertexFinder = NULL;
SpatialSort _vertexFinder;
- ai_real posEpsilon = 1e-5;
+ ai_real posEpsilon = ai_real( 1e-5 );
if (shared) {
std::vector<std::pair<SpatialSort,ai_real> >* avf;
shared->GetProperty(AI_SPP_SPATIAL_SORT,avf);
{
aiVectorKey& key = anim->mPositionKeys[i];
- const ai_real dt = (i * in.speed * 0.001 );
+ const ai_real dt = (i * in.speed * ai_real( 0.001 ) );
const ai_real u = dt - std::floor(dt);
const int idx = (int)std::floor(dt) % size;
const ai_real u2 = u*u;
const ai_real u3 = u2*2;
- const ai_real h1 = 2.0 * u3 - 3.0 * u2 + 1.0;
- const ai_real h2 = -2.0 * u3 + 3.0 * u3;
- const ai_real h3 = u3 - 2.0 * u3;
+ const ai_real h1 = ai_real( 2.0 ) * u3 - ai_real( 3.0 ) * u2 + ai_real( 1.0 );
+ const ai_real h2 = ai_real( -2.0 ) * u3 + ai_real( 3.0 ) * u3;
+ const ai_real h3 = u3 - ai_real( 2.0 ) * u3;
const ai_real h4 = u3 - u2;
// compute the spline tangents
explicit Animator(AT t = UNKNOWN)
: type (t)
- , speed (0.001)
- , direction (0.0,1.0,0.0)
- , circleRadius (1.0)
- , tightness (0.5f)
+ , speed ( ai_real( 0.001 ) )
+ , direction ( ai_real( 0.0 ), ai_real( 1.0 ), ai_real( 0.0 ) )
+ , circleRadius ( ai_real( 1.0) )
+ , tightness ( ai_real( 0.5 ) )
, loop (true)
, timeForWay (100)
{
{
float fGloss;
if (mIsLWO2) {
- fGloss = std::pow( surf.mGlossiness*10.0+2.0, 2.0);
+ fGloss = std::pow( surf.mGlossiness*ai_real( 10.0 )+ ai_real( 2.0 ), ai_real( 2.0 ) );
}
else
{
// emissive color
// luminosity is not really the same but it affects the surface in a similar way. Some scaling looks good.
- clr.g = clr.b = clr.r = surf.mLuminosity*0.8;
+ clr.g = clr.b = clr.r = surf.mLuminosity*ai_real( 0.8 );
pcMat->AddProperty<aiColor3D>(&clr,1,AI_MATKEY_COLOR_EMISSIVE);
// opacity ... either additive or default-blended, please
{
ai_real lat = (ai_real)(( p_iNormal >> 8u ) & 0xff);
ai_real lng = (ai_real)(( p_iNormal & 0xff ));
- lat *= 3.141926/128.0;
- lng *= 3.141926/128.0;
+ const ai_real invVal( ai_real( 1.0 ) / ai_real( 128.0 ) );
+ lat *= ai_real( 3.141926 ) * invVal;
+ lng *= ai_real( 3.141926 ) * invVal;
- p_afOut[0] = std::cos(lat) * std::sin(lng);
- p_afOut[1] = std::sin(lat) * std::sin(lng);
- p_afOut[2] = std::cos(lng);
- return;
+ p_afOut[ 0 ] = std::cos(lat) * std::sin(lng);
+ p_afOut[ 1 ] = std::sin(lat) * std::sin(lng);
+ p_afOut[ 2 ] = std::cos(lng);
}
// copy texture coordinates
pcUVCur->x = pcUVs[quak].u;
- pcUVCur->y = 1.0-pcUVs[quak].v; // DX to OGL
+ pcUVCur->y = ai_real( 1.0 )-pcUVs[quak].v; // DX to OGL
}
pcVertCur->x += pcFrame->localOrigin[0] ;
pcVertCur->y += pcFrame->localOrigin[1] ;
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
aiMaterial* pcMat = new aiMaterial();
- aiColor4D clr(0.6,0.6,0.6,1.0);
+ aiColor4D clr( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 1.0 ) );
pcMat->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE);
pScene->mMaterials[0] = pcMat;
//! Constructor
Material()
- : diffuse (0.6,0.6,0.6)
- , alpha (1.0)
- , shineness (0.0)
+ : diffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) )
+ , alpha (ai_real( 1.0 ) )
+ , shineness ( ai_real( 0.0) )
, illumination_model (1)
- , ior (1.0)
+ , ior ( ai_real( 1.0 ) )
{
// empty
for (size_t i = 0; i < TextureTypeCount; ++i)
// Create materials that can be found and parsed via the IOSystem.
for (size_t i=0, len=mesh->NumSubMeshes(); i<len; ++i)
{
- SubMeshXml *submesh = mesh->GetSubMesh(i);
+ SubMeshXml *submesh = mesh->GetSubMesh( static_cast<uint16_t>(i));
if (submesh && !submesh->materialRef.empty())
{
aiMaterial *material = ReadMaterial(pFile, pIOHandler, submesh->materialRef);
// find the dominant axis
aiVector3D d = max-min;
- const ai_real div = std::max(d.x,std::max(d.y,d.z))*0.5;
+ const ai_real div = std::max(d.x,std::max(d.y,d.z))*ai_real( 0.5);
d = min + d * (ai_real)0.5;
for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) {
void FindAABBTransformed (const aiMesh* mesh, aiVector3D& min, aiVector3D& max,
const aiMatrix4x4& m)
{
- min = aiVector3D (10e10, 10e10, 10e10);
- max = aiVector3D (-10e10,-10e10,-10e10);
+ min = aiVector3D ( ai_real( 10e10 ), ai_real( 10e10 ), ai_real( 10e10 ) );
+ max = aiVector3D ( ai_real( -10e10 ), ai_real( -10e10 ), ai_real( -10e10 ) );
for (unsigned int i = 0;i < mesh->mNumVertices;++i)
{
const aiVector3D v = m * mesh->mVertices[i];
// -------------------------------------------------------------------------------
ai_real ComputePositionEpsilon(const aiMesh* pMesh)
{
- const ai_real epsilon = 1e-4;
+ const ai_real epsilon = ai_real( 1e-4 );
// calculate the position bounds so we have a reliable epsilon to check position differences against
aiVector3D minVec, maxVec;
{
ai_assert( NULL != pMeshes );
- const ai_real epsilon = 1e-4;
+ const ai_real epsilon = ai_real( 1e-4 );
// calculate the position bounds so we have a reliable epsilon to check position differences against
aiVector3D minVec, maxVec, mi, ma;
// 99% and 1% percentiles.
// OpenGL: I = cos(angle)^E
// Solving: angle = acos(I^(1/E))
- ai_real E = 1.0 / std::max(spotExponent, (ai_real)0.00001);
+ ai_real E = ai_real( 1.0 ) / std::max(spotExponent, (ai_real)0.00001);
ai_real inner = std::acos(std::pow((ai_real)0.99, E));
ai_real outer = std::acos(std::pow((ai_real)0.01, E));
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
-void STLImporter::InternReadFile( const std::string& pFile,
- aiScene* pScene, IOSystem* pIOHandler)
+void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler )
{
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
this->mBuffer = &mBuffer2[0];
// the default vertex color is light gray.
- clrColorDefault.r = clrColorDefault.g = clrColorDefault.b = clrColorDefault.a = 0.6;
+ clrColorDefault.r = clrColorDefault.g = clrColorDefault.b = clrColorDefault.a = (ai_real) 0.6;
// allocate a single node
pScene->mRootNode = new aiNode();
s.Set(AI_DEFAULT_MATERIAL_NAME);
pcMat->AddProperty(&s, AI_MATKEY_NAME);
- aiColor4D clrDiffuse(0.6,0.6,0.6,1.0);
+ aiColor4D clrDiffuse(ai_real(0.6),ai_real(0.6),ai_real(0.6),ai_real(1.0));
if (bMatClr) {
clrDiffuse = clrColorDefault;
}
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_DIFFUSE);
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_SPECULAR);
- clrDiffuse = aiColor4D(0.05,0.05,0.05,1.0);
+ clrDiffuse = aiColor4D( ai_real( 0.05), ai_real( 0.05), ai_real( 0.05), ai_real( 1.0));
pcMat->AddProperty(&clrDiffuse,1,AI_MATKEY_COLOR_AMBIENT);
pScene->mNumMaterials = 1;
// read the default vertex color for facets
bIsMaterialise = true;
DefaultLogger::get()->info("STL: Taking code path for Materialise files");
- clrColorDefault.r = (*sz2++) / 255.0;
- clrColorDefault.g = (*sz2++) / 255.0;
- clrColorDefault.b = (*sz2++) / 255.0;
- clrColorDefault.a = (*sz2++) / 255.0;
+ const ai_real invByte = (ai_real)1.0 / ( ai_real )255.0;
+ clrColorDefault.r = (*sz2++) * invByte;
+ clrColorDefault.g = (*sz2++) * invByte;
+ clrColorDefault.b = (*sz2++) * invByte;
+ clrColorDefault.a = (*sz2++) * invByte;
break;
}
}
}
aiColor4D* clr = &pMesh->mColors[0][i*3];
clr->a = 1.0;
+ const ai_real invVal( (ai_real)1.0 / ( ai_real )31.0 );
if (bIsMaterialise) // this is reversed
{
- clr->r = (color & 0x31u) / 31.0;
- clr->g = ((color & (0x31u<<5))>>5u) / 31.0;
- clr->b = ((color & (0x31u<<10))>>10u) / 31.0;
+ clr->r = (color & 0x31u) *invVal;
+ clr->g = ((color & (0x31u<<5))>>5u) *invVal;
+ clr->b = ((color & (0x31u<<10))>>10u) *invVal;
}
else
{
- clr->b = (color & 0x31u) / 31.0;
- clr->g = ((color & (0x31u<<5))>>5u) / 31.0;
- clr->r = ((color & (0x31u<<10))>>10u) / 31.0;
+ clr->b = (color & 0x31u) *invVal;
+ clr->g = ((color & (0x31u<<5))>>5u) *invVal;
+ clr->r = ((color & (0x31u<<10))>>10u) *invVal;
}
// assign the color to all vertices of the face
*(clr+1) = *clr;
{
// if the node has no children, it's an end node. Put a little knob there instead
aiVector3D ownpos( pNode->mTransformation.a4, pNode->mTransformation.b4, pNode->mTransformation.c4);
- ai_real sizeEstimate = ownpos.Length() * 0.18;
+ ai_real sizeEstimate = ownpos.Length() * ai_real( 0.18 );
mVertices.push_back( aiVector3D( -sizeEstimate, 0.0, 0.0));
mVertices.push_back( aiVector3D( 0.0, sizeEstimate, 0.0));
{
positions.reserve(positions.size()+60);
- const ai_real t = (1.0 + 2.236067977)/2.0;
- const ai_real s = std::sqrt(1.0 + t*t);
+ const ai_real t = ( ai_real( 1.0 )+ ai_real( 2.236067977 ) ) / ai_real( 2.0 );
+ const ai_real s = std::sqrt(ai_real(1.0) + t*t);
const aiVector3D v0 = aiVector3D(t,1.0, 0.0)/s;
const aiVector3D v1 = aiVector3D(-t,1.0, 0.0)/s;
{
positions.reserve(positions.size()+108);
- const ai_real a = 1.0 / 1.7320508;
- const ai_real b = std::sqrt((3.0-2.23606797f)/6.0);
- const ai_real c = std::sqrt((3.0+2.23606797f)/6.0);
+ const ai_real a = ai_real( 1.0 ) / ai_real(1.7320508);
+ const ai_real b = std::sqrt(( ai_real( 3.0 )- ai_real( 2.23606797))/ ai_real( 6.0) );
+ const ai_real c = std::sqrt(( ai_real( 3.0 )+ ai_real( 2.23606797f))/ ai_real( 6.0) );
const aiVector3D v0 = aiVector3D(a,a,a);
const aiVector3D v1 = aiVector3D(a,a,-a);
{
positions.reserve(positions.size()+9);
- const ai_real a = 1.41421/3.0;
- const ai_real b = 2.4494/3.0;
+ const ai_real invThree = ai_real( 1.0 ) / ai_real( 3.0 );
+ const ai_real a = ai_real( 1.41421 ) * invThree;
+ const ai_real b = ai_real( 2.4494 ) * invThree;
const aiVector3D v0 = aiVector3D(0.0,0.0,1.0);
- const aiVector3D v1 = aiVector3D(2*a,0,-1.0/3.0);
- const aiVector3D v2 = aiVector3D(-a,b,-1.0/3.0);
- const aiVector3D v3 = aiVector3D(-a,-b,-1.0/3.0);
+ const aiVector3D v1 = aiVector3D(2*a,0,-invThree );
+ const aiVector3D v2 = aiVector3D(-a,b,-invThree );
+ const aiVector3D v3 = aiVector3D(-a,-b,-invThree );
ADD_TRIANGLE(v0,v1,v2);
ADD_TRIANGLE(v0,v2,v3);
bool polygons /*= false*/)
{
positions.reserve(positions.size()+36);
- const ai_real length = 1.0/1.73205080;
+ const ai_real length = ai_real(1.0)/ai_real(1.73205080);
const aiVector3D v0 = aiVector3D(-1.0,-1.0,-1.0)*length;
const aiVector3D v1 = aiVector3D(1.0,-1.0,-1.0)*length;
radius1 = std::fabs(radius1);
radius2 = std::fabs(radius2);
- ai_real halfHeight = height / 2.0;
+ ai_real halfHeight = height / ai_real(2.0);
// radius1 is always the smaller one
if (radius2 > radius1)
if (quantMode == O3DGC_SC3DMC_DIAG_BB)
{
- Real diag = 0.0;
+ Real diag = Real( 0.0 );
Real r;
for(unsigned long d = 0; d < dim; ++d)
{