Пример #1
0
// ------------------------------------------------------------------------------------------------
// Convert a 3DS texture to texture keys in an aiMaterial
void CopyTexture(aiMaterial& mat, D3DS::Texture& texture, aiTextureType type)
{
    // Setup the texture name
    aiString tex;
    tex.Set( texture.mMapName);
    mat.AddProperty( &tex, AI_MATKEY_TEXTURE(type,0));

    // Setup the texture blend factor
    if (is_not_qnan(texture.mTextureBlend))
        mat.AddProperty<float>( &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));
    mat.AddProperty<int>((int*)&texture.mMapMode,1,AI_MATKEY_MAPPINGMODE_V(type,0));

    // Mirroring - double the scaling values
    // 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;
    }

    // Setup texture UV transformations
    mat.AddProperty<float>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
}
Пример #2
0
// ------------------------------------------------------------------------------------------------
// Convert a material from AC3DImporter::Material to aiMaterial
void AC3DImporter::ConvertMaterial(const Object& object,
    const Material& matSrc,
    aiMaterial& matDest)
{
    aiString s;

    if (matSrc.name.length())
    {
        s.Set(matSrc.name);
        matDest.AddProperty(&s,AI_MATKEY_NAME);
    }
    if (object.texture.length())
    {
        s.Set(object.texture);
        matDest.AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));

        // UV transformation
        if (1.f != object.texRepeat.x || 1.f != object.texRepeat.y ||
            object.texOffset.x        || object.texOffset.y)
        {
            aiUVTransform transform;
            transform.mScaling = object.texRepeat;
            transform.mTranslation = object.texOffset;
            matDest.AddProperty(&transform,1,AI_MATKEY_UVTRANSFORM_DIFFUSE(0));
        }
    }

    matDest.AddProperty<aiColor3D>(&matSrc.rgb,1, AI_MATKEY_COLOR_DIFFUSE);
    matDest.AddProperty<aiColor3D>(&matSrc.amb,1, AI_MATKEY_COLOR_AMBIENT);
    matDest.AddProperty<aiColor3D>(&matSrc.emis,1,AI_MATKEY_COLOR_EMISSIVE);
    matDest.AddProperty<aiColor3D>(&matSrc.spec,1,AI_MATKEY_COLOR_SPECULAR);

    int n;
    if (matSrc.shin)
    {
        n = aiShadingMode_Phong;
        matDest.AddProperty<float>(&matSrc.shin,1,AI_MATKEY_SHININESS);
    }
    else n = aiShadingMode_Gouraud;
    matDest.AddProperty<int>(&n,1,AI_MATKEY_SHADING_MODEL);

    float f = 1.f - matSrc.trans;
    matDest.AddProperty<float>(&f,1,AI_MATKEY_OPACITY);
}
// ------------------------------------------------------------------------------------------------
// Copy a texture from the ASE structs to the output material
void CopyASETexture(aiMaterial& mat, ASE::Texture& texture, aiTextureType type)
{
	// Setup the texture name
	aiString tex;
	tex.Set( texture.mMapName);
	mat.AddProperty( &tex, AI_MATKEY_TEXTURE(type,0));

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

	// Setup texture UV transformations
	mat.AddProperty<float>(&texture.mOffsetU,5,AI_MATKEY_UVTRANSFORM(type,0));
}
Пример #4
0
// ------------------------------------------------------------------------------------------------
// Convert a 3DS material to an aiMaterial
void Discreet3DSImporter::ConvertMaterial(D3DS::Material& oldMat,
    aiMaterial& mat)
{
    // NOTE: Pass the background image to the viewer by bypassing the
    // material system. This is an evil hack, never do it again!
    if (0 != mBackgroundImage.length() && bHasBG)
    {
        aiString tex;
        tex.Set( mBackgroundImage);
        mat.AddProperty( &tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE);

        // Be sure this is only done for the first material
        mBackgroundImage = std::string("");
    }

    // At first add the base ambient color of the scene to the material
    oldMat.mAmbient.r += mClrAmbient.r;
    oldMat.mAmbient.g += mClrAmbient.g;
    oldMat.mAmbient.b += mClrAmbient.b;

    aiString name;
    name.Set( oldMat.mName);
    mat.AddProperty( &name, AI_MATKEY_NAME);

    // Material colors
    mat.AddProperty( &oldMat.mAmbient, 1, AI_MATKEY_COLOR_AMBIENT);
    mat.AddProperty( &oldMat.mDiffuse, 1, AI_MATKEY_COLOR_DIFFUSE);
    mat.AddProperty( &oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR);
    mat.AddProperty( &oldMat.mEmissive, 1, AI_MATKEY_COLOR_EMISSIVE);

    // Phong shininess and shininess strength
    if (D3DS::Discreet3DS::Phong == oldMat.mShading ||
        D3DS::Discreet3DS::Metal == oldMat.mShading)
    {
        if (!oldMat.mSpecularExponent || !oldMat.mShininessStrength)
        {
            oldMat.mShading = D3DS::Discreet3DS::Gouraud;
        }
        else
        {
            mat.AddProperty( &oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
            mat.AddProperty( &oldMat.mShininessStrength, 1, AI_MATKEY_SHININESS_STRENGTH);
        }
    }

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

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

    // Two sided rendering?
    if (oldMat.mTwoSided)
    {
        int i = 1;
        mat.AddProperty<int>(&i,1,AI_MATKEY_TWOSIDED);
    }

    // Shading mode
    aiShadingMode eShading = aiShadingMode_NoShading;
    switch (oldMat.mShading)
    {
        case D3DS::Discreet3DS::Flat:
            eShading = aiShadingMode_Flat; break;

        // I don't know what "Wire" shading should be,
        // assume it is simple lambertian diffuse shading
        case D3DS::Discreet3DS::Wire:
            {
                // Set the wireframe flag
                unsigned int iWire = 1;
                mat.AddProperty<int>( (int*)&iWire,1,AI_MATKEY_ENABLE_WIREFRAME);
            }

        case D3DS::Discreet3DS::Gouraud:
            eShading = aiShadingMode_Gouraud; break;

        // assume cook-torrance shading for metals.
        case D3DS::Discreet3DS::Phong :
            eShading = aiShadingMode_Phong; break;

        case D3DS::Discreet3DS::Metal :
            eShading = aiShadingMode_CookTorrance; break;

            // FIX to workaround a warning with GCC 4 who complained
            // about a missing case Blinn: here - Blinn isn't a valid
            // value in the 3DS Loader, it is just needed for ASE
        case D3DS::Discreet3DS::Blinn :
            eShading = aiShadingMode_Blinn; break;
    }
    mat.AddProperty<int>( (int*)&eShading,1,AI_MATKEY_SHADING_MODEL);

    // DIFFUSE texture
    if( oldMat.sTexDiffuse.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexDiffuse, aiTextureType_DIFFUSE);

    // SPECULAR texture
    if( oldMat.sTexSpecular.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexSpecular, aiTextureType_SPECULAR);

    // OPACITY texture
    if( oldMat.sTexOpacity.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexOpacity, aiTextureType_OPACITY);

    // EMISSIVE texture
    if( oldMat.sTexEmissive.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexEmissive, aiTextureType_EMISSIVE);

    // BUMP texture
    if( oldMat.sTexBump.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexBump, aiTextureType_HEIGHT);

    // SHININESS texture
    if( oldMat.sTexShininess.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexShininess, aiTextureType_SHININESS);

    // REFLECTION texture
    if( oldMat.sTexReflective.mMapName.length() > 0)
        CopyTexture(mat,oldMat.sTexReflective, aiTextureType_REFLECTION);

    // Store the name of the material itself, too
    if( oldMat.mName.length())  {
        aiString tex;
        tex.Set( oldMat.mName);
        mat.AddProperty( &tex, AI_MATKEY_NAME);
    }
}