void bhkProxyObject::CreateMesh() { if (Interface *gi = this->mIP) { if (const Mesh* pMesh = &this->proxyMesh) { if (TriObject *triObject = CreateNewTriObject()) { MNMesh mnmesh(*pMesh); Mesh& mesh = triObject->GetMesh(); mnmesh.OutToTri(mesh); INode *node = gi->CreateObjectNode(triObject); // Wireframe Red color StdMat2 *collMat = NewDefaultStdMat(); collMat->SetDiffuse(Color(1.0f, 0.0f, 0.0f), 0); collMat->SetWire(TRUE); collMat->SetFaceted(TRUE); gi->GetMaterialLibrary().Add(collMat); node->SetMtl(collMat); node->SetPrimaryVisibility(FALSE); node->SetSecondaryVisibility(FALSE); node->BoneAsLine(TRUE); node->SetRenderable(FALSE); node->SetWireColor( RGB(255,0,0) ); gi->SelectNode(node); } } } }
bool CollisionImport::ImportBase(bhkRigidBodyRef body, bhkShapeRef shape, INode* parent, INode *shapeNode, Matrix3& tm) { // Now do common post processing for the node if (shapeNode != NULL) { shapeNode->SetName( TSTR(shape->GetType().GetTypeName().c_str()) ); if (!tm.IsIdentity()) { Point3 pos = tm.GetTrans(); Quat rot(tm); PosRotScaleNode(shapeNode, pos, rot, 1.0, prsDefault); } // Wireframe Red color StdMat2 *collMat = NewDefaultStdMat(); collMat->SetDiffuse(Color(1.0f, 0.0f, 0.0f), 0); collMat->SetWire(TRUE); collMat->SetFaceted(TRUE); ni.gi->GetMaterialLibrary().Add(collMat); shapeNode->SetMtl(collMat); shapeNode->SetPrimaryVisibility(FALSE); shapeNode->SetSecondaryVisibility(FALSE); shapeNode->BoneAsLine(TRUE); shapeNode->SetRenderable(FALSE); //shapeNode->XRayMtl(TRUE); shapeNode->SetWireColor( RGB(255,0,0) ); if (parent) parent->AttachChild(shapeNode); return true; } return false; }
void bhkRigidBodyModifier::CreateMesh() { if (Interface *gi = this->mIP) { if (const Mesh* pMesh = this->GetMesh()) { if (TriObject *triObject = CreateNewTriObject()) { MNMesh mnmesh(*pMesh); Mesh& mesh = triObject->GetMesh(); mnmesh.buildNormals(); mnmesh.OutToTri(mesh); INode *node = gi->CreateObjectNode(triObject); // Wireframe Red color StdMat2 *collMat = NewDefaultStdMat(); collMat->SetDiffuse(Color(1.0f, 0.0f, 0.0f), 0); collMat->SetWire(TRUE); collMat->SetFaceted(TRUE); gi->GetMaterialLibrary().Add(collMat); node->SetMtl(collMat); node->SetPrimaryVisibility(FALSE); node->SetSecondaryVisibility(FALSE); node->BoneAsLine(TRUE); node->SetRenderable(FALSE); node->SetWireColor( RGB(255,0,0) ); if (gi->GetSelNodeCount() == 1) { if (INode *snode = gi->GetSelNode(0)) { Matrix3 tm = snode->GetObjTMAfterWSM(0, NULL); node->SetNodeTM(0, tm); } } gi->SelectNode(node); } } } }
StdMat2 *NifImporter::ImportMaterialAndTextures(ImpNode *node, NiAVObjectRef avObject) { // Texture NiMaterialPropertyRef matRef = avObject->GetPropertyByType(NiMaterialProperty::TYPE); if (matRef != NULL){ StdMat2 *m = NewDefaultStdMat(); m->SetName(matRef->GetName().c_str()); if (showTextures) { m->SetMtlFlag(MTL_DISPLAY_ENABLE_FLAGS, TRUE); } // try the civ4 shader first then default back to normal shaders if (ImportNiftoolsShader(node, avObject, m)) { return m; } NiTexturingPropertyRef texRef = avObject->GetPropertyByType(NiTexturingProperty::TYPE); NiWireframePropertyRef wireRef = avObject->GetPropertyByType(NiWireframeProperty::TYPE); NiAlphaPropertyRef alphaRef = avObject->GetPropertyByType(NiAlphaProperty::TYPE); NiStencilPropertyRef stencilRef = avObject->GetPropertyByType(NiStencilProperty::TYPE); NiShadePropertyRef shadeRef = avObject->GetPropertyByType(NiShadeProperty::TYPE); vector<NiPropertyRef> props = avObject->GetProperties(); if (IsFallout3()) { m->SetAmbient(Color(0.588f, 0.588f, 0.588f),0); m->SetDiffuse(Color(0.588f, 0.588f, 0.588f),0); m->SetSpecular(Color(0.902f, 0.902f, 0.902f),0); } else { m->SetAmbient(TOCOLOR(matRef->GetAmbientColor()),0); m->SetDiffuse(TOCOLOR(matRef->GetDiffuseColor()),0); m->SetSpecular(TOCOLOR(matRef->GetSpecularColor()),0); } Color c = TOCOLOR(matRef->GetEmissiveColor()); if (c.r != 0 || c.b != 0 || c.g != 0) { m->SetSelfIllumColorOn(TRUE); m->SetSelfIllumColor(c,0); } m->SetShinStr(0.0,0); m->SetShininess(matRef->GetGlossiness()/100.0,0); m->SetOpacity(matRef->GetTransparency(),0); bool hasShaderAttributes = (wireRef != NULL) || (stencilRef != NULL) || (shadeRef != NULL); if (m->SupportsShaders() && hasShaderAttributes) { if (Shader *s = m->GetShader()) { if (wireRef != NULL && (wireRef->GetFlags() & 1)) { BOOL value = TRUE; m->SetWire(value); } if (stencilRef != NULL) { if (stencilRef->GetFaceDrawMode() == DRAW_BOTH) { BOOL value = TRUE; m->SetTwoSided(value); } } if (shadeRef != NULL && shadeRef->GetFlags() & 1) { m->SetFaceted(TRUE); } } } if (NULL != texRef) { // Handle Base/Detail ??? if (texRef->HasTexture(DECAL_0_MAP)){ if (Texmap* tex = CreateTexture(texRef->GetTexture(DECAL_0_MAP))) m->SetSubTexmap(ID_DI, tex); if (texRef->HasTexture(BASE_MAP)){ m->LockAmbDiffTex(FALSE); if (Texmap* tex = CreateTexture(texRef->GetTexture(BASE_MAP))) m->SetSubTexmap(ID_AM, tex); } } else if (texRef->HasTexture(BASE_MAP)) { if (Texmap* tex = CreateTexture(texRef->GetTexture(BASE_MAP))) { m->SetSubTexmap(ID_DI, tex); if (showTextures) gi->ActivateTexture(tex,m); } } // Handle Bump map if (texRef->HasTexture(BUMP_MAP)) { if (Texmap* tex = CreateTexture(texRef->GetTexture(BUMP_MAP))) m->SetSubTexmap(ID_BU, CreateNormalBump(NULL, tex)); } // Shiny map if (texRef->HasTexture(GLOSS_MAP)) { if (Texmap* tex = CreateTexture(texRef->GetTexture(GLOSS_MAP))) m->SetSubTexmap(ID_SS, tex); } // Self illumination if (texRef->HasTexture(GLOW_MAP)) { if (Texmap* tex = CreateTexture(texRef->GetTexture(GLOW_MAP))) m->SetSubTexmap(ID_SI, tex); } // Custom Shader Handling int nTex = texRef->GetShaderTextureCount(); if (nTex > 0) { list<NiExtraDataRef> data = avObject->GetExtraData(); NiGeometryRef trigeom = DynamicCast<NiGeometry>(avObject); if (trigeom->HasShader()) { for (list<NiExtraDataRef>::iterator itr = data.begin(); itr != data.end(); ++itr) { if ( NiIntegerExtraDataRef idx = DynamicCast<NiIntegerExtraData>(*itr) ) { string name = idx->GetName(); if ( wildmatch("*Index", name) ) { int shader = idx->GetData(); if (shader < nTex) { if ( name == "NormalMapIndex" ) { if (Texmap* tex = CreateTexture(texRef->GetShaderTexture(shader))) m->SetSubTexmap(ID_BU, CreateNormalBump(NULL, tex)); } else if ( name == "SpecularIntensity" ) { if (Texmap* tex = CreateTexture(texRef->GetShaderTexture(shader))) m->SetSubTexmap(ID_SP, CreateNormalBump(NULL, tex)); } } } } } } } } if (NiTexturePropertyRef tex2Ref = avObject->GetPropertyByType(NiTextureProperty::TYPE)){ // Handle Base/Detail ??? if (Texmap* tex = CreateTexture(tex2Ref)) { m->SetSubTexmap(ID_DI, tex); } } if (BSShaderNoLightingPropertyRef noLightShadeRef = SelectFirstObjectOfType<BSShaderNoLightingProperty>(props)) { if ( Texmap* tex = CreateTexture( noLightShadeRef->GetFileName() ) ) { m->SetSubTexmap(ID_DI, tex); } } if (BSShaderPPLightingPropertyRef ppLightShadeRef = SelectFirstObjectOfType<BSShaderPPLightingProperty>(props)) { if ( BSShaderTextureSetRef textures = ppLightShadeRef->GetTextureSet() ) { if ( Texmap* tex = CreateTexture( textures->GetTexture(0) ) ) m->SetSubTexmap(ID_DI, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(1) ) ) m->SetSubTexmap(ID_BU, CreateNormalBump(NULL, tex)); if ( Texmap* tex = CreateTexture( textures->GetTexture(3) ) ) m->SetSubTexmap(ID_SI, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(4) ) ) m->SetSubTexmap(ID_RL, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(5) ) ) { if ( Texmap* mask = CreateTexture( textures->GetTexture(2) ) ) tex = CreateMask(NULL, tex, mask); m->SetSubTexmap(ID_SP, tex); } } } if (SkyShaderPropertyRef skyShadeRef = SelectFirstObjectOfType<SkyShaderProperty>(props)) { if ( Texmap* tex = CreateTexture( skyShadeRef->GetFileName() ) ) { m->SetSubTexmap(ID_DI, tex); } } if (TileShaderPropertyRef tileShadeRef = SelectFirstObjectOfType<TileShaderProperty>(props)) { if ( Texmap* tex = CreateTexture( tileShadeRef->GetFileName() ) ) { m->SetSubTexmap(ID_DI, tex); } } if (TallGrassShaderPropertyRef grassShadeRef = SelectFirstObjectOfType<TallGrassShaderProperty>(props)) { if ( Texmap* tex = CreateTexture( grassShadeRef->GetFileName() ) ) { m->SetSubTexmap(ID_DI, tex); } } if (Lighting30ShaderPropertyRef lighting30ShadeRef = SelectFirstObjectOfType<Lighting30ShaderProperty>(props)) { if ( BSShaderTextureSetRef textures = lighting30ShadeRef->GetTextureSet() ) { if ( Texmap* tex = CreateTexture( textures->GetTexture(0) ) ) m->SetSubTexmap(ID_DI, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(1) ) ) m->SetSubTexmap(ID_BU, CreateNormalBump(NULL, tex)); if ( Texmap* tex = CreateTexture( textures->GetTexture(3) ) ) m->SetSubTexmap(ID_SI, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(4) ) ) m->SetSubTexmap(ID_RL, tex); if ( Texmap* tex = CreateTexture( textures->GetTexture(5) ) ) { if ( Texmap* mask = CreateTexture( textures->GetTexture(2) ) ) tex = CreateMask(NULL, tex, mask); m->SetSubTexmap(ID_SP, tex); } } } return m; } return NULL; }