BaseMatInstance* DecalData::getMaterialInstance() { if ( !material || !matInst || matInst->getMaterial() != material ) _initMaterial(); return matInst; }
BaseMatInstance* SkyBox::_getMaterialInstance() { if ( !mMaterial || !mMatInstance || mMatInstance->getMaterial() != mMaterial ) _initMaterial(); if ( !mMatInstance ) return NULL; return mMatInstance; }
void SkyBox::_updateMaterial() { if ( mMatName.isEmpty() ) return; Material *pMat = NULL; if ( !Sim::findObject( mMatName, pMat ) ) Con::printf( "SkyBox::_updateMaterial, failed to find Material of name %s!", mMatName.c_str() ); else if ( isProperlyAdded() ) { mMaterial = pMat; _initMaterial(); } }
void PxCloth::prepRenderImage( SceneRenderState *state ) { if ( mIsVBDirty ) _updateVBIB(); // Recreate the material if we need to. if ( !mMatInst ) _initMaterial(); // If we don't have a material instance after the override then // we can skip rendering all together. BaseMatInstance *matInst = state->getOverrideMaterial( mMatInst ); if ( !matInst ) return; MeshRenderInst *ri = state->getRenderPass()->allocInst<MeshRenderInst>(); // If we need lights then set them up. if ( matInst->isForwardLit() ) { LightQuery query; query.init( getWorldSphere() ); query.getLights( ri->lights, 8 ); } ri->projection = state->getRenderPass()->allocSharedXform(RenderPassManager::Projection); ri->objectToWorld = &MatrixF::Identity; ri->worldToCamera = state->getRenderPass()->allocSharedXform(RenderPassManager::View); ri->type = RenderPassManager::RIT_Mesh; ri->primBuff = &mPrimBuffer; ri->vertBuff = &mVB; ri->matInst = matInst; ri->prim = state->getRenderPass()->allocPrim(); ri->prim->type = GFXTriangleList; ri->prim->minIndex = 0; ri->prim->startIndex = 0; ri->prim->numPrimitives = mNumIndices / 3; ri->prim->startVertex = 0; ri->prim->numVertices = mNumVertices; ri->defaultKey = matInst->getStateHint(); ri->defaultKey2 = (U32)ri->vertBuff; state->getRenderPass()->addInst( ri ); }
void DecalData::_updateMaterial() { if ( materialName.isEmpty() ) return; Material *pMat = NULL; if ( !Sim::findObject( materialName, pMat ) ) { Con::printf( "DecalData::unpackUpdate, failed to find Material of name %s!", materialName.c_str() ); return; } material = pMat; // Only update material instance if we have one allocated. if ( matInst ) _initMaterial(); }
bool DecalRoad::onAdd() { if ( !Parent::onAdd() ) return false; // DecalRoad is at position zero when created, // it sets its own position to the first node inside // _generateEdges but until it has at least one node // it will be at 0,0,0. MatrixF mat(true); Parent::setTransform( mat ); // The client side calculates bounds based on clipped geometry. It would // be wasteful for the server to do this so the server uses global bounds. if ( isServerObject() ) { setGlobalBounds(); resetWorldBox(); } // Set the Render Transform. setRenderTransform(mObjToWorld); // Add to Scene. addToScene(); if ( isServerObject() ) getServerSet()->addObject( this ); // TerrainBlock::smUpdateSignal.notify( this, &DecalRoad::_onTerrainChanged ); // if ( isClientObject() ) _initMaterial(); _generateEdges(); _captureVerts(); return true; }
void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream ) { // Unpack Parent. Parent::unpackUpdate( con, stream ); // DecalRoadMask if ( stream->readFlag() ) { String matName; stream->read( &matName ); if ( matName != mMaterialName ) { mMaterialName = matName; Material *pMat = NULL; if ( !Sim::findObject( mMaterialName, pMat ) ) { Con::printf( "DecalRoad::unpackUpdate, failed to find Material of name %s!", mMaterialName.c_str() ); } else { mMaterial = pMat; if ( isProperlyAdded() ) _initMaterial(); } } stream->read( &mBreakAngle ); stream->read( &mSegmentsPerBatch ); stream->read( &mTextureLength ); stream->read( &mRenderPriority ); } // NodeMask if ( stream->readFlag() ) { //U32 count = stream->readInt( 16 ); //mNodes.clear(); //Point3F pos; //F32 width; //for ( U32 i = 0; i < count; i++ ) //{ // mathRead( *stream, &pos ); // stream->read( &width ); // _addNode( pos, width ); //} if (stream->readFlag()) { // Nodes have been passed in this update U32 count = stream->readInt( 16 ); mNodes.clear(); Point3F pos; F32 width; for ( U32 i = 0; i < count; i++ ) { mathRead( *stream, &pos ); stream->read( &width ); _addNode( pos, width ); } } else { // Nodes will arrive as events U32 id; stream->read( &id ); // Check if the road's nodes made it here before we did. NodeListManager::NodeList* list = NULL; if ( gClientNodeListManager->findListById( id, &list, true) ) { // Work with the completed list DecalRoadNodeList* roadList = dynamic_cast<DecalRoadNodeList*>( list ); if (roadList) buildNodesFromList( roadList ); delete list; } else { // Nodes have not yet arrived, so register our interest in the list DecalRoadNodeListNotify* notify = new DecalRoadNodeListNotify( this, id ); gClientNodeListManager->registerNotification( notify ); } } } // GenEdgesMask if ( stream->readFlag() && isProperlyAdded() ) _generateEdges(); // ReClipMask if ( stream->readFlag() && isProperlyAdded() ) _captureVerts(); // TerrainChangedMask if ( stream->readFlag() ) { if ( isProperlyAdded() ) { if ( mTerrainUpdateRect.isOverlapped( getWorldBox() ) ) { _generateEdges(); _captureVerts(); // Clear out the mTerrainUpdateRect since we have updated its // region and we now need to store future terrain changes // in it. mTerrainUpdateRect = Box3F::Invalid; } } } }
void DecalRoad::unpackUpdate( NetConnection *con, BitStream *stream ) { // Unpack Parent. Parent::unpackUpdate( con, stream ); // NodeMask if ( stream->readFlag() ) { U32 count = stream->readInt( 16 ); mNodes.clear(); Point3F pos; F32 width; for ( U32 i = 0; i < count; i++ ) { mathRead( *stream, &pos ); stream->read( &width ); _addNode( pos, width ); } } // DecalRoadMask if ( stream->readFlag() ) { String matName; stream->read( &matName ); if ( matName != mMaterialName ) { mMaterialName = matName; Material *pMat = NULL; if ( !Sim::findObject( mMaterialName, pMat ) ) { Con::printf( "DecalRoad::unpackUpdate, failed to find Material of name %s!", mMaterialName.c_str() ); } else { mMaterial = pMat; if ( isProperlyAdded() ) _initMaterial(); } } stream->read( &mBreakAngle ); stream->read( &mSegmentsPerBatch ); stream->read( &mTextureLength ); stream->read( &mRenderPriority ); } // GenEdgesMask if ( stream->readFlag() && isProperlyAdded() ) _generateEdges(); // ReClipMask if ( stream->readFlag() && isProperlyAdded() ) _captureVerts(); // TerrainChangedMask if ( stream->readFlag() ) { if ( isProperlyAdded() ) { if ( mTerrainUpdateRect.isOverlapped( getWorldBox() ) ) { _generateEdges(); _captureVerts(); // Clear out the mTerrainUpdateRect since we have updated its // region and we now need to store future terrain changes // in it. mTerrainUpdateRect = Box3F::Invalid; } } } }