示例#1
0
    static MaterialChunkRecPtr getMatChunk(Material* matPtr) {
        if (matPtr == 0) return 0;

        MaterialChunkRecPtr mchunk = 0;
        MaterialRecPtr mat = MaterialRecPtr(matPtr);

        SimpleMaterialRecPtr smat = dynamic_pointer_cast<SimpleMaterial>(mat);
        SimpleTexturedMaterialRecPtr stmat = dynamic_pointer_cast<SimpleTexturedMaterial>(mat);
        ChunkMaterialRecPtr cmat = dynamic_pointer_cast<ChunkMaterial>(mat);

        if (smat || stmat)  {
            MAC* macc = (MAC*)matPtr;
            MaterialChunkRecPtr mchunk = macc->_materialChunk;
            if (mchunk) return mchunk;
        }

        if (cmat) {
            for (uint i=0; i<cmat->getMFChunks()->size(); i++) {
                StateChunkRecPtr chunk = cmat->getChunk(i);
                mchunk = dynamic_pointer_cast<MaterialChunk>(chunk);
                if (mchunk) return mchunk;
            }
        }

        return mchunk;
    }
示例#2
0
 static BlendChunkRecPtr getBlendChunk(Material* matPtr) {
     MaterialRecPtr mat = MaterialRecPtr(matPtr);
     ChunkMaterialRecPtr cmat = dynamic_pointer_cast<ChunkMaterial>(mat);
     BlendChunkRecPtr bchunk = 0;
     if (cmat) {
         for (uint i=0; i<cmat->getMFChunks()->size(); i++) {
             StateChunkRecPtr chunk = cmat->getChunk(i);
             bchunk = dynamic_pointer_cast<BlendChunk>(chunk);
             if (bchunk) return bchunk;
         }
     }
     return bchunk;
 }
示例#3
0
void VRMaterial::setMaterial(MaterialRecPtr m) {
    if ( dynamic_pointer_cast<MultiPassMaterial>(m) ) {
        MultiPassMaterialRecPtr mm = dynamic_pointer_cast<MultiPassMaterial>(m);
        for (unsigned int i=0; i<mm->getNPasses(); i++) {
            if (i > 0) addPass();
            setMaterial(mm->getMaterials(i));
        }
        setActivePass(0);
        return;
    }

    if ( isSMat(m) ) {
        SimpleMaterialRecPtr sm = dynamic_pointer_cast<SimpleMaterial>(m);
        setDiffuse(sm->getDiffuse());
        setAmbient(sm->getAmbient());
        setSpecular(sm->getSpecular());

        if ( isSTMat(m) ) {
            SimpleTexturedMaterialRecPtr stm = dynamic_pointer_cast<SimpleTexturedMaterial>(m);
            setTexture( VRTexture::create(stm->getImage()), true);
        }

        return;
    }
    if ( isCMat(m) ) {
        MaterialChunkRecPtr mc = 0;
        BlendChunkRecPtr bc = 0;
        TextureEnvChunkRecPtr ec = 0;
        TextureObjChunkRecPtr tc = 0;

        ChunkMaterialRecPtr cmat = dynamic_pointer_cast<ChunkMaterial>(m);
        for (uint i=0; i<cmat->getMFChunks()->size(); i++) {
            StateChunkRecPtr chunk = cmat->getChunk(i);
            if (mc == 0) mc = dynamic_pointer_cast<MaterialChunk>(chunk);
            if (bc == 0) bc = dynamic_pointer_cast<BlendChunk>(chunk);
            if (ec == 0) ec = dynamic_pointer_cast<TextureEnvChunk>(chunk);
            if (tc == 0) tc = dynamic_pointer_cast<TextureObjChunk>(chunk);
        }

        auto md = mats[activePass];
        if (mc) mc->setBackMaterial(false);
        if (mc) {
            if (md->colChunk) md->mat->subChunk(md->colChunk);
            md->colChunk = mc;
            md->mat->addChunk(mc);
        }
        if (bc) {
            if (md->blendChunk) md->mat->subChunk(md->blendChunk);
            md->blendChunk = bc;
            md->mat->addChunk(bc);
        }
        if (ec) {
            if (md->envChunk) md->mat->subChunk(md->envChunk);
            md->envChunk = ec;
            md->mat->addChunk(ec);
        }
        if (tc) {
            if (md->texChunk) md->mat->subChunk(md->texChunk);
            md->texChunk = tc;
            md->mat->addChunk(tc);
        }
        return;
    }

    cout << "Warning: unhandled material type\n";
    if (dynamic_pointer_cast<Material>(m)) cout << " Material" << endl;
    if (dynamic_pointer_cast<PrimeMaterial>(m)) cout << "  PrimeMaterial" << endl;
    if (dynamic_pointer_cast<SimpleMaterial>(m)) cout << "   SimpleMaterial" << endl;
    if (dynamic_pointer_cast<SimpleTexturedMaterial>(m)) cout << "   SimpleTexturedMaterial" << endl;
    if (dynamic_pointer_cast<VariantMaterial>(m)) cout << "   VariantMaterial" << endl;
    if (dynamic_pointer_cast<ChunkMaterial>(m)) cout << "  ChunkMaterial" << endl;
    if (dynamic_pointer_cast<MultiPassMaterial>(m)) cout << "   MultiPassMaterial" << endl;
    if (dynamic_pointer_cast<CompositeMaterial>(m)) cout << "   CompositeMaterial" << endl;
    if (dynamic_pointer_cast<SwitchMaterial>(m)) cout << "   SwitchMaterial" << endl;
}