/*---------------------------------------------------------------------------*/ void NifCollisionUtility::cleanTreeCollision(NiNodeRef pNode) { vector<NiAVObjectRef> srcChildList(pNode->GetChildren()); // children of node // remove collision object (new style [>= Oblivion]) pNode->SetCollisionObject(NULL); // iterate over source nodes and remove possible old-style [Morrowind] collision node for (auto ppIter=srcChildList.begin(), pEnd=srcChildList.end(); ppIter != pEnd; ppIter++) { // RootCollisionNode if (DynamicCast<RootCollisionNode>(*ppIter) != NULL) { pNode->RemoveChild(*ppIter); } // NiNode else if (DynamicCast<NiNode>(*ppIter) != NULL) { cleanTreeCollision(DynamicCast<NiNode>(*ppIter)); } // other children else { (*ppIter)->SetCollisionObject(NULL); } } // for (vector<NiAVObjectRef>::iterator ppIter = srcChildList.begin(); .... }
NiNodeRef Exporter::createNode(INode* maxNode, const string& name) { USES_CONVERSION; bool ismatch = strmatch(T2A(maxNode->GetName()), name); if (ismatch) { NodeToNodeMap::iterator itr = mNodeMap.find(maxNode); if (itr != mNodeMap.end()) return (*itr).second; } NiNodeRef node; if (!findNode(name, node)) { node = createNode(); BOOL noname = FALSE; if (!maxNode->GetUserPropBool(NP_NONAME, noname) || !noname) node->SetName(name); } if (wildmatch("noname*", name)) { maxNode->SetUserPropBool(NP_NONAME, TRUE); } mNodeMap[maxNode] = node; return node; }
NiSkinInstance::NiSkinInstance( NiNode * skeleton_root, vector< Ref<NiNode> > bone_nodes ) { //Call normal constructor NiSkinInstance(); //Ensure that all bones are below the skeleton root node on the scene graph for ( unsigned int i = 0; i < bone_nodes.size(); ++i ) { bool is_decended = false; NiNodeRef node = bone_nodes[i]; while ( node != NULL ) { if ( node == skeleton_root ) { is_decended = true; break; } node = node->GetParent(); } if ( is_decended == false ) { throw runtime_error( "All bones must be lower than the skeleton root in the scene graph." ); } } //Add the bones to the internal list bones.resize( bone_nodes.size() ); for ( unsigned int i = 0; i < bone_nodes.size(); ++i ) { bones[i] = bone_nodes[i]; } //Flag any bones that are part of this skin instance for ( unsigned int i = 0; i < bones.size(); ++i ) { bones[i]->SetSkinFlag(true); } //Store skeleton root and inform it of this attachment skeletonRoot = skeleton_root; skeletonRoot->AddSkin( this ); }
bool NifImporter::ImportMeshes(NiNodeRef node) { bool ok = true; try { #if 1 vector<NiTriShapeRef> trinodes = DynamicCast<NiTriShape>(node->GetChildren()); for (vector<NiTriShapeRef>::iterator itr = trinodes.begin(), end = trinodes.end(); itr != end; ++itr){ ok |= ImportMesh(*itr); } vector<NiTriStripsRef> tristrips = DynamicCast<NiTriStrips>(node->GetChildren()); for (vector<NiTriStripsRef>::iterator itr = tristrips.begin(), end = tristrips.end(); itr != end; ++itr){ ok |= ImportMesh(*itr); } #else // Only do multiples on object that have same name and use XXX:# notation vector<NiTriBasedGeomRef> trigeom = DynamicCast<NiTriBasedGeom>(node->GetChildren()); ok |= ImportMultipleGeometry(node, trigeom); #endif vector<NiNodeRef> nodes = DynamicCast<NiNode>(node->GetChildren()); for (vector<NiNodeRef>::iterator itr = nodes.begin(), end = nodes.end(); itr != end; ++itr){ ok |= ImportMeshes(*itr); } } catch( exception & e ) { e=e; ok = false; } catch( ... ) { ok = false; } return ok; }
NiNodeRef Exporter::createNode() { NiNodeRef node = CreateNiObject<NiNode>(); if (IsFallout3() || IsSkyrim()) { node->SetFlags(14); } return node; }
void Exporter::sortNodes(NiNodeRef node) { node->SortChildren(SortNodeEquivalence()); vector<NiNodeRef> children = DynamicCast<NiNode>(node->GetChildren()); for (vector<NiNodeRef>::iterator itr = children.begin(); itr != children.end(); ++itr) sortNodes(*itr); }
void GoToSkeletonBindPosition(vector<NiNodeRef>& blocks) { //Send all skeleton roots to bind position for (unsigned int i = 0; i < blocks.size(); ++i) { NiNodeRef node = blocks[i]; if ( node != NULL && node->IsSkeletonRoot() ) { node->GoToSkeletonBindPosition(); } } }
NiNodeRef Exporter::getNode(const string& name) { NodeMap::iterator itr = mNameMap.find(name); if (itr != mNameMap.end()) return (*itr).second; NiNodeRef node = CreateNiObject<NiNode>(); if ( IsFallout3() || IsSkyrim() ) { node->SetFlags( 14 ); } node->SetName(name); mNameMap[name] = node; return node; }
/** * @brief writes the given nif to the given file. */ void dumpNif(const std::string& n, CellMeshList& l){ using namespace Niflib; NiNodeRef node = new NiNode; for ( std::list<NiAVObjectRef>::iterator iter = l.begin(); l.end() != iter; ++iter) if ( *iter ) node->AddChild(*iter); NiObjectRef obj = DynamicCast<NiObject>( node ); unsigned ver = 67108866; WriteNifTree(n, obj, NifInfo(ver)); }
void getcasesout(QString etc) { hkroot=new hkRootLevelContainer(); if(etc.contains(".xml",Qt::CaseSensitive)==true) { hkOstream stream(etc.toStdString().c_str()); hkSerializeUtil::saveTagfile( hkroot, hkRootLevelContainerClass, stream.getStreamWriter(), HK_NULL, hkSerializeUtil::SAVE_TEXT_FORMAT); } if(etc.contains(".hkx",Qt::CaseSensitive)==true) { hkPackfileWriter::Options options; hkOstream stream(etc.toStdString().c_str()); hkSerializeUtil::savePackfile( hkroot, hkRootLevelContainerClass, hkOstream(stream).getStreamWriter(), options ); //hkResult res = hkSerializeUtil::save(hkroot, stream.getStreamWriter(),hkSerializeUtil::SAVE_WRITE_ATTRIBUTES); } else if(etc.contains(".nif",Qt::CaseSensitive)==true) { niparentnode=new NiNode(); niparentnode->SetName("root"); WriteNifTree(etc.toStdString(),niparentnode,nifInfo); } else if(etc.contains(".kfm",Qt::CaseSensitive)==true) { niparentnode=new NiNode(); niparentnode->SetName("root"); WriteNifTree(etc.toStdString(),niparentnode,nifInfo); } else if(etc.contains(".dae",Qt::CaseSensitive)==true) { const aiScene* scene1; aiExportScene(scene1,"dae","hihh",0); } else if(etc.contains(".obj",Qt::CaseSensitive)==true) { const aiScene* scene1; aiExportScene(scene1,"obj","hihh",0); } else if(etc.contains(".FBX",Qt::CaseSensitive)==true) { // } else { QMessageBox* mes; mes->setText("format isnt available for export"); mes->exec(); } }
/*---------------------------------------------------------------------------*/ unsigned int NifCollisionUtility::getGeometryFromNode(NiNodeRef pNode, vector<hkGeometry>& geometryMap, vector<hkGeometry>& geometryMapColl, vector<Matrix44>& transformAry) { bhkCollisionObjectRef pCollObject(DynamicCast<bhkCollisionObject>(pNode->GetCollisionObject())); vector<NiAVObjectRef> childList (pNode->GetChildren()); // add own translation to list transformAry.push_back(pNode->GetLocalTransform()); // get geometry from collision object if (pCollObject != NULL) { // search for embedded shape bhkRigidBodyRef pRBody(DynamicCast<bhkRigidBody>(pCollObject->GetBody())); if (pRBody != NULL) { getGeometryFromCollShape(pRBody->GetShape(), geometryMapColl, transformAry); } } // if (pCollObject != NULL) // iterate over children for (vector<NiAVObjectRef>::iterator ppIter = childList.begin(); ppIter != childList.end(); ppIter++) { // NiTriShape if (DynamicCast<NiTriShape>(*ppIter) != NULL) { getGeometryFromTriShape(DynamicCast<NiTriShape>(*ppIter), geometryMap, transformAry); } // NiTriStrips else if (DynamicCast<NiTriStrips>(*ppIter) != NULL) { getGeometryFromTriStrips(DynamicCast<NiTriStrips>(*ppIter), geometryMap, transformAry); } // RootCollisionNode else if (DynamicCast<RootCollisionNode>(*ppIter) != NULL) { getGeometryFromNode(&(*DynamicCast<RootCollisionNode>(*ppIter)), geometryMapColl, geometryMapColl, transformAry); } // NiNode (and derived classes?) else if (DynamicCast<NiNode>(*ppIter) != NULL) { getGeometryFromNode(DynamicCast<NiNode>(*ppIter), geometryMap, geometryMapColl, transformAry); } } // for (vector<NiAVObjectRef>::iterator ppIter = childList.begin(); ppIter != childList.end(); ppIter++) // remove own translation from list transformAry.pop_back(); return geometryMap.size(); }
bool NifImporter::IsBiped() { if (HasSkeleton()){ NiNodeRef rootNode = root; if (rootNode){ list<NiExtraDataRef> extraData = rootNode->GetExtraData(); if (!extraData.empty()) { if ( BSXFlagsRef flags = SelectFirstObjectOfType<BSXFlags>(extraData) ) { return (flags->GetData() & 0x4); } } } } return false; }
static float CalcScale(INode *bone, NiNodeRef node, vector<NiNodeRef>& children) { int n = bone->NumberOfChildren(); if (n > 0) { float len1 = 0.0f; float len2 = 0.0f; Matrix3 m = bone->GetNodeTM(0); Matrix3 m2 = TOMATRIX3(node->GetWorldTransform()); for (int i = 0; i<n; i++) { INode *child = bone->GetChildNode(i); LPCTSTR name = child->GetName(); if (HasBipedPosDOF(name)) continue; Matrix3 cm = child->GetObjectTM(0); len1 += Length(m.GetTrans()-cm.GetTrans()); if (NiNodeRef child2 = FindNodeByName(children, string(child->GetName()))){ Matrix3 cm2 = TOMATRIX3(child2->GetWorldTransform()); len2 += Length(m2.GetTrans()-cm2.GetTrans()); } } return (len2 != 0.0f && len1 != 0.0f) ? (len2/len1) : 1.0f; } return 1.0f; }
void Exporter::setName(NiNodeRef node, const string& name) { USES_CONVERSION; tstring tname = A2TString(name); node->SetName(name); mNameMap[tname] = node; }
bool Exporter::exportUPB(NiNodeRef &root, INode *node) { bool ok = false; if (!mUserPropBuffer) return ok; // Write the actual UPB sans any np_ prefixed strings TSTR upb; node->GetUserPropBuffer(upb); if (!upb.isNull()) { string line; istringstream istr(string(upb), ios_base::out); ostringstream ostr; while (!istr.eof()) { std::getline(istr, line); if (!line.empty() && 0 != line.compare(0, 3, "np_")) ostr << line << endl; } if (!ostr.str().empty()) { NiStringExtraDataRef strings = CreateNiObject<NiStringExtraData>(); strings->SetName("UPB"); strings->SetData(ostr.str()); root->AddExtraData(DynamicCast<NiExtraData>(strings)); ok = true; } } return ok; }
void Exporter::ApplyAllSkinOffsets( NiAVObjectRef & root ) { NiGeometryRef niGeom = DynamicCast<NiGeometry>(root); if ( niGeom != NULL && niGeom->IsSkin() == true ) { niGeom->ApplySkinOffset(); } NiNodeRef niNode = DynamicCast<NiNode>(root); if ( niNode != NULL ) { //Call this function on all children vector<NiAVObjectRef> children = niNode->GetChildren(); for ( unsigned i = 0; i < children.size(); ++i ) { ApplyAllSkinOffsets( children[i] ); } } }
Exporter::Result Exporter::exportLight(NiNodeRef parent, INode *node, GenLight* light) { TimeValue t = 0; NiLightRef niLight; switch (light->Type()) { case OMNI_LIGHT: { if (light->GetAmbientOnly()) { niLight = new NiAmbientLight(); } else { NiPointLightRef pointLight = new NiPointLight(); float atten = light->GetAtten(t, ATTEN_START); switch (light->GetDecayType()) { case 0: pointLight->SetConstantAttenuation(1.0f); break; case 1: pointLight->SetLinearAttenuation( atten / 4.0f ); break; case 2: pointLight->SetQuadraticAttenuation( sqrt(atten / 4.0f) ); break; } niLight = StaticCast<NiLight>(pointLight); } } break; case TSPOT_LIGHT: case FSPOT_LIGHT: niLight = new NiSpotLight(); break; case DIR_LIGHT: case TDIR_LIGHT: niLight = new NiDirectionalLight(); break; } if (niLight == NULL) return Skip; niLight->SetName(node->GetName()); Matrix3 tm = getObjectTransform(node, t, !mFlattenHierarchy); niLight->SetLocalTransform( TOMATRIX4(tm, false) ); niLight->SetDimmer( light->GetIntensity(0) ); Color3 rgbcolor = TOCOLOR3( light->GetRGBColor(0) ); if (light->GetAmbientOnly()) { niLight->SetDiffuseColor(Color3(0,0,0)); niLight->SetSpecularColor(Color3(0,0,0)); niLight->SetAmbientColor(rgbcolor); } else { niLight->SetDiffuseColor(rgbcolor); niLight->SetSpecularColor(rgbcolor); niLight->SetAmbientColor(Color3(0,0,0)); } parent->AddChild( DynamicCast<NiAVObject>(niLight) ); return Ok; }
static void BuildNodes(NiNodeRef object, vector<NiNodeRef>& nodes) { if (!object) return; nodes.push_back(object); vector<NiNodeRef> links = DynamicCast<NiNode>(object->GetChildren()); for (vector<NiNodeRef>::iterator itr = links.begin(), end = links.end(); itr != end; ++itr) BuildNodes(*itr, nodes); }
static bool HasUserPropBuffer(NiNodeRef node) { if (node) { if (NiStringExtraDataRef data = SelectFirstObjectOfType<NiStringExtraData>(node->GetExtraData())){ if (strmatch(data->GetName(), "UserPropBuffer")) return true; } } return false; }
bool Exporter::removeUnreferencedBones(NiNodeRef node) { NiNodeRef parent = node->GetParent(); bool remove = (NULL != parent) && !node->IsSkinInfluence(); Matrix44 ntm = node->GetLocalTransform(); vector<NiAVObjectRef> children = node->GetChildren(); for (vector<NiAVObjectRef>::iterator itr = children.begin(); itr != children.end(); ++itr) { NiAVObjectRef& child = (*itr); bool childRemove = false; if (child->IsDerivedType(NiNode::TYPE)) { childRemove = removeUnreferencedBones(StaticCast<NiNode>(child)); } if (childRemove) { node->RemoveChild(child); } else if (remove) // Reparent abandoned nodes to root { Matrix44 tm = child->GetLocalTransform(); child->SetLocalTransform( ntm * tm ); node->RemoveChild(child); mNiRoot->AddChild(child); } } return remove; }
bool NifImporter::ImportCollision(NiNodeRef node) { bool ok = false; if (!enableCollision) return false; // Currently only support the Oblivion bhk basic objects bhkNiCollisionObjectRef collObj = node->GetCollisionObject(); if (collObj) { NiObjectRef body = collObj->GetBody(); if (body->IsDerivedType(bhkRigidBody::TYPE)) { bhkRigidBodyRef rbody = DynamicCast<bhkRigidBody>(body); if (bhkShapeRef shape = rbody->GetShape()) { INode *node = NULL; NiNodeRef target = collObj->GetTarget(); if (mergeNonAccum && target && wildmatch("* NonAccum", target->GetName()) ) { node = FindNode(target->GetParent()); } else if (target && strmatch(target->GetName(), "Scene Root")) { node = gi->GetRootNode(); } else { node = FindNode(target); } CollisionImport ci(*this); Matrix3 tm(true); if (INode *body = ci.CreateRigidBody(rbody, node, tm)) { if (!ci.ImportShape(body, rbody, shape, node, tm)) { gi->DeleteNode(body, FALSE); } } } } } return ok; }
bool Exporter::exportPrn(NiNodeRef &obj, INode *node) { // Export Prn Text strings for any parent bones if parent is root if (mSupportPrnStrings && Exporter::mNifVersionInt >= VER_10_0_1_0) { if (INode *parentNode = node->GetParentNode()){ string parentName = parentNode->GetName(); NiStringExtraDataRef strings = new NiStringExtraData(); strings->SetName("Prn"); strings->SetData(parentName); obj->AddExtraData(DynamicCast<NiExtraData>(strings)); return true; } } return false; }
NiNodeRef Exporter::makeNode(NiNodeRef &parent, INode *maxNode, bool local) { string name = (char*)maxNode->GetName(); NiNodeRef node = getNode(maxNode); Matrix33 rot; Vector3 trans; TimeValue t = 0; nodeTransform(rot, trans, maxNode, t, local); node->SetLocalRotation(rot); node->SetLocalTranslation(trans); exportUPB(node, maxNode); // Normal Embedded Animation if (mExportType == NIF_WO_KF) CreateController(maxNode, Interval()); parent->AddChild(DynamicCast<NiAVObject>(node)); return node; }
static float CalcLength(NiNodeRef node, vector<NiAVObjectRef>& children) { bool hasChildren = !children.empty(); float len = 0.0f; if (hasChildren) { for (vector<NiAVObjectRef>::iterator itr=children.begin(), end = children.end(); itr != end; ++itr) { len += GetObjectLength(*itr); } len /= float(children.size()); } else { len = node->GetLocalTranslation().Magnitude(); } return len; }
/*---------------------------------------------------------------------------*/ NiNodeRef NifConvertUtility::convertNiNode(NiNodeRef pSrcNode, NiTriShapeRef pTmplNode, NiNodeRef pRootNode, NiAlphaPropertyRef pTmplAlphaProp) { NiNodeRef pDstNode (pSrcNode); vector<NiAVObjectRef> srcShapeList(pDstNode->GetChildren()); // find NiAlphaProperty and use as template in sub-nodes if (DynamicCast<NiAlphaProperty>(pDstNode->GetPropertyByType(NiAlphaProperty::TYPE)) != NULL) { pTmplAlphaProp = DynamicCast<NiAlphaProperty>(pDstNode->GetPropertyByType(NiAlphaProperty::TYPE)); } // unlink protperties -> not used in new format pDstNode->ClearProperties(); // shift extra data to new version pDstNode->ShiftExtraData(VER_20_2_0_7); // unlink children pDstNode->ClearChildren(); // iterate over source nodes and convert using template for (vector<NiAVObjectRef>::iterator ppIter = srcShapeList.begin(); ppIter != srcShapeList.end(); ppIter++) { // NiTriShape //Type t = (*ppIter)->GetType(); if (DynamicCast<NiTriShape>(*ppIter) != NULL) { pDstNode->AddChild(&(*convertNiTriShape(DynamicCast<NiTriShape>(*ppIter), pTmplNode, pTmplAlphaProp))); } // NiNode (and derived classes?) else if (DynamicCast<NiNode>(*ppIter) != NULL) { pDstNode->AddChild(&(*convertNiNode(DynamicCast<NiNode>(*ppIter), pTmplNode, pRootNode, pTmplAlphaProp))); } } return pDstNode; }
/*---------------------------------------------------------------------------*/ NiNodeRef NifPrepareUtility::parse4Blender(NiNodeRef pNode) { vector<NiAVObjectRef> childList(pNode->GetChildren()); list<NiExtraDataRef> extraList(pNode->GetExtraData()); // parse extra data for BSInvMarker for (auto pIter(extraList.begin()), pEnd(extraList.end()); pIter != pEnd; pIter++) { if (_remBSInvMarker && (DynamicCast<BSInvMarker>(*pIter) != NULL)) { pNode->RemoveExtraData(*pIter); } } // unlink children pNode->ClearChildren(); // iterate over children for (auto pIter(childList.begin()), pEnd(childList.end()); pIter != pEnd; pIter++) { // NiTriShape => remove BSLightingShaderProperty if (DynamicCast<NiTriShape>(*pIter) != NULL) { if (_remBSProperties) { NiTriShapeRef pShape (DynamicCast<NiTriShape>(*pIter)); // remove properties (Bethesda uses max. 2) pShape->SetBSProperty(0, NULL); pShape->SetBSProperty(1, NULL); } // add shape to node pNode->AddChild(*pIter); } // BSInvMarker => remove whole object else if (_remBSInvMarker && (DynamicCast<BSInvMarker>(*pIter) != NULL)) { // skip entry => do not add to final list } // NiNode (and derived classes?) => iterate subnodes else if (DynamicCast<NiNode>(*pIter) != NULL) { pNode->AddChild(&(*parse4Blender(DynamicCast<NiNode>(*pIter)))); } } // for (auto pIter(childList.begin()), pEnd(childList.end()); pIter != pEnd; pIter++) return pNode; }
static void BuildControllerRefList(NiNodeRef node, map<string,int>& ctrlCount) { list<NiTimeControllerRef> ctrls = node->GetControllers(); for (list<NiTimeControllerRef>::iterator itr = ctrls.begin(), end = ctrls.end(); itr != end; ++itr) { list<NiNodeRef> nlist = DynamicCast<NiNode>((*itr)->GetRefs()); // Append extra targets. Goes away if GetRefs eventually returns the extra targets if (NiMultiTargetTransformControllerRef multiCtrl = DynamicCast<NiMultiTargetTransformController>(*itr)) { vector<NiNodeRef> extra = DynamicCast<NiNode>( multiCtrl->GetExtraTargets() ); nlist.insert(nlist.end(), extra.begin(), extra.end()); } for (list<NiNodeRef>::iterator nitr = nlist.begin(); nitr != nlist.end(); ++nitr){ string name = (*nitr)->GetName(); map<string,int>::iterator citr = ctrlCount.find(name); if (citr != ctrlCount.end()) ++(*citr).second; else ctrlCount[name] = 1; } } }
static AngAxis CalcTransform(INode *bone, NiNodeRef node, vector<NiNodeRef>& children) { Matrix3 mr(TRUE); int n = bone->NumberOfChildren(); if (n > 0) { int c = 0; Point3 vs(0.0f, 0.0f, 0.0f), vf(0.0f, 0.0f, 0.0f); Matrix3 m = bone->GetNodeTM(0); Matrix3 m2 = TOMATRIX3(node->GetWorldTransform()); for (int i = 0; i<n; i++) { INode *child = bone->GetChildNode(i); LPCTSTR name = child->GetName(); if (HasBipedPosDOF(name)) continue; Matrix3 cm = child->GetObjectTM(0); vs += (m.GetTrans()-cm.GetTrans()); if (NiNodeRef child2 = FindNodeByName(children, string(child->GetName()))){ Matrix3 cm2 = TOMATRIX3(child2->GetWorldTransform()); vf += (m2.GetTrans()-cm2.GetTrans()); } ++c; } vs = FNormalize(vs); vf = FNormalize(vf); Point3 cross = CrossProd(vs, vf); if (fabs(cross.x) < 0.01 && fabs(cross.y) < 0.01 && fabs(cross.z) < 0.01) return AngAxis(Point3(0.0f, 0.0f, 0.0f), 0.0f); float dot = DotProd(vs, vf); return AngAxis( cross, acos( dot ) ); } return mr; }
NiTriBasedGeomRef Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp, bool exportStrips) { NiTriBasedGeomRef shape; NiTriBasedGeomDataRef data; //if (Exporter::mFixNormals) { // FixNormals(grp.faces, grp.verts, grp.vnorms); //} if (exportStrips) { shape = new NiTriStrips(); data = new NiTriStripsData(grp.faces, !mUseAlternateStripper); } else { shape = new NiTriShape(); data = new NiTriShapeData(grp.faces); } if ( IsFallout3() || IsSkyrim() ) shape->SetFlags( 14 ); data->SetVertices(grp.verts); data->SetNormals(grp.vnorms); data->SetVertexIndices(grp.vidx); data->SetUVSetMap(grp.uvMapping); int nUVs = grp.uvs.size(); if ( IsFallout3() || IsSkyrim() ) nUVs = min(1, nUVs); data->SetUVSetCount(nUVs); for (int i =0;i<nUVs; ++i) { data->SetUVSet(i, grp.uvs[i]); } //if (IsSkyrim() && grp.vcolors.size() == 0) // grp.vcolors.resize(grp.verts.size(), Color4(1.0f,1.0f,1.0f,1.0f)); if (mVertexColors && grp.vcolors.size() > 0) { bool allWhite = true; Color4 white(1.0f, 1.0f, 1.0f, 1.0f); for (int i=0,n=grp.vcolors.size();i<n; ++i) { if (white != grp.vcolors[i]) { allWhite = false; break; } } if (!allWhite) data->SetVertexColors(grp.vcolors); } data->SetConsistencyFlags(CT_STATIC); shape->SetData(data); if (Exporter::mTangentAndBinormalExtraData && (Exporter::mNifVersionInt > VER_4_2_2_0)) { // enable traditional tangents and binormals for non-oblivion meshes if ( !IsOblivion() && (Exporter::mNifVersionInt >= VER_10_0_1_0) ) data->SetTspaceFlag( 0x01 ); shape->UpdateTangentSpace(Exporter::mTangentAndBinormalMethod); } parent->AddChild(DynamicCast<NiAVObject>(shape)); NiAVObjectRef av(DynamicCast<NiAVObject>(shape)); makeMaterial(av, mtl); shape->SetActiveMaterial(0); return shape; }
unsigned long CMesh::Load_Mesh(unsigned long want_formID) { unsigned long index; CStat_Record *dastat; MeshData *dameshdata; char tmppath[MAX_PATH]; dastat=pTreeManager->GetStat(want_formID); if(dastat==NULL) return 1; formID=want_formID; strcpy_s(tmppath,MAX_PATH,"data\\meshes\\"); strcat_s(tmppath,MAX_PATH,dastat->Get_Filename()); //output_text_char(L"Filename: ",tmppath); NiObjectRef root=ReadNifTree(tmppath); NiNodeRef node = DynamicCast<NiNode>(root); if(node==NULL) return 2; vector<NiAVObjectRef> refs=node->GetChildren(); for(index=0;index<refs.size();index++) { if(refs[index]->IsSameType(NiTriStrips::TYPE)) { NiTriStripsRef datristrip=DynamicCast<NiTriStrips>(refs[index]); //Add a tri strip buffer to the mesh dameshdata=AddTriStrips(datristrip); if(dameshdata==NULL) { output_text(L"Error AddTriStrips\r\n"); return 3; } Vector3 translation=datristrip->GetLocalTranslation(); dameshdata->local_translation[0]=translation.x; dameshdata->local_translation[1]=translation.y; dameshdata->local_translation[2]=translation.z; dameshdata->tristrip=1; } else { if(refs[index]->IsSameType(NiTriShape::TYPE)) { NiTriShapeRef datrishape=DynamicCast<NiTriShape>(refs[index]); //Add a tri shape to the mesh dameshdata=AddTriShape(datrishape); if(dameshdata==NULL) { output_text(L"Error AddTriShape\r\n"); return 3; } Vector3 translation=datrishape->GetLocalTranslation(); dameshdata->local_translation[0]=translation.x; dameshdata->local_translation[1]=translation.y; dameshdata->local_translation[2]=translation.z; dameshdata->tristrip=0; } } } //Load the collision data /*NiCollisionObjectRef dacol=node->GetCollisionObject(); if(dacol->IsSameType(bhkCollisionObject::TYPE)) { bhkCollisionObjectRef bhkCol=DynamicCast<bhkCollisionObject>(dacol); NiObjectRef daobj=bhkCol->GetBody(); if(daobj->IsSameType(bhkRigidBody::TYPE)) { bhkRigidBody } }*/ return 0; }