BOOL PFOperatorInstanceShapeMXSValidator::Validate(PB2Value& v) { INode* iNode = (INode*)v.r; if (iNode == NULL) return NULL; TimeValue t = GetCOREInterface()->GetTime(); Tab<INode*> stack; stack.Append(1, &iNode, 10); while (stack.Count()) { INode *node = stack[stack.Count()-1]; stack.Delete(stack.Count()-1, 1); Object *obj = node->EvalWorldState(t).obj; if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0))) return TRUE; // add children to the stack for (int i = 0; i < node->NumberOfChildren(); i++) { INode *childNode = node->GetChildNode(i); if (childNode) stack.Append(1, &childNode, 10); } } return FALSE; }
BOOL SplineData::HitTestCrossSection(GraphicsWindow *gw, HitRegion hr, SplineMapProjectionTypes projType, Tab<int> &hitSplines, Tab<int> &hitCrossSections) { hitSplines.SetCount(0); hitCrossSections.SetCount(0); DWORD limit = gw->getRndLimits(); gw->setRndLimits(( limit | GW_PICK) & ~GW_ILLUM); gw->setHitRegion(&hr); //loop through splines for (int splineIndex = 0; splineIndex < mSplineElementData.Count();splineIndex++) { if (mSplineElementData[splineIndex]->IsSelected()) { for (int crossSectionIndex = 0; crossSectionIndex < NumberOfCrossSections(splineIndex); crossSectionIndex++) { SplineCrossSection section = mSplineElementData[splineIndex]->GetCrossSection(crossSectionIndex); Matrix3 crossSectionTM = section.mTM; gw->setTransform(crossSectionTM); gw->clearHitCode(); mSplineElementData[splineIndex]->DisplayCrossSections(gw, crossSectionIndex,projType ); if (gw->checkHitCode()) { hitSplines.Append(1,&splineIndex,10); hitCrossSections.Append(1,&crossSectionIndex,10); } } } } return hitSplines.Count(); }
void PrismObject::GetCollapseTypes(Tab<Class_ID> &clist,Tab<TSTR*> &nlist) { Object::GetCollapseTypes(clist, nlist); Class_ID id = EDITABLE_SURF_CLASS_ID; TSTR *name = new TSTR(GetString(IDS_SM_NURBS_SURFACE)); clist.Append(1,&id); nlist.Append(1,&name); }
void EditPolyMod::GetPaintHosts( Tab<MeshPaintHost*>& hosts, Tab<INode*>& paintNodes ) { ModContextList mcList; INodeTab nodes; ip->GetModContexts(mcList,nodes); EditPolyData* modData = NULL; for (int i=0; i<mcList.Count(); i++ ) { if( (modData=(EditPolyData*)mcList[i]->localData)== NULL) continue; MeshPaintHost* host = modData; hosts.Append( 1, &(host) ); INode *pNode = nodes[i]->GetActualINode(); paintNodes.Append( 1, &pNode ); } nodes.DisposeTemporary(); }
void Unreal3DExport::ExportNode( IGameNode * child ) { DebugPrint( _T("ExportNode: %s\n"), child->GetName() ); CheckCancel(); ProgressMsg.printf(GetString(IDS_INFO_ENUM_OBJ),NodeIdx,NodeCount,TSTR(child->GetName())); pInt->ProgressUpdate(Progress+((float)NodeIdx/NodeCount*U3D_PROGRESS_ENUM), FALSE, ProgressMsg.data()); ++NodeIdx; if( child->IsGroupOwner() ) { // do nothing } else { IGameObject * obj = child->GetIGameObject(); switch(obj->GetIGameType()) { case IGameObject::IGAME_MESH: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { Nodes.Append(1,&child); } break; } case IGameObject::IGAME_HELPER: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { TrackedNodes.Append(1,&child); } } break; } child->ReleaseIGameObject(); } for( int i=0; i<child->GetChildCount(); ++i ) { IGameNode * n = child->GetNodeChild(i); ExportNode(n); } }
bool UnflaggedNodeNamer::Proc(INode * pNode) { if (!m_namelist) return false; // otherwise, grab the list of node names and stick them in namelist if (! pNode->TestAFlag(A_WORK1)) { TSTR * pName = new TSTR(pNode->GetName()); // consumer must delete m_namelist->Append(1, &pName, 5); } return true; }
void SplineData::GetSelectedCrossSections(Tab<int> &selSplines, Tab<int> &selCrossSections) { selSplines.SetCount(0); for (int i = 0; i < mSplineElementData.Count(); i++) { if (mSplineElementData[i]->IsSelected()) { for (int j = 0; j < NumberOfCrossSections(i); j++) { if (CrossSectionIsSelected(i,j)) { selCrossSections.Append(1,&j,10); selSplines.Append(1,&i,10); } } } } }
void plDistributor::IFindFaceSet(const Box3& box, Tab<int32_t>& faces) const { Tab<int32_t> distNodes; fMeshTree.HarvestBox(box, distNodes); int i; for( i = 0; i < distNodes.Count(); i++ ) { int32_t iFace = int32_t(fMeshTree.GetBox(distNodes[i]).fIData); faces.Append(1, &iFace); } }
void SplineData::GetSelectedSplines(Tab<int> &selSplines) { selSplines.SetCount(0); for (int i = 0; i < mSplineElementData.Count(); i++) { if (mSplineElementData[i]->IsSelected()) { selSplines.Append(1,&i,10); } } }
void CModelExporter::CollectMeshFaces( Tab<FaceEx*>& faceList, IGameMesh* pMesh, size_t uMatID, BOOL bMultiMat ) { if(!bMultiMat) { for(int x = 0; x < pMesh->GetNumberOfFaces(); x++) { FaceEx* pTemp = pMesh->GetFace(x); faceList.Append(1, &pTemp); } } else faceList = pMesh->GetFacesFromMatID(uMatID); }
//From SpringSysClient //************************************************* Tab<Matrix3> Jiggle::GetForceMatrices(TimeValue t) { Tab<Matrix3> tms; INode* node; Matrix3 parentTM; parentTM = GetCurrentTM(t); tms.Append(1, &parentTM); for (int x=1;x<dyn_pb->Count(jig_control_node); x++) { Interval for_ever = FOREVER; dyn_pb->GetValue(jig_control_node, 0, node, for_ever, x); if (node) { Matrix3 mat = node->GetNodeTM(t); tms.Append(1, &mat); } } return tms; }
void Xrefutil::ConvertSelectedToXrefScene(HWND hWnd) { // *** ConvertSelectedToXrefScene *** // // Relatively simple -- take the selected nodes, save them out // to a new .MAX file, delete the selected nodes from the // current scene, and then do a RootNode->AddNewXRefFile // with the just-saved MAX file. INode * pNode = NULL; TSTR filename = _T(""); int i; INode * pRootNode = m_pInterface->GetRootNode(); if (!pRootNode) { // well, this is actually _really_ bad, but we just exit return; } if (m_pInterface->GetSelNodeCount() == 0) { ::MessageBox(hWnd, GetString(IDS_ERR3), ERROR_TITLE, MB_ICONSTOP | MB_OK); return; } Tab<INode *> nodetab; nodetab.ZeroCount(); nodetab.Shrink(); for (i = 0; i < m_pInterface->GetSelNodeCount(); i++) { pNode = m_pInterface->GetSelNode(i); nodetab.Append(1, &pNode, 5); } if (!DoOpenSaveDialog(filename)) { // either cancel or fail, just return return; } m_pInterface->FileSaveSelected(filename); // delete selected nodes, don't refresh yet for (i = 0; i < nodetab.Count(); i++) { nodetab[i]->Delete(0,TRUE); } AssetUser asset = IAssetManager::GetInstance()->GetAsset(filename,kXRefAsset); // add in the nodes we saved out as an xref'd scene pRootNode->AddNewXRefFile(asset, TRUE); m_pInterface->RedrawViews(m_pInterface->GetTime()); }
Tab<float> FP_Basic::myFunction3(Tab<float>& listRect) { mprintf(L"xin chao mytestfunction3\n"); mflush(); for (int i = 0; i < listRect.Count(); ++i) { listRect[i]++; mprintf(L"listRect[%d] = %f\n", i, listRect[i]); }; float a = 20; listRect.Append(1, &a); mflush(); //MessageBox(NULL, _T("Xin chao myFunction3!!!"), _T("Function Publishing Demonstration"), MB_OK); return Tab<float>(); }
void UniformGrid::InRadius(Point3 p, Tab<int> &indexList) { float radius = largestRadius; xHitList.ClearAll(); yHitList.ClearAll(); zHitList.ClearAll(); hitList.SetCount(0); //find the cell in the XGrid TagCells(p,radius, 0); //find the cell in the YGrid TagCells(p,radius, 1); //find the cell in the ZGrid TagCells(p,radius, 2); BitArray usedList; usedList.SetSize(pointBase.Count()); usedList.ClearAll(); int closest = -1; float d = 0.0f; Box3 localBounds; localBounds.Init(); localBounds += p; localBounds.EnlargeBy(radius); for (int i = 0; i < hitList.Count(); i++) { int index = hitList[i]; if (!usedList[index]) //check to see if we have processed this one or not { if (xHitList[index] && yHitList[index] && zHitList[index]) { usedList.Set(index); Point3 source = pointBase[index]; if (localBounds.Contains(source)) { indexList.Append(1,&index,1000); } } } } }
void Unreal3DExport::Init() { // Init CheckCancel(); pScene = GetIGameInterface(); GetConversionManager()->SetUserCoordSystem(UnrealCoords); if( bExportSelected ) { Tab<INode*> selnodes;; for( int i=0; i<pInt->GetSelNodeCount(); ++i ) { INode* n = pInt->GetSelNode(i); selnodes.Append(1,&n); } if( !pScene->InitialiseIGame(selnodes,false) ) throw MAXException(GetString(IDS_ERR_IGAME)); } else { if( !pScene->InitialiseIGame() ) throw MAXException(GetString(IDS_ERR_IGAME)); } // Enumerate scene NodeCount = pScene->GetTotalNodeCount(); for( int i=0; i<pScene->GetTopLevelNodeCount(); ++i ) { IGameNode * n = pScene->GetTopLevelNode(i); ExportNode(n); } Progress += U3D_PROGRESS_ENUM; // Get animation info FrameStart = pScene->GetSceneStartTime() / pScene->GetSceneTicks(); FrameEnd = pScene->GetSceneEndTime() / pScene->GetSceneTicks(); FrameCount = FrameEnd - FrameStart+1; if( FrameCount <= 0 || FrameEnd < FrameStart ) { ProgressMsg.printf(GetString(IDS_ERR_FRAMERANGE),FrameStart,FrameEnd); throw MAXException(ProgressMsg.data()); } pScene->SetStaticFrame(FrameStart); }
////////////////////////////////////////////////////////////////////////// // MNMeshLoopAdvancerEdge // TODO int MNMeshLoopAdvancerEdge::SetupFront(int startid, Tab<MNMeshLoopFront> &fronts) { // first previous is root // set initial connectors MNEdge *edge = m_mesh->E(startid); fronts.SetCount(0); int outcount = 0; for (int o = 0; o < 4; o++){ if (m_disableFlag & 1<<o) continue; int connector = -1; int contype; int nextid; if (o < 2){ // loop contype = 0; connector = o ? edge->v1 : edge->v2; nextid = MNMeshLoop_nextEdgeLoop(m_mesh,startid,connector); } else{ // ring contype = 1; connector = o%2 ? edge->f1 : edge->f2; nextid = connector >= 0 ? MNMeshLoop_nextEdgeRing(m_mesh,startid,connector) : -1; } if (nextid >= 0){ MNMeshLoopFront advance; advance.previndex = 0; advance.nextid = nextid; advance.connector = connector; advance.contype = contype; advance.crossed = FALSE; outcount++; fronts.Append(1,&advance); } } return outcount; }
static void GetSceneLights(Tab<INode*> & lights) { Interface *ip = GetCOREInterface(); TimeValue t = ip->GetTime(); INode * Root = ip->GetRootNode(); int Count = Root->NumberOfChildren(); int i=0; for( i=0; i < Count; i++) { INode * node = Root->GetChildNode(i); ObjectState Os = node->EvalWorldState(t); if(Os.obj && Os.obj->SuperClassID() == LIGHT_CLASS_ID) { lights.Append(1, &node); } } }
void Unreal3DExport::RegisterMaterial( IGameNode* node, IGameMesh* mesh, FaceEx* f, FJSMeshTri* tri ) { tri->TextureNum = f->matID; int matid = f->matID; IGameMaterial* mat = mesh->GetMaterialFromFace(f); if( mat ) { Tab<TSTR*> tokens = TokStr(mat->GetMaterialName(),_T(" \t,;")); for( int i=0; i!=tokens.Count(); ++i ) { if( MatchPattern(*tokens[i],TSTR(_T("F=*")),TRUE) ) { SplitStr(*tokens[i],_T('=')); tri->Flags = static_cast<byte>(_ttoi(tokens[i]->data())); } } tokens.Delete(0,tokens.Count()); if( Materials.Count() <= matid ) { Materials.Append(matid-Materials.Count()+1,&sMaterial::DefaultMaterial); } if( Materials[matid].Mat != mat ) { Materials[matid].Mat = mat; } /*for( int i=0; i!=mat->GetSubMaterialCount(); ++i ) { IGameMaterial* sub = mat->GetSubMaterial(i); if( sub ) { TSTR matname = sub->GetMaterialName(); int subid = mat->GetMaterialID(i); int x = 0; } }*/ } }
void proc(INodeTab &nodeTab) { int i; Tab<int> freeC; freeC.ZeroCount(); // find available channels for(i=0;i<100;i++) { int tI = i; if(!mp->chanBank[i].mModded) freeC.Append(1,&tI,0); } // If there are less channels than incoming targets, tell the user and quit out if(nodeTab.Count()>freeC.Count()) { TSTR buf1(GetString(IDS_NOFREE)); TSTR buf2(GetString(IDS_CANNOT)); MessageBox(mp->hwChannelList,buf1,buf2,MB_ICONSTOP | MB_OK); goto leapOut; } // Do the assignment of nodes for(i=0;i<nodeTab.Count();i++) { UI_MAKEBUSY if (theHold.Holding()) theHold.Put(new Restore_FullChannel(mp, i )); mp->ReplaceReference(101+freeC[i],nodeTab[i]); mp->chanBank[freeC[i]].buildFromNode(nodeTab[i]); mp->chanBank[freeC[i]].ReNormalize(); UI_MAKEFREE } leapOut: i=0; }
INT_PTR CALLBACK MainDlgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { TSTR buf; RefWatch *rc = DLGetWindowLongPtr<RefWatch *>(hWnd); if (!rc && msg != WM_INITDIALOG ) return FALSE; switch (msg) { case WM_INITDIALOG: rc = (RefWatch *)lParam; DLSetWindowLongPtr(hWnd, rc); CenterWindow(hWnd, IP->GetMAXHWnd()); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); return TRUE; case WM_CLOSE: DestroyWindow(rc->hMain); break; case WM_DESTROY: rc->DestroyWindow(); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_CLEAR: SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); break; case IDC_TVPICK: { TSTR str; HWND hIRefList = GetDlgItem(hWnd, IDC_IREF_LIST); HWND hRefMeList = GetDlgItem(hWnd, IDC_REFME_LIST); TrackViewPick tvp; tvp.anim = tvp.client = NULL; BOOL ok = IP->TrackViewPickDlg(hWnd, &tvp); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); if (ok) { if (tvp.anim && tvp.client) { rc->watchMe = tvp.anim; buf.printf(_T("Item Name: %s"), rc->GetName()); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), buf.data()); notifyObject.RemoveReference(); notifyObject.CreateReference(rc->watchMe); tvp.anim->GetClassName(str); buf.printf(_T("This Target ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), buf.data()); tvp.client->GetClassName(str); buf.printf(_T("Client ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), buf.data()); Tab<TSTR *> ptStr; TSTR *pTstr, Str(_T("")); pTstr = &Str; ptStr.Append(1, &pTstr); DisplayRefInfo(rc, hWnd, &ptStr); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); } else ok = FALSE; } if (!ok) { rc->watchMe = NULL; notifyObject.RemoveReference(); SendMessage(hIRefList, LB_RESETCONTENT, 0, 0L); SendMessage(hRefMeList, LB_RESETCONTENT, 0, 0L); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); } break; }; return TRUE; case IDC_REFME_LIST: case IDC_IREF_LIST: if (HIWORD(wParam) == LBN_DBLCLK) { TSTR str; HWND hIRefList = GetDlgItem(hWnd, IDC_IREF_LIST); HWND hRefMeList = GetDlgItem(hWnd, IDC_REFME_LIST); BOOL ok = TRUE; // Get list item. HWND listbox = (HWND)lParam; int i = SendMessage(listbox, LB_GETCURSEL, 0, 0); // Change the currently watched object. if (LOWORD(wParam) == IDC_IREF_LIST) rc->watchMe = rc->watchMe->GetReference(i); else { bool fulltree = IsDlgButtonChecked(hWnd, IDC_FULLTREE) ? true : false; if (fulltree) { // Enum dependents. RefCheckFindDepEnumProc rfep(i, rc->watchMe); rc->watchMe->DoEnumDependents(&rfep); if (rfep.rmaker != NULL) { if (!OkToDisplay(hWnd, rfep.rmaker)) return TRUE; rc->watchMe = (ReferenceTarget*)rfep.rmaker; } else ok = FALSE; } else { // We only displayed first-level dependents. int count = 0; DependentIterator di(rc->watchMe); ReferenceMaker* maker = NULL; while ((maker = di.Next()) != NULL) { if (count == i) { if (!OkToDisplay(hWnd, maker)) return TRUE; rc->watchMe = (ReferenceTarget*)maker; break; } if (count > i) return TRUE;// not sure how this could happen... ++count; } } } SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); if (ok) { buf.printf(_T("Item Name: %s"), rc->GetName()); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), buf.data()); notifyObject.RemoveReference(); notifyObject.CreateReference(rc->watchMe); rc->watchMe->GetClassName(str); buf.printf(_T("This Target ClassName: %s"), str); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), buf.data()); buf.printf(_T("Client ClassName: %s"), _T("(Unable to determine)")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), buf.data()); Tab<TSTR *> ptStr; TSTR *pTstr, Str(_T("")); pTstr = &Str; ptStr.Append(1, &pTstr); DisplayRefInfo(rc, hWnd, &ptStr); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); } else { rc->watchMe = NULL; notifyObject.RemoveReference(); SendMessage(hIRefList, LB_RESETCONTENT, 0, 0L); SendMessage(hRefMeList, LB_RESETCONTENT, 0, 0L); SendMessage(GetDlgItem(hWnd, IDC_MSG_LIST), LB_RESETCONTENT, 0, 0L); SetWindowText(GetDlgItem(hWnd, IDC_CLASSNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_CLIENTNAME), _T("")); SetWindowText(GetDlgItem(hWnd, IDC_ITEM_NAME), _T("")); } } break; }; break; default: return FALSE; }; return TRUE; }
void UnwrapMod::fnUnfoldSelectedPolygons(int unfoldMethod, BOOL normalize) { // flatten selected polygons BailStart(); BitArray *polySel = fnGetSelectedPolygons(); BitArray holdPolySel; if (polySel == NULL) return; if (TVMaps.f.Count() == 0) return; if (!theHold.Holding()) { theHold.SuperBegin(); theHold.Begin(); } holdPolySel.SetSize(polySel->GetSize()); holdPolySel = *polySel; HoldPointsAndFaces(); Point3 normal(0.0f,0.0f,1.0f); BitArray oldSel = *fnGetSelectedPolygons(); Tab<Point3> mapNormal; mapNormal.SetCount(0); BOOL bContinue = BuildCluster( mapNormal, 5.0f, TRUE, TRUE); TSTR statusMessage; BitArray sel; sel.SetSize(TVMaps.f.Count()); if (bContinue) { for (int i =0; i < clusterList.Count(); i++) { sel.ClearAll(); for (int j = 0; j < clusterList[i]->faces.Count();j++) sel.Set(clusterList[i]->faces[j]); fnSelectPolygonsUpdate(&sel, FALSE); PlanarMapNoScale(clusterList[i]->normal); int per = (i * 100)/clusterList.Count(); statusMessage.printf("%s %d%%.",GetString(IDS_PW_STATUS_MAPPING),per); if (Bail(ip,statusMessage)) { i = clusterList.Count(); bContinue = FALSE; } } if ( (bContinue) && (clusterList.Count() > 1) ) { if (!ip) return; ModContextList mcList; INodeTab nodes; ip->GetModContexts(mcList,nodes); int objects = mcList.Count(); MeshTopoData *md = (MeshTopoData*)mcList[0]->localData; if (md == NULL) { theHold.Cancel(); theHold.SuperCancel(); return; } Tab<Point3> objNormList; BuildNormals(md,objNormList); //remove internal edges BitArray *selectedPolygons = fnGetSelectedPolygons(); Tab<int> clusterGroups; clusterGroups.SetCount(TVMaps.f.Count()); for (i =0; i < clusterGroups.Count(); i++) { clusterGroups[i] = -1; } //loop through all tagged edges and remove any that onely have one edhes selected for (i = 0; i < clusterList.Count(); i++) { for (int j = 0; j < clusterList[i]->faces.Count(); j++) { int faceIndex = clusterList[i]->faces[j]; clusterGroups[faceIndex] = i; } } BitArray processedClusters; processedClusters.SetSize(clusterList.Count()); processedClusters.ClearAll(); Tab<BorderClass> edgesToBeProcessed; BOOL done = FALSE; int currentCluster = 0; processedClusters.Set(0); clusterList[0]->newX = 0.0f; clusterList[0]->newY = 0.0f; // clusterList[0]->angle = 0.0f; for (int i = 0; i < clusterList[0]->borderData.Count(); i++) { int outerFaceIndex = clusterList[0]->borderData[i].outerFace; int connectedClusterIndex = clusterGroups[outerFaceIndex]; if ((connectedClusterIndex != 0) && (connectedClusterIndex != -1)) { edgesToBeProcessed.Append(1,&clusterList[0]->borderData[i]); } } BitArray seedFaceList; seedFaceList.SetSize(clusterGroups.Count()); seedFaceList.ClearAll(); for (i = 0; i < seedFaces.Count(); i++) { seedFaceList.Set(seedFaces[i]); } while (!done) { Tab<int> clustersJustProcessed; clustersJustProcessed.ZeroCount(); done = TRUE; int edgeToAlign = -1; float angDist = PI*2; if (unfoldMethod == 1) angDist = PI*2; else if (unfoldMethod == 2) angDist = 0; for (i = 0; i < edgesToBeProcessed.Count(); i++) { int outerFace = edgesToBeProcessed[i].outerFace; int connectedClusterIndex = clusterGroups[outerFace]; if (!processedClusters[connectedClusterIndex]) { int innerFaceIndex = edgesToBeProcessed[i].innerFace; int outerFaceIndex = edgesToBeProcessed[i].outerFace; //get angle Point3 innerNorm, outerNorm; innerNorm = objNormList[innerFaceIndex]; outerNorm = objNormList[outerFaceIndex]; float dot = DotProd(innerNorm,outerNorm); float angle = 0.0f; if (dot == -1.0f) angle = PI; else if (dot == 1.0f) angle = 0.f; else angle = acos(dot); if (unfoldMethod == 1) { if (seedFaceList[outerFaceIndex]) angle = 0.0f; if (angle < angDist) { angDist = angle; edgeToAlign = i; } } else if (unfoldMethod == 2) { if (seedFaceList[outerFaceIndex]) angle = 180.0f; if (angle > angDist) { angDist = angle; edgeToAlign = i; } } } } if (edgeToAlign != -1) { int innerFaceIndex = edgesToBeProcessed[edgeToAlign].innerFace; int outerFaceIndex = edgesToBeProcessed[edgeToAlign].outerFace; int edgeIndex = edgesToBeProcessed[edgeToAlign].edge; int connectedClusterIndex = clusterGroups[outerFaceIndex]; seedFaceList.Set(outerFaceIndex, FALSE); processedClusters.Set(connectedClusterIndex); clustersJustProcessed.Append(1,&connectedClusterIndex); AlignCluster(i,connectedClusterIndex,innerFaceIndex, outerFaceIndex,edgeIndex); done = FALSE; } //build new cluster list for (int j = 0; j < clustersJustProcessed.Count(); j++) { int clusterIndex = clustersJustProcessed[j]; for (int i = 0; i < clusterList[clusterIndex]->borderData.Count(); i++) { int outerFaceIndex = clusterList[clusterIndex]->borderData[i].outerFace; int connectedClusterIndex = clusterGroups[outerFaceIndex]; if ((!processedClusters[connectedClusterIndex]) && (connectedClusterIndex != 0) && (connectedClusterIndex != -1)) { edgesToBeProcessed.Append(1,&clusterList[clusterIndex]->borderData[i]); } } } } } vsel.SetSize(TVMaps.v.Count()); vsel.ClearAll(); for (i = 0; i < clusterList.Count(); i++) { for (int j =0; j < clusterList[i]->faces.Count(); j++) { int faceIndex = clusterList[i]->faces[j]; for (int k =0; k < TVMaps.f[faceIndex]->count; k++) { int vertexIndex = TVMaps.f[faceIndex]->t[k]; vsel.Set(vertexIndex); } } } //now weld the verts if (normalize) { NormalizeCluster(); } float tempWeld = weldThreshold; weldThreshold = 0.001f; WeldSelected(FALSE); weldThreshold = tempWeld; } FreeClusterList(); if (bContinue) { theHold.Accept(_T(GetString(IDS_PW_PLANARMAP))); theHold.SuperAccept(_T(GetString(IDS_PW_PLANARMAP))); fnSelectPolygonsUpdate(&holdPolySel, FALSE); theHold.Suspend(); fnSyncTVSelection(); theHold.Resume(); } else { theHold.Cancel(); theHold.SuperCancel(); } RebuildEdges(); theHold.Suspend(); fnSyncGeomSelection(); theHold.Resume(); NotifyDependents(FOREVER,PART_SELECT,REFMSG_CHANGE); InvalidateView(); }
void BlobMesh::BuildMesh(TimeValue t) { //TODO: Implement the code to build the mesh representation of the object // using its parameter settings at the time passed. The plug-in should // use the data member mesh to store the built mesh. int numberOfNodes = pblock2->Count(pb_nodelist); float size, tension, renderCoarseness, viewCoarseness,coarseness; // Interval valid; pblock2->GetValue(pb_size,t,size,ivalid); pblock2->GetValue(pb_tension,t,tension,ivalid); if (tension < 0.011f) tension = 0.011f; if (tension > 1.0f) tension = 1.0f; pblock2->GetValue(pb_render,t,renderCoarseness,ivalid); pblock2->GetValue(pb_viewport,t,viewCoarseness,ivalid); BOOL autoCoarseness; pblock2->GetValue(pb_relativecoarseness,t,autoCoarseness,ivalid); BOOL largeDataSetOpt; pblock2->GetValue(pb_oldmetaballmethod,t,largeDataSetOpt,ivalid); BOOL useSoftSel; float minSize; pblock2->GetValue(pb_usesoftsel,t,useSoftSel,ivalid); pblock2->GetValue(pb_minsize,t,minSize,ivalid); if (inRender) coarseness = renderCoarseness; else coarseness = viewCoarseness; if (autoCoarseness) coarseness = size/coarseness; Tab<INode *> pfList; BOOL useAllPFEvents; pblock2->GetValue(pb_useallpf,0,useAllPFEvents,FOREVER); int pfCt = pblock2->Count(pb_pfeventlist); BOOL offInView; pblock2->GetValue(pb_offinview,0,offInView,FOREVER); for (int i = 0; i < pfCt; i++) { INode* node = NULL; pblock2->GetValue(pb_pfeventlist,0,node,FOREVER,i); if (node) pfList.Append(1,&node); } float thres = 0.6f; //need to get our tm if (selfNode == NULL) { MyEnumProc dep(true); DoEnumDependents(&dep); if (dep.Nodes.Count() > 0) selfNode = dep.Nodes[0]; } Matrix3 baseTM(1); if (selfNode != NULL) baseTM = Inverse(selfNode->GetObjectTM(t)); //loop throght the nodes if (!inRender) { if (offInView) numberOfNodes = 0; } std::vector<SphereData> data; data.reserve(500); for (int i = 0; i < numberOfNodes; i++) { INode* node = NULL; pblock2->GetValue(pb_nodelist,t,node,ivalid,i); if (node) { //get the nodes tm Matrix3 objectTM = node->GetObjectTM(t); Matrix3 toLocalSpace = objectTM*baseTM; ObjectState tos = node->EvalWorldState(t,TRUE); if (tos.obj->IsParticleSystem()) { SimpleParticle* pobj = NULL; IParticleObjectExt* epobj = NULL; pobj = static_cast<SimpleParticle*>( tos.obj->GetInterface(I_SIMPLEPARTICLEOBJ) ); if (pobj) { pobj->UpdateParticles(t, node); int count = pobj->parts.Count(); data.reserve(data.size() + count); float closest = 999999999.9f; SphereData d; for (int pid = 0; pid < count; pid++) { TimeValue age = pobj->ParticleAge(t,pid); TimeValue life = pobj->ParticleLife(t,pid); if (age != -1) { float psize = pobj->ParticleSize(t,pid); Point3 curval = pobj->parts.points[pid]; d.center = curval * baseTM; d.radius = psize; d.oradius = psize; d.rsquare = psize * psize; d.tover4 = tension * d.rsquare *d.rsquare ; data.push_back(d); } } } else { epobj = (IParticleObjectExt*) tos.obj->GetInterface(PARTICLEOBJECTEXT_INTERFACE); if (epobj) { epobj->UpdateParticles(node, t); int count = epobj->NumParticles(); data.reserve(data.size() + count); for (int pid = 0; pid < count; pid++) { TimeValue age = epobj->GetParticleAgeByIndex(pid); if (age!=-1) { INode *node = epobj->GetParticleGroup(pid); Point3 *curval = epobj->GetParticlePositionByIndex(pid); BOOL useParticle = TRUE; if (!useAllPFEvents) { useParticle = FALSE; for (int k = 0; k < pfList.Count(); k++) { if (node == pfList[k]) { useParticle = TRUE; k = pfList.Count(); } } } if ((curval) && (useParticle)) { float scale = epobj->GetParticleScaleByIndex(pid) ; float psize = scale; SphereData d; d.center = *curval*baseTM; d.radius = psize; d.oradius = psize; d.rsquare = psize * psize; d.tover4 = tension * d.rsquare *d.rsquare ; data.push_back(d); } } } } } } else if (tos.obj->IsShapeObject()) { PolyShape shape; ShapeObject *pathOb = (ShapeObject*)tos.obj; pathOb->MakePolyShape(t, shape); // first find out how many points there are: size_t num_points = 0; for (int i = 0; i < shape.numLines; i++) { PolyLine& line = shape.lines[i]; num_points += line.numPts; } data.reserve(data.size() + num_points); for (int i = 0; i < shape.numLines; i++) { PolyLine line = shape.lines[i]; for (int j = 0; j < line.numPts; j++) { SphereData d; float tsize = size; d.center = line.pts[j].p*toLocalSpace; d.radius = tsize; d.oradius = tsize; d.rsquare = tsize * tsize; d.tover4 = tension * d.rsquare *d.rsquare ; data.push_back(d); } } } else if (tos.obj->SuperClassID()==GEOMOBJECT_CLASS_ID) { SphereData d; BOOL converted = FALSE; TriObject *triObj = NULL; if(tos.obj->IsSubClassOf(triObjectClassID)) { triObj = (TriObject *)tos.obj; } // If it can convert to a TriObject, do it else if(tos.obj->CanConvertToType(triObjectClassID)) { triObj = (TriObject *)tos.obj->ConvertToType(t, triObjectClassID); converted = TRUE; } if (triObj != NULL) { Mesh* mesh = &triObj->GetMesh(); if (mesh) { int vcount = mesh->getNumVerts(); float *vsw = mesh->getVSelectionWeights (); BitArray vsel = mesh->VertSel(); data.reserve(data.size() + vcount); for (int j = 0; j < vcount; j++) { float tsize = size; if (useSoftSel) { tsize = 0.0f; if (vsw) { float v = 0.0f; if (vsel[j]) v = 1.0f; else { if (vsw) v = vsw[j]; } if (v == 0.0f) tsize = 0.0f; else { tsize = minSize + (size -minSize)*v; } } else { float v = 0.0f; if (vsel[j]) v = 1.0f; tsize = minSize + (size -minSize)*v; } } if (tsize != 0.0f) { d.center = mesh->getVert(j)*toLocalSpace; d.radius = tsize; d.oradius = tsize; d.rsquare = tsize * tsize; d.tover4 = tension * d.rsquare *d.rsquare ; data.push_back(d); } } } if (converted) triObj->DeleteThis(); } } else { SphereData d; d.center = Point3(0.0f,0.0f,0.0f)*toLocalSpace; d.radius = size; d.oradius = size; d.rsquare = size * size; d.tover4 = tension * d.rsquare *d.rsquare ; data.push_back(d); } } } if ((data.size() == 0) && (numberOfNodes==0)) { data.resize(1); data[0].center = Point3(0.0f,0.0f,0.0f); data[0].radius = size; data[0].oradius = size; data[0].rsquare = size * size; data[0].tover4 = tension * data[0].rsquare *data[0].rsquare ; } if (data.size() > 0) { int iRes = 1; if (!largeDataSetOpt) { MetaParticle oldBlob; iRes = oldBlob.CreatePodMetas(&data[0],(int)data.size(),&mesh,thres,coarseness); } else { MetaParticleFast blob; iRes = blob.CreatePodMetas(&data[0],(int)data.size(),&mesh,thres,coarseness); } // An out of memory error is the only reason iRes would be zero in either case if( (iRes == 0) && GetCOREInterface() ) GetCOREInterface()->DisplayTempPrompt(GetString(IDS_NOT_ENOUGH_MEM), 5000 ); } else { mesh.setNumFaces(0); mesh.setNumVerts(0); } mesh.InvalidateTopologyCache(); ivalid.Set(t,t); }
void TVConnectionInfo::OrderLists() { int hiddenVertID = -1; for (int i = 0; i < mVertex.Count(); i++) { if (mVertex[i]->mConnectedFaces.Count() > 0) { // DumpVert(i); //order our faces Tab<int> faceStack; Tab<int> finalFaceStack; Tab<int> remainingFaces = mVertex[i]->mConnectedFaces; faceStack.Append(1,&remainingFaces[0]); remainingFaces.Delete(0,1); int vert = i; //gather all the faces that are together and ordered them while (remainingFaces.Count() > 0) { int currentFace = faceStack[0]; int prevVert = -1; int nextVert = -1; int deg = mMd->GetFaceDegree(currentFace); for (int j = 0; j < deg; j++) { int a = mMd->GetFaceTVVert(currentFace,j); if (a == vert) { nextVert = mMd->GetFaceTVVert(currentFace,(j+1)%deg); prevVert = mMd->GetFaceTVVert(currentFace,(j+deg-1)%deg); j = deg; } } int hit = FALSE; for (int j = 0; j < remainingFaces.Count(); j++) { int faceIndex = remainingFaces[j]; //see if we have any matching faces int ithEdge = mMd->FindUVEdge(faceIndex,vert,nextVert); if (ithEdge != -1) //we have a match { faceStack.Append(1,&faceIndex,8); remainingFaces.Delete(j,1); j = -1; hit = TRUE; //find the new nextvert int deg = mMd->GetFaceDegree(faceIndex); for (int k = 0; k < deg; k++) { int a = mMd->GetFaceTVVert(faceIndex,k); if (a == vert) { nextVert = mMd->GetFaceTVVert(faceIndex,(k+1)%deg); k = deg; } } } else { ithEdge = mMd->FindUVEdge(faceIndex,vert,prevVert); if (ithEdge != -1) //we have a match { faceStack.Insert(0,1,&faceIndex); remainingFaces.Delete(j,1); j = -1; hit = TRUE; //find the new prevvert int deg = mMd->GetFaceDegree(faceIndex); for (int k = 0; k < deg; k++) { int a = mMd->GetFaceTVVert(faceIndex,k); if (a == vert) { prevVert = mMd->GetFaceTVVert(faceIndex,(k+deg-1)%deg); k = deg; } } } } } //see if we hit an open edge if so add all the faces we have and add a -1 to mark the gap int remainingFacesCount = remainingFaces.Count(); if (hit == FALSE || (remainingFacesCount == 0)) { for (int j = 0; j < faceStack.Count(); j++) finalFaceStack.Append(1,&faceStack[j],8); int neg = -1; if (remainingFaces.Count() != 0) finalFaceStack.Append(1,&neg); if (remainingFaces.Count() > 0) { faceStack.SetCount(0); faceStack.Append(1,&remainingFaces[0],8); remainingFaces.Delete(0,1); } } } //special condition with 1 face if (mVertex[i]->mConnectedFaces.Count() == 1) { int neg = -1; finalFaceStack = mVertex[i]->mConnectedFaces; finalFaceStack.Append(1,&neg); } //else see if the last and end faces dont connect and if mark it with -1 else if (mVertex[i]->mConnectedFaces.Count() > 1) { int firstFace = finalFaceStack[0]; int lastFace = finalFaceStack[finalFaceStack.Count()-1]; int pVert = -1; int nVert = -1; if ((firstFace != -1) && (lastFace != -1)) { int deg = mMd->GetFaceDegree(firstFace); for (int j = 0; j < deg; j++) { int a = mMd->GetFaceTVVert(firstFace,j); if (a == vert) { pVert = mMd->GetFaceTVVert(firstFace,(j+deg-1)%deg); j = deg; } } deg = mMd->GetFaceDegree(lastFace); for (int j = 0; j < deg; j++) { int a = mMd->GetFaceTVVert(lastFace,j); if (a == vert) { nVert = mMd->GetFaceTVVert(lastFace,(j+1)%deg); j = deg; } } } //there is a gap add a neg -1 to signify this if (nVert != pVert) { int neg = -1; finalFaceStack.Append(1,&neg); } } /* DebugPrint (" unordered face list "); for (int j = 0; j < mVertex[i]->mConnectedFaces.Count(); j++) { DebugPrint(_T(" %d"),mVertex[i]->mConnectedFaces[j]); } DebugPrint (_T("\n")); */ mVertex[i]->mConnectedFaces = finalFaceStack; /* DebugPrint (" ordered face list "); for (int j = 0; j < mVertex[i]->mConnectedFaces.Count(); j++) { DebugPrint(_T(" %d"),mVertex[i]->mConnectedFaces[j]); } DebugPrint (_T("\n")); */ //now order the edges //just a temp list to store the verts as we sort them Tab<VertexConnectedTo> sortedtVerts; if (mVertex[i]->mConnectedFaces.Count() == 2) //special case for corners since they have both the same face IDs { int faceIndex1 = mVertex[i]->mConnectedFaces[0]; if (faceIndex1 == -1) faceIndex1 = mVertex[i]->mConnectedFaces[1]; int prevVert = -1; int nextVert = -1; int deg = mMd->GetFaceDegree(faceIndex1); for (int j = 0; j < deg; j++) { int a = mMd->GetFaceTVVert(faceIndex1,j); if (a == vert) { nextVert = mMd->GetFaceTVVert(faceIndex1,(j+1)%deg); prevVert = mMd->GetFaceTVVert(faceIndex1,(j+deg-1)%deg); j = deg; } } //see if we need to swap edge order if (mVertex[i]->mConnectedTo[0].mVert == nextVert) { sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[1],8); sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[0],8); } else { sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[0],8); sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[1],8); } VertexConnectedTo data(hiddenVertID--,-1,0,-1,-1,FALSE); sortedtVerts.Append(1,&data,8); } else { int currentEdge = 0; //we can just walk around looking for matching faces at the edge for (int faceIndex = 0; faceIndex < mVertex[i]->mConnectedFaces.Count(); faceIndex++) { int fa = finalFaceStack[faceIndex]; int fb = finalFaceStack[(faceIndex+1)%mVertex[i]->mConnectedFaces.Count()]; //make sure to add the gap if there is no face if (fa == -1) { VertexConnectedTo data(hiddenVertID--,-1,0,-1,-1,FALSE); sortedtVerts.Append(1,&data,8); //open edges are not hidden since we want to count them for purpuses of rings and loops currentEdge++; } //find a matching edge for (int k = 0; k < mVertex[i]->mConnectedTo.Count(); k++) { int testa = mVertex[i]->mConnectedTo[k].mFace[0]; int testb = mVertex[i]->mConnectedTo[k].mFace[1]; if ( ((testa == fa) && (testb == fb)) || ((testa == fb) && (testb == fa)) ) { sortedtVerts.Append(1,&mVertex[i]->mConnectedTo[k],8); // sortedtVerts[currentEdge] = mVertex[i]->mConnectedTo[k]; currentEdge++; k = mVertex[i]->mConnectedTo.Count(); } } } } /* DebugPrint (" unordered edge list "); for (int j = 0; j < mVertex[i]->mConnectedTo.Count(); j++) { DebugPrint(_T(" %d"),mVertex[i]->mConnectedTo[j].mVert); } DebugPrint (_T("\n")); */ mVertex[i]->mConnectedTo = sortedtVerts; /* DebugPrint (" ordered edge list "); for (int j = 0; j < mVertex[i]->mConnectedTo.Count(); j++) { DebugPrint(_T(" %d"),mVertex[i]->mConnectedTo[j].mVert); } DebugPrint (_T("\n")); */ int ct = mVertex[i]->mConnectedTo.Count(); for (int j = 0; j < ct; j++) { if (mVertex[i]->mConnectedTo[j].mHiddenEdge) mVertex[i]->mHiddenEdgeCount++; else mVertex[i]->mVisibleEdgeCount++; } } } //build our opposing edges now for (int i = 0; i < mVertex.Count(); i++) { Vertex *v = mVertex[i]; v->mNumRealEdges = 0; int deg = v->mConnectedTo.Count(); for (int j = 0; j < deg; j++) { if ( (v->mConnectedTo[j].mVert >= 0) && (v->mConnectedTo[j].mHiddenEdge == FALSE) ) v->mNumRealEdges++; } if (v->mNumRealEdges == 3) { int center = -1; for (int j = 0; j < deg; j++) { if (v->mConnectedTo[j].mVert < 0) center = j; } bool done = false; int prevIth = center; int nextIth = center; int nIndex = -1; int pIndex = -1; while (!done) { nextIth++; prevIth--; nextIth = (nextIth+deg)%deg; prevIth = (prevIth+deg)%deg; if ((v->mConnectedTo[nextIth].mVert >= 0) && (v->mConnectedTo[nextIth].mHiddenEdge == FALSE) ) { if (nIndex == -1) nIndex = nextIth; } if ((v->mConnectedTo[prevIth].mVert >= 0) && (v->mConnectedTo[prevIth].mHiddenEdge == FALSE) ) { if (pIndex == -1) pIndex = prevIth; } if ((pIndex != -1) && (nIndex != -1)) done = true; } //find our -1 edge go left and right of it til hit a real edge v->mConnectedTo[pIndex].mIthOpposingEdge = nIndex; v->mConnectedTo[nIndex].mIthOpposingEdge = pIndex; } else if (v->mNumRealEdges > 3) { BOOL valid = FALSE; if ((v->mNumRealEdges%2) == 0) valid = TRUE; if (valid) { int halfIth = v->mNumRealEdges/2; for (int j = 0; j < deg; j++) { int startIndex = j; BOOL isEdgeHidden = v->mConnectedTo[startIndex].mHiddenEdge; if ( (v->mConnectedTo[startIndex].mVert < 0) || isEdgeHidden ) v->mConnectedTo[j].mIthOpposingEdge = -1; else { int ct = 0; while (ct != halfIth) { startIndex++; if (startIndex >= deg) startIndex = 0; if ( (v->mConnectedTo[startIndex].mVert >= 0) && (v->mConnectedTo[startIndex].mHiddenEdge == FALSE) ) ct++; } v->mConnectedTo[j].mIthOpposingEdge = startIndex; } } } else for (int j = 0; j < deg; j++) v->mConnectedTo[j].mIthOpposingEdge = -1; } // DumpVert(i); } }
//pelt void UVW_ChannelClass::EdgeListFromPoints(Tab<int> &selEdges, int source, int target, Point3 vec) { //make sure point a and b are on the same element if not bail Tab<VConnections*> ourConnects; BOOL del = FALSE; BitArray selVerts; selVerts.SetSize(geomPoints.Count()); selVerts.ClearAll(); // if (TRUE) //loop through the edges Tab<int> numberOfConnections; numberOfConnections.SetCount(geomPoints.Count()); for (int i = 0; i < geomPoints.Count(); i++) { numberOfConnections[i] = 0; } //count the number of vertxs connected for (int i = 0; i < gePtrList.Count(); i++) { if (!(gePtrList[i]->flags & FLAG_HIDDENEDGEA)) { int a = gePtrList[i]->a; numberOfConnections[a] +=1; int b = gePtrList[i]->b; numberOfConnections[b] +=1; } } //allocate our connections now ourConnects.SetCount(geomPoints.Count()); for (int i = 0; i < geomPoints.Count(); i++) { ourConnects[i] = new VConnections(); ourConnects[i]->closestNode = NULL; ourConnects[i]->linkedListChild = NULL; ourConnects[i]->linkedListParent = NULL; ourConnects[i]->accumDist = 1.0e+9f; ourConnects[i]->solved = FALSE; ourConnects[i]->vid = i; ourConnects[i]->connectingVerts.SetCount(numberOfConnections[i]); } for (int i = 0; i < geomPoints.Count(); i++) { numberOfConnections[i] = 0; } //build our vconnection data for (int i = 0; i < gePtrList.Count(); i++) { if (!(gePtrList[i]->flags & FLAG_HIDDENEDGEA)) { int a = gePtrList[i]->a; int b = gePtrList[i]->b; int index = numberOfConnections[a]; ourConnects[a]->connectingVerts[index].vertexIndex = b; ourConnects[a]->connectingVerts[index].edgeIndex = i; numberOfConnections[a] +=1; index = numberOfConnections[b]; ourConnects[b]->connectingVerts[index].vertexIndex = a; ourConnects[b]->connectingVerts[index].edgeIndex = i; numberOfConnections[b] +=1; } } del = TRUE; // else ourConnects = vConnects; //spider out till hit our target or no more left BOOL done = FALSE; BOOL hit = FALSE; Tab<int> vertsToDo; BitArray processedVerts; processedVerts.SetSize(ourConnects.Count()); processedVerts.ClearAll(); //if no more left bail int currentVert = source; while (!done) { // int startingNumberProcessed = processedVerts.NumberSet(); int ct = ourConnects[currentVert]->connectingVerts.Count(); processedVerts.Set(currentVert, TRUE); for (int j = 0; j < ct; j++) { int index = ourConnects[currentVert]->connectingVerts[j].vertexIndex; if (index == target) { done = TRUE; hit = TRUE; } if (!processedVerts[index]) vertsToDo.Append(1,&index, 10000); } if (vertsToDo.Count()) { currentVert = vertsToDo[vertsToDo.Count()-1]; vertsToDo.Delete(vertsToDo.Count()-1,1); } if (vertsToDo.Count() == 0) done = TRUE; // int endingNumberProcessed = processedVerts.NumberSet(); if (currentVert == target) { done = TRUE; hit = TRUE; } // if (startingNumberProcessed == endingNumberProcessed) // done = TRUE; } vertsToDo.ZeroCount(); if (hit) { Tab<VConnections*> solvedNodes; ourConnects[source]->accumDist = 0; VConnections* unsolvedNodeHead = ourConnects[source]; VConnections* unsolvedNodeCurrent = unsolvedNodeHead; //put all our vertices in the unsolved list for (int i = 0; i < ourConnects.Count(); i++) { if (ourConnects[i] != unsolvedNodeHead) { unsolvedNodeCurrent->linkedListChild = ourConnects[i]; VConnections *parent = unsolvedNodeCurrent; unsolvedNodeCurrent = ourConnects[i]; unsolvedNodeCurrent->linkedListParent = parent; } } //build our edge distances Tab<float> edgeDistances; edgeDistances.SetCount(gePtrList.Count()); for (int i = 0 ; i < gePtrList.Count(); i++) { int a = gePtrList[i]->a; int b = gePtrList[i]->b; float d = Length(geomPoints[a] - geomPoints[b]); edgeDistances[i] = d; } BOOL done = FALSE; while (!done) { //pop the top unsolved VConnections *top = unsolvedNodeHead; unsolvedNodeHead = unsolvedNodeHead->linkedListChild; top->linkedListChild = NULL; top->linkedListParent = NULL; if (unsolvedNodeHead != NULL) { unsolvedNodeHead->linkedListParent = NULL; //mark it as processed top->solved = TRUE; //put it in our solved list solvedNodes.Append(1,&top,5000); int neighborCount = top->connectingVerts.Count(); //loop through the neighbors for (int i = 0; i < neighborCount; i++) { int index = top->connectingVerts[i].vertexIndex; int eindex = top->connectingVerts[i].edgeIndex; VConnections *neighbor = ourConnects[index]; //make sure it is not procssedd if (!neighbor->solved) { //find the distance from the top to this neighbor float d = neighbor->accumDist; float testAccumDistance = top->accumDist + edgeDistances[eindex]; //see if it accum dist needs to be relaxed if (testAccumDistance<d) { float originalDist = neighbor->accumDist; neighbor->accumDist = testAccumDistance; neighbor->closestNode = top; //sort this node float dist = neighbor->accumDist; if (originalDist == 1.0e+9f) { //start at the top and look down VConnections *currentNode = unsolvedNodeHead; if (neighbor == currentNode) { currentNode = currentNode->linkedListChild; unsolvedNodeHead = currentNode; } VConnections *prevNode = NULL; //unhook node VConnections *parent = neighbor->linkedListParent; VConnections *child = neighbor->linkedListChild; if (parent) parent->linkedListChild = child; if (child) child->linkedListParent = parent; while ((currentNode!= NULL) && (currentNode->accumDist < dist)) { prevNode = currentNode; currentNode = currentNode->linkedListChild; SHORT iret = GetAsyncKeyState (VK_ESCAPE); if (iret==-32767) { done = TRUE; currentNode= NULL; } } //empty list if ((prevNode==NULL) && (currentNode== NULL)) { neighbor->linkedListChild = NULL; neighbor->linkedListParent = NULL; unsolvedNodeHead = neighbor; } //at top else if (currentNode && (prevNode == NULL)) { unsolvedNodeHead->linkedListParent = neighbor; neighbor->linkedListParent = NULL; neighbor->linkedListChild =unsolvedNodeHead; unsolvedNodeHead = neighbor; } //at bottom else if (currentNode == NULL) { prevNode->linkedListChild = neighbor; neighbor->linkedListParent = currentNode; neighbor->linkedListChild = NULL; } else if (currentNode) { //insert VConnections *parent = currentNode->linkedListParent; VConnections *child = currentNode; parent->linkedListChild = neighbor; child->linkedListParent = neighbor; neighbor->linkedListParent = parent; neighbor->linkedListChild = child; } } else { //sort smallest to largest BOOL moveUp = FALSE; if (neighbor->linkedListParent && neighbor->linkedListChild) { float parentDist = neighbor->linkedListParent->accumDist; float childDist = neighbor->linkedListChild->accumDist; //walkup up or down the list till find a spot an unlink and relink if ((dist >= parentDist) && (dist <= childDist)) { //done dont need to move } else if (dist < parentDist) moveUp = FALSE; } else if (neighbor->linkedListParent && (neighbor->linkedListChild==NULL)) { moveUp = TRUE; } else if ((neighbor->linkedListParent==NULL) && (neighbor->linkedListChild)) { moveUp = FALSE; } //unlink the node //unhook node VConnections *parent = neighbor->linkedListParent; VConnections *child = neighbor->linkedListChild; if (parent) parent->linkedListChild = child; else unsolvedNodeHead = child; if (child) child->linkedListParent = parent; VConnections *currentNode = NULL; if (moveUp) currentNode = neighbor->linkedListParent; else currentNode = neighbor->linkedListChild; VConnections *prevNode = NULL; while ((currentNode!= NULL) && (currentNode->accumDist < dist)) { prevNode = currentNode; if (moveUp) currentNode = currentNode->linkedListParent; else currentNode = currentNode->linkedListChild; SHORT iret = GetAsyncKeyState (VK_ESCAPE); if (iret==-32767) { done = TRUE; currentNode= NULL; } } //empty list if ((prevNode==NULL) && (currentNode== NULL)) { neighbor->linkedListChild = NULL; neighbor->linkedListParent = NULL; unsolvedNodeHead = neighbor; } //at top else if (currentNode && (prevNode == NULL)) { unsolvedNodeHead->linkedListParent = neighbor; neighbor->linkedListParent = NULL; neighbor->linkedListChild =unsolvedNodeHead; unsolvedNodeHead = neighbor; } //at bottom else if (currentNode == NULL) { prevNode->linkedListChild = neighbor; neighbor->linkedListParent = currentNode; neighbor->linkedListChild = NULL; } else if (currentNode) { //insert VConnections *parent = currentNode->linkedListParent; VConnections *child = currentNode; parent->linkedListChild = neighbor; child->linkedListParent = neighbor; neighbor->linkedListParent = parent; neighbor->linkedListChild = child; } } } } } } if (unsolvedNodeHead == NULL) done = TRUE; if ((solvedNodes[solvedNodes.Count()-1]) == ourConnects[target]) done = TRUE; } //now get our edge list selEdges.ZeroCount(); VConnections *cNode = ourConnects[target]; while ((cNode->closestNode != NULL) && (cNode != ourConnects[source])) { VConnections *pNode = cNode->closestNode; int ct = cNode->connectingVerts.Count(); int edgeIndex = -1; for (int i = 0; i < ct; i++) { int vindex = cNode->connectingVerts[i].vertexIndex; int eindex = cNode->connectingVerts[i].edgeIndex; if (ourConnects[vindex] == pNode) { edgeIndex = eindex; i = ct; } } if (edgeIndex != -1) selEdges.Append(1,&edgeIndex,500); cNode = pNode; } } if (del) { for (int i = 0; i < geomPoints.Count(); i++) { delete ourConnects[i]; } } }
void RenderMesh::ConvertFaces(Mesh *Mesh, int MatIndex, Tab<Vert3> &Verts, Tab<Face3> &Faces, bool NegScale) { Face3 TmpFace; Vert3 TmpVert; BitArray Written; int i,j,k,NumFace; int NumUV,UVCount,Index; int NumVert,Count,VIndex; Face *aFace; Tab<BasisVert> FNormals; Tab<VNormal> Normals; UVVert *UVVert; TVFace *UVFace; Point3 S,T,SxT; unsigned long Sg; bool useMeshNorms = false; if(NegScale) { gVIndex[0] = 2; gVIndex[1] = 1; gVIndex[2] = 0; } else { gVIndex[0] = 0; gVIndex[1] = 1; gVIndex[2] = 2; } // Do we have an EditNormal modifier present - if so we use those normals instead. // We only use this if they have been applied on a face with smoothing groups, otherwise // it messes up the tangent space calculation. Probably not the most obtmized route, but it // works... MeshNormalSpec * meshNorm = Mesh->GetSpecifiedNormals(); if(meshNorm && meshNorm->GetNumNormals()) useMeshNorms = true; NumFace = 0; for(i=0; i < Mesh->getNumFaces(); i++) { if(!Mesh->faces[i].Hidden()) { Index = Mesh->getFaceMtlIndex(i) + 1; if(Index == MatIndex || MatIndex == 0) { NumFace++; } } } NumVert = Mesh->getNumVerts(); Verts.SetCount(NumVert); Faces.SetCount(NumFace); if(NumVert == 0 || NumFace == 0) { return; } ComputeVertexNormals(Mesh,FNormals,Normals,NegScale); Written.SetSize(Mesh->getNumVerts()); Written.ClearAll(); NumUV = Mesh->getNumMaps(); if(NumUV) { Count = 0; if(NumUV > MAX_TMUS + 1) { NumUV = MAX_TMUS + 1; } for(i=0; i < Mesh->getNumFaces(); i++) { aFace = &Mesh->faces[i]; TmpFace.m_Num[0] = aFace->v[gVIndex[0]]; TmpFace.m_Num[1] = aFace->v[gVIndex[1]]; TmpFace.m_Num[2] = aFace->v[gVIndex[2]]; Sg = aFace->smGroup; for(j=0; j < 3; j++) { VIndex = aFace->v[gVIndex[j]]; TmpVert.m_Pos = Mesh->verts[VIndex]; if(Sg) { if(useMeshNorms) { int normID = meshNorm->Face(i).GetNormalID(gVIndex[j]); TmpVert.m_Normal = meshNorm->Normal(normID).Normalize(); Normals[VIndex].GetNormal(Sg,S,T,SxT); } else TmpVert.m_Normal = Normals[VIndex].GetNormal(Sg,S,T,SxT); TmpVert.m_S = S; TmpVert.m_T = T; TmpVert.m_SxT = SxT; } else { TmpVert.m_Normal = FNormals[i].m_Normal; TmpVert.m_S = FNormals[i].m_S; TmpVert.m_T = FNormals[i].m_T; TmpVert.m_SxT = FNormals[i].m_SxT; } UVCount = 0; TmpVert.m_Sg = Sg; for(k=0;k<m_MapChannels.Count();k++) { int index = m_MapChannels[k]; if(Mesh->getNumMapVerts(index)) { UVVert = Mesh->mapVerts(index); UVFace = Mesh->mapFaces(index); TmpVert.m_UV[k].x = UVVert[UVFace[i].t[gVIndex[j]]].x; TmpVert.m_UV[k].y = UVVert[UVFace[i].t[gVIndex[j]]].y; } else { TmpVert.m_UV[k].x = 0.0f; TmpVert.m_UV[k].y = 0.0f; } } if(Written[VIndex]) { if((Sg == 0) || (Verts[VIndex].m_Sg != TmpVert.m_Sg) || (!UVVertEqual(Verts[VIndex].m_UV[0],TmpVert.m_UV[0]))) { TmpFace.m_Num[j] = Verts.Count(); Verts.Append(1,&TmpVert,10); } } else { Verts[VIndex] = TmpVert; Written.Set(VIndex); } } if(!Mesh->faces[i].Hidden()) { Index = Mesh->getFaceMtlIndex(i) + 1; if(Index == MatIndex || MatIndex == 0) { Faces[Count++] = TmpFace; } } } } else { for(i=0; i < Mesh->getNumFaces(); i++) { aFace = &Mesh->faces[i]; Faces[i].m_Num[0] = aFace->v[gVIndex[0]]; Faces[i].m_Num[1] = aFace->v[gVIndex[1]]; Faces[i].m_Num[2] = aFace->v[gVIndex[2]]; for(j=0; j < 3; j++) { VIndex = aFace->v[gVIndex[j]]; Verts[VIndex].m_Pos = Mesh->verts[VIndex]; Verts[VIndex].m_Normal = Normals[VIndex].GetNormal(aFace->smGroup,S,T,SxT); Verts[VIndex].m_S = Point3(0.0f,0.0f,0.0f); Verts[VIndex].m_T = Point3(0.0f,0.0f,0.0f); Verts[VIndex].m_SxT = Point3(0.0f,0.0f,0.0f); for(k=0; k < MAX_TMUS; k++) { Verts[VIndex].m_UV[k].x = 0.0f; Verts[VIndex].m_UV[k].y = 0.0f; } } } } Verts.Shrink(); }
void ParticleMesherObject::PickPFEvents(HWND hWnd) { Tab<INode *> pfEvents; int numberOfNodes = 1;; TimeValue t = GetCOREInterface()->GetTime(); pfNodes.ZeroCount(); addPFNodes.ZeroCount(); for (int i = 0; i < numberOfNodes; i++) { INode *node; pblock2->GetValue(particlemesher_pick,t,node,ivalid,i); if (node) { ObjectState tos = node->EvalWorldState(t,TRUE); if (tos.obj->IsParticleSystem()) { IParticleObjectExt* epobj; epobj = (IParticleObjectExt*) tos.obj->GetInterface(PARTICLEOBJECTEXT_INTERFACE); if (epobj) { MyEnumProc dep; tos.obj->DoEnumDependents(&dep); for (int i = 0; i < dep.Nodes.Count(); i++) { Interval valid; INode *node = dep.Nodes[i]; Object *obj = node->GetObjectRef(); IParticleGroup* iPGroup = ParticleGroupInterface(obj); if (iPGroup != nullptr) { // we need to filter out the global action list events since // they do not carry any actual particle shape geometry if (iPGroup->GetParticleSystem() != iPGroup->GetActionList()) { pfNodes.Append(1, &node); } } } } } } } if (pfNodes.Count() > 0) { int iret = DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_ADD_DIALOG), hWnd,AddDlgProc,(LPARAM)this); if ((iret) && (addPFNodes.Count() > 0)) { theHold.Begin(); for (int i = 0; i < addPFNodes.Count(); i++) { int index = addPFNodes[i]; INode *node = pfNodes[index]; pblock2->Append(particlemesher_pfeventlist,1,&node); } theHold.Accept(GetString(IDS_ADDEVENTS)); } } }
bool NifImporter::ImportSkin(ImpNode *node, NiTriBasedGeomRef triGeom, int v_start/*=0*/) { bool ok = true; NiSkinInstanceRef nifSkin = triGeom->GetSkinInstance(); if (!nifSkin) return false; INode *tnode = node->GetINode(); NiSkinDataRef data = nifSkin->GetSkinData(); NiSkinPartitionRef part = nifSkin->GetSkinPartition(); vector<NiNodeRef> nifBones = nifSkin->GetBones(); //create a skin modifier and add it Modifier *skinMod = GetOrCreateSkin(tnode); TriObject *triObject = GetTriObject(tnode->GetObjectRef()); Mesh& m = triObject->GetMesh(); //get the skin interface if (ISkin *skin = (ISkin *) skinMod->GetInterface(I_SKIN)){ ISkinImportData* iskinImport = (ISkinImportData*) skinMod->GetInterface(I_SKINIMPORTDATA); // Set the num weights to 4. Yes its in the nif but Shon doesn't like to expose those values // and the value always seems to be 4 anyway. I'd also this be more dynamic than hard coded numbers // but I cant figure out the correct values to pass the scripting engine from here so I'm giving up. int numWeightsPerVertex = 4; #if VERSION_3DSMAX >= ((5000<<16)+(15<<8)+0) // Version 5+ IParamBlock2 *params = skinMod->GetParamBlockByID(2/*advanced*/); params->SetValue(0x7/*bone_Limit*/, 0, numWeightsPerVertex); #endif // Can get some truly bizarre animations without this in MAX with Civ4 Leaderheads #if VERSION_3DSMAX > ((5000<<16)+(15<<8)+0) // Version 6+ BOOL ignore = TRUE; params->SetValue(0xE/*ignoreBoneScale*/, 0, ignore); #endif //RefTargetHandle advanced = skinMod->GetReference(3); //setMAXScriptValue(advanced, "bone_Limit", 0, numWeightsPerVertex); Matrix3 geom = TOMATRIX3(triGeom->GetLocalTransform()); Matrix3 m3 = TOMATRIX3(data->GetOverallTransform()); Matrix3 im3 = Inverse(m3); Matrix3 nm3 = im3 * geom; iskinImport->SetSkinTm(tnode, nm3, nm3); // ??? // Create Bone List Tab<INode*> bones; for (size_t i=0; i<nifBones.size(); ++i){ NiNodeRef bone = nifBones[i]; if (INode *boneRef = FindNode(bone)) { bones.Append(1, &boneRef); iskinImport->AddBoneEx(boneRef, TRUE); //// Set Bone Transform Matrix3 b3 = TOMATRIX3(data->GetBoneTransform(i)); Matrix3 ib3 = Inverse(b3); ib3 *= geom; iskinImport->SetBoneTm(boneRef, ib3, ib3); } } if (bones.Count() != data->GetBoneCount()) return false; ObjectState os = tnode->EvalWorldState(0); // Need to get a list of bones and weights for each vertex. vector<VertexHolder> vertexHolders; vertexHolders.resize(m.numVerts); for (int i=0, n=data->GetBoneCount();i<n; ++i){ if (INode *boneRef = bones[i]){ vector<SkinWeight> weights = data->GetBoneWeights(i); for (vector<SkinWeight>::iterator itr=weights.begin(), end=weights.end(); itr != end; ++itr){ VertexHolder& h = vertexHolders[itr->index]; h.vertIndex = itr->index; ++h.count; h.weights.Append(1, &itr->weight); h.boneNodeList.Append(1, &boneRef); } } } tnode->EvalWorldState(0); skinMod->DisableModInViews(); skinMod->EnableModInViews(); #if VERSION_3DSMAX < ((5000<<16)+(15<<8)+0) // Version 4 gi->SetCommandPanelTaskMode(TASK_MODE_MODIFY); gi->SelectNode(tnode); #endif // Assign the weights for (vector<VertexHolder>::iterator itr=vertexHolders.begin(), end=vertexHolders.end(); itr != end; ++itr){ VertexHolder& h = (*itr); if (h.count){ float sum = 0.0f; for (int i = 0; i < h.count; ++i) sum += h.weights[i]; ASSERT(fabs(sum-1.0f) < 0.001f); BOOL add = iskinImport->AddWeights(tnode, h.vertIndex, h.boneNodeList, h.weights); add = add; // What was the purpose of this? } } // This is a kludge to get skin transforms to update and avoid jumping around after modifying the transforms. // Initially they show up incorrectly but magically fix up if you go to the modifier roll up. // There is still an outstanding issue with skeleton and GetObjectTMBeforeWSM. skinMod->DisableModInViews(); skinMod->EnableModInViews(); // If BSDismembermentSkinInstance, ... if ( BSDismemberSkinInstanceRef bsdsi = DynamicCast<BSDismemberSkinInstance>(nifSkin) ) { Modifier *dismemberSkinMod = GetOrCreateBSDismemberSkin(tnode); if (IBSDismemberSkinModifier *disSkin = (IBSDismemberSkinModifier *) dismemberSkinMod->GetInterface(I_BSDISMEMBERSKINMODIFIER)){ // Evaluate node ensure the modifier data is created // ObjectState os = tnode->EvalWorldState(0); FaceMap faceMap; int nfaces = m.getNumFaces(); for ( int i=0; i<nfaces; ++i ){ Face f = m.faces[i]; faceMap[ rotate(f) ] = i; } Tab<IBSDismemberSkinModifierData*> modData = disSkin->GetModifierData(); for (int i=0; i<modData.Count(); ++i) { IBSDismemberSkinModifierData* bsdsmd = modData[i]; Tab<BSDSPartitionData> &flags = bsdsmd->GetPartitionFlags(); vector<BodyPartList> partitions = bsdsi->GetPartitions(); if (partitions.empty()) continue; //bsdsmd->SetActivePartition( partitions.size() - 1 ); // Old Code for (unsigned int j = 0; j < (partitions.size() - 1); ++j){ bsdsmd->AddPartition(); } for (unsigned int j=0; j < partitions.size(); ++j ) { flags[j].bodyPart = (DismemberBodyPartType)partitions[j].bodyPart; flags[j].partFlag = partitions[j].partFlag; } for (int j=0; j < part->GetNumPartitions(); ++j) { bsdsmd->SetActivePartition( j ); dismemberSkinMod->SelectAll(3); // ensures bitarrays are properly synced to mesh dismemberSkinMod->ClearSelection(3); vector<Triangle> triangles = part->GetTriangles(j); vector<unsigned short> map = part->GetVertexMap(j); GenericNamedSelSetList& fselSet = bsdsmd->GetFaceSelList(); if ( BitArray* fsel = fselSet.GetSetByIndex(j) ) { for (vector<Triangle>::iterator itrtri = triangles.begin(); itrtri != triangles.end(); ++itrtri) { Face f; f.setVerts( map[(*itrtri).v1], map[(*itrtri).v2], map[(*itrtri).v3] ); FaceMap::iterator fitr = faceMap.find( rotate(f) ); if (fitr != faceMap.end()) fsel->Set((*fitr).second); } } } bsdsmd->SetActivePartition( 0 ); disSkin->LocalDataChanged(); } } } } return ok; }
void ParticleMesherObject::BuildMesh(TimeValue t) { //check if render time //get node //mkae ivalid interesect with the int isRendering = 0; ivalid = FOREVER; TimeValue offset; float foffset; Interval iv; pblock2->GetValue(particlemesher_time, 0, foffset, iv); foffset = -foffset; pblock2->GetValue(particlemesher_radius, 0, radius, iv); foffset *= GetTicksPerFrame(); offset = (TimeValue) foffset; // pblock2->GetValue(particlemesher_time, 0, foffset, iv); if ((lastTime == t) ) { ivalid.Set(t,t); return; } pblock2->GetValue(particlemesher_rendertimeonly, 0, isRendering, ivalid); isRendering = !isRendering; if ((isRendering) || (TestAFlag(A_RENDER))) { INode *node=NULL; pblock2->GetValue(particlemesher_pick, 0, node, ivalid); BOOL reevalGroup = FALSE; if ((node != NULL) && (node->IsGroupHead()) ) { for (int ch=0;ch<node->NumberOfChildren();ch++) { INode *cnode= node->GetChildNode(ch); Interval iv; Matrix3 tm=cnode->GetObjectTM(t,&iv); if (cnode->IsGroupMember()) { reevalGroup = TRUE; for (int groupCount = 0; groupCount < pblock2->Count(particlemesher_extranodes); groupCount++) { INode *extraNode = pblock2->GetINode(particlemesher_extranodes,t,ch); if (cnode == extraNode) { reevalGroup = FALSE; groupCount = pblock2->Count(particlemesher_extranodes); } } if (reevalGroup) ch=node->NumberOfChildren(); } } if (reevalGroup) { tmList.ZeroCount(); pblock2->ZeroCount(particlemesher_extranodes); for (int ch=0;ch<node->NumberOfChildren();ch++) { INode *cnode= node->GetChildNode(ch); Interval iv; Matrix3 tm=cnode->GetObjectTM(t,&iv); if (cnode->IsGroupMember()) { pblock2->Append(particlemesher_extranodes,1,&cnode); tmList.Append(1,&tm); } } } } if (node) { if ( (node->IsGroupHead()) && (pblock2->Count(particlemesher_extranodes)!=0)) { int ct = 0; Matrix3 ident(1), inverseTm(1); mesh.setNumVerts(0); mesh.setNumFaces(0); for (int ch=0;ch<pblock2->Count(particlemesher_extranodes);ch++) { INode *cnode = pblock2->GetINode(particlemesher_extranodes,t,ch); if (cnode) { Object *pobj = cnode->EvalWorldState(t+offset).obj; if ( (pobj->SuperClassID() == GEOMOBJECT_CLASS_ID) || (pobj->SuperClassID() == SHAPE_CLASS_ID) ) { BOOL needDel; NullView nullView; Mesh *msh = ((GeomObject*)pobj)->GetRenderMesh(t+offset,cnode,nullView,needDel); Mesh tmsh = *msh; ivalid &= pobj->ObjectValidity(t+offset); Matrix3 tm(1); if (ch < tmList.Count()) tm = tmList[ch]; for (int v = 0; v < msh->numVerts; v++) { tmsh.verts[v] = tmsh.verts[v] * tm; } if (tmsh.numVerts != 0) { if (ct ==0) { mesh = tmsh; } else mesh = mesh + tmsh; ct++; } if (needDel) delete msh; } } } mesh.InvalidateTopologyCache(); } else { // Object *tobj = node->GetObjectRef(); // macroRecorder->FunctionCall(_T("time"), 1, 0, mr_int, t); // macroRecorder->EmitScript(); ObjectState os = node->EvalWorldState(t+offset); IParticleObjectExt* epobj; epobj = (IParticleObjectExt*) os.obj->GetInterface(PARTICLEOBJECTEXT_INTERFACE); if (os.obj->IsParticleSystem() && epobj) { if (epobj) { BOOL useAllPFEvents; pblock2->GetValue(particlemesher_useallpf,0,useAllPFEvents,FOREVER); pfNodes.ZeroCount(); INode *basenode=NULL; pblock2->GetValue(particlemesher_pick, 0, basenode, ivalid); tmList.ZeroCount(); if (useAllPFEvents) { MyEnumProc dep; os.obj->DoEnumDependents(&dep); for (int i = 0; i < dep.Nodes.Count(); i++) { Interval valid; INode *node = dep.Nodes[i]; Object *obj = node->GetObjectRef(); if (ParticleGroupInterface(obj) != nullptr) { pfNodes.Append(1,&node); Matrix3 tm = node->GetNodeTM(t+offset); tmList.Append(1,&tm); } } } else { int ct = pblock2->Count(particlemesher_pfeventlist); for (int i = 0; i < ct; i++) { INode *node; pblock2->GetValue(particlemesher_pfeventlist,t,node,FOREVER,i); if (node) { Object *obj = node->GetObjectRef(); if (ParticleGroupInterface(obj) != nullptr) { pfNodes.Append(1,&node); Matrix3 tm(1);// = basenode->GetNodeTM(t+offset); Matrix3 ntm = node->GetObjectTM(t+offset); tm = ntm; tmList.Append(1,&ntm); } } } } mesh.setNumVerts(0); mesh.setNumFaces(0); int ct = 0; for (int ch=0;ch< pfNodes.Count();ch++) { INode *cnode = pfNodes[ch]; if (cnode) { Object *pobj = cnode->EvalWorldState(t+offset).obj; if ( (pobj->SuperClassID() == GEOMOBJECT_CLASS_ID) || (pobj->SuperClassID() == SHAPE_CLASS_ID) ) { BOOL needDel; NullView nullView; Mesh *msh = ((GeomObject*)pobj)->GetRenderMesh(t+offset,cnode,nullView,needDel); Mesh tmsh = *msh; ivalid &= pobj->ObjectValidity(t+offset); Matrix3 tm(1); if (ch < tmList.Count()) tm = tmList[ch]; for (int v = 0; v < msh->numVerts; v++) { tmsh.verts[v] = tmsh.verts[v] * tm; } if (tmsh.numVerts != 0) { if (ct ==0) { mesh = tmsh; } else { Mesh tempMesh = mesh; CombineMeshes(mesh, tempMesh, tmsh); } ct++; } if (needDel) delete msh; } } } mesh.InvalidateTopologyCache(); } } else if ( (os.obj->SuperClassID() == GEOMOBJECT_CLASS_ID) || (os.obj->SuperClassID() == SHAPE_CLASS_ID) ) { BOOL needDel; NullView nullView; Mesh *msh = ((GeomObject*)os.obj)->GetRenderMesh(t+offset,node,nullView,needDel); ivalid &= os.obj->ObjectValidity(t); if (msh) { mesh = *msh; mesh.InvalidateTopologyCache(); if (needDel) delete msh; } } } lastTime = t; } else { //build proxy mesh if (node == NULL) { mesh.setNumVerts(5); mesh.setNumFaces(8); mesh.setNumMaps(2); mesh.setNumMapVerts(0, 0); mesh.setNumMapVerts(1, 0); mesh.setNumMapFaces(0, 0); mesh.setNumMapFaces(1, 0); mesh.setVert(0, Point3(-radius,-radius, 0.0f)); mesh.setVert(1, Point3( radius,-radius, 0.0f)); mesh.setVert(2, Point3( radius, radius, 0.0f)); mesh.setVert(3, Point3(-radius, radius, 0.0f)); // mesh.setVert(4, Point3(0.0f, 0.0f, 0.0f)); mesh.setVert(4, Point3(0.0f, 0.0f, radius)); mesh.faces[0].setEdgeVisFlags(1,0,1); mesh.faces[0].setSmGroup(1); mesh.faces[0].setVerts(0,1,3); mesh.faces[1].setEdgeVisFlags(1,1,0); mesh.faces[1].setSmGroup(1); mesh.faces[1].setVerts(1,2,3); mesh.faces[2].setEdgeVisFlags(1,1,1); mesh.faces[2].setSmGroup(1); mesh.faces[2].setVerts(0,4,1); mesh.faces[3].setEdgeVisFlags(1,1,1); mesh.faces[3].setSmGroup(1); mesh.faces[3].setVerts(1,4,0); mesh.faces[4].setEdgeVisFlags(1,1,1); mesh.faces[4].setSmGroup(1); mesh.faces[4].setVerts(2,4,3); mesh.faces[5].setEdgeVisFlags(1,1,1); mesh.faces[5].setSmGroup(1); mesh.faces[5].setVerts(3,4,2); mesh.faces[6].setEdgeVisFlags(1,0,1); mesh.faces[6].setSmGroup(1); mesh.faces[6].setVerts(3,1,0); mesh.faces[7].setEdgeVisFlags(1,1,0); mesh.faces[7].setSmGroup(1); mesh.faces[7].setVerts(3,2,1); } } } else { //build proxy mesh //build proxy mesh INode *node=NULL; pblock2->GetValue(particlemesher_pick, 0, node, ivalid); // if (node == NULL) { mesh.setNumVerts(5); mesh.setNumFaces(8); mesh.setNumMaps(2); mesh.setNumMapVerts(0, 0); mesh.setNumMapVerts(1, 0); mesh.setNumMapFaces(0, 0); mesh.setNumMapFaces(1, 0); mesh.setVert(0, Point3(-radius,-radius, 0.0f)); mesh.setVert(1, Point3( radius,-radius, 0.0f)); mesh.setVert(2, Point3( radius, radius, 0.0f)); mesh.setVert(3, Point3(-radius, radius, 0.0f)); // mesh.setVert(4, Point3(0.0f, 0.0f, 0.0f)); mesh.setVert(4, Point3(0.0f, 0.0f, radius)); mesh.faces[0].setEdgeVisFlags(1,0,1); mesh.faces[0].setSmGroup(1); mesh.faces[0].setVerts(0,1,3); mesh.faces[1].setEdgeVisFlags(1,1,0); mesh.faces[1].setSmGroup(1); mesh.faces[1].setVerts(1,2,3); mesh.faces[2].setEdgeVisFlags(1,1,1); mesh.faces[2].setSmGroup(1); mesh.faces[2].setVerts(0,4,1); mesh.faces[3].setEdgeVisFlags(1,1,1); mesh.faces[3].setSmGroup(1); mesh.faces[3].setVerts(1,4,0); mesh.faces[4].setEdgeVisFlags(1,1,1); mesh.faces[4].setSmGroup(1); mesh.faces[4].setVerts(2,4,3); mesh.faces[5].setEdgeVisFlags(1,1,1); mesh.faces[5].setSmGroup(1); mesh.faces[5].setVerts(3,4,2); mesh.faces[6].setEdgeVisFlags(1,0,1); mesh.faces[6].setSmGroup(1); mesh.faces[6].setVerts(3,1,0); mesh.faces[7].setEdgeVisFlags(1,1,0); mesh.faces[7].setSmGroup(1); mesh.faces[7].setVerts(3,2,1); } } mesh.InvalidateTopologyCache(); }
bool DxStdMtl2::CreateAndLoadEffectData() { ResetDXStates(); if(IsDxMaterialEnabled(map)) { bool useLPRT; TCHAR filename[MAX_PATH]; _tcscpy(filename,GetCOREInterface()->GetDir(APP_PLUGCFG_DIR)); _tcscat(filename,"\\DXDisplay.ini"); useLPRT = GetPrivateProfileInt(_T("Settings"),_T("LPRTEnabled"),0,filename) ? true : false; if(!pd3dDevice) pd3dDevice = GetDevice(); if(!pd3dDevice) return false; if(pEffectParser) { pEffectParser->DestroyParser(); pEffectParser = NULL; } elementContainer.DeleteAllElements(); UpdateSceneLights(); DWORD numberOfPSinst = 0; //lets make sure we get the correct code for the GFX card.. IHLSLCodeGenerator::CodeVersion code = GetPixelShaderSupport(pd3dDevice,numberOfPSinst); if(code == IHLSLCodeGenerator::PS_1_X) return false; IHLSLCodeGenerator * codeGen = IHLSLCodeGenerator::GetHLSLCodeGenerator(); Tab<INode*> lights; for(int j=0;j<sceneLights.Count();j++){ INode * Light = sceneLights[j]->GetLightNode(); lights.Append(1, &Light); } TCHAR * effectString = codeGen->GenerateEffectFile(map,lights,code,bTransparency,numberOfPSinst,useLPRT); if(!pEffectParser) CreateEffectParser(); if(pEffectParser && effectString){ pEffectParser->SetUseLPRT(useLPRT); pEffectParser->LoadEffect(pd3dDevice,this,effectString,false,true); pEffectParser->ParseEffectFile(pd3dDevice,NULL,this); PatchInLightNodes(); LoadTextureData(codeGen); } delete codeGen; IRenderMesh * rm = mpMeshCache->GetActiveRenderMesh(m_CurCache); if(rm) rm->Invalidate(); GetCOREInterface()->ForceCompleteRedraw(FALSE); } return true; }
void xref_low_error(std::wstring project_path, std::wstring pname) { //Tab<const MCHAR*> sourceFile_Files; Tab<const MCHAR*>* pointer_sourceFile_Files = new Tab<const MCHAR*>(); std::wstring filename = (project_path + L"\\" + pname + L"_low0.max"); const wchar_t* file = filename.c_str(); sourceFile_Files.Append(1, &file); sourceFile_Files.Shrink(); pointer_sourceFile_Files->Init(); pointer_sourceFile_Files->Append(1, &file); Tab<MSTR*> tstr_tab; MSTR str(filename.c_str()); MSTR* a = &str; tstr_tab.Append(1, &a); tstr_tab.Shrink(); Tab<MSTR*> tstr_tab_dynamic_allocate_items; MSTR* str_dynamic_allocate_items = new MSTR(filename.c_str()); tstr_tab_dynamic_allocate_items.Append(1, &str_dynamic_allocate_items); tstr_tab_dynamic_allocate_items.Shrink(); //FPValue param1; //int i = 10; ////param1.LoadPtr(FILENAME_ADDXREFITEMSFROMFILE_IOBJXREFMGR_PARAM1_TYPE, filename.data()); //param1.type = FILENAME_ADDXREFITEMSFROMFILE_IOBJXREFMGR_PARAM1_TYPE; //param1.s = filename.data(); //param1.LoadPtr(ParamType2::TYPE_INT_BP, &i); //LOG("param1.s here= "); LOG(param1.s); LOG("\n"); // FPValue param1_FPValue; // TCHAR* param1_TCHAR = _T("Test Track View"); // param1_FPValue.type = TYPE_STRING, // param1_FPValue.s = param1_TCHAR; // param1.type = (ParamType2)TYPE_FPVALUE; // param1.fpv = ¶m1_FPValue; try { { //std::lock_guard<std::mutex> lock(mymutex); //FPValue param3; param3.type = ParamType2::TYPE_STRING_TAB; //param3.s_tab = pointer_sourceFile_Files; param3.s_tab = &sourceFile_Files; //OBJNAMES_ADDXREFITEMSFROMFILE_IOBJXREFMGR_PARAM3_TYPE; //param3.InitTab(ParamType2::TYPE_STRING_TAB, sourceFile_Files.Count()); //param3.LoadPtr(ParamType2::TYPE_STRING_TAB_BV, &sourceFile_Files); //param3.Load(ParamType2::TYPE_STRING_TAB_BV,&sourceFile_Files); //param3.LoadPtr(ParamType2::TYPE_STRING_TAB, &sourceFile_Files); //param3.LoadPtr(ParamType2::TYPE_STRING_TAB_BV, tstr_tab); //param3.LoadPtr(ParamType2::TYPE_STRING_TAB_BV, &tstr_tab_dynamic_allocate_items); //SYSTEM_CALL(param3.LoadPtr(ParamType2::TYPE_STRING_TAB_BV, &sourceFile_Files);) //param3.Load(ParamType2::TYPE_STRING_TAB, &sourceFile_Files); mprintf((*param3.s_tab)[0]); //LOG(); } } catch (const std::exception&) { //LOG("Why this is error, tell me pls"); }; // FPValue param4; // param4.type = ParamType2::TYPE_FPVALUE_TAB_BV; // Tab<FPValue*> param4_fpvalues; // FPValue param4_fpvalue; // FPValue* pointer_param4_fpvalue; // param4_fpvalue.type = (ParamType2)1; // param4_fpvalue.i = 10; // param4_fpvalues.Append(1, &pointer_param4_fpvalue); // param4.fpv_tab = ¶m4_fpvalues; FPValue param4; //param4.type = ParamType2::TYPE_INT_TAB; //param4.type = ParamType2::TYPE_INT_TAB_BV; //param4.type = ParamType2::TYPE_INT_TAB_BR; Tab<int> xrefoptions; xrefoptions.Resize(1); int h = 1; xrefoptions.Append(1, &h); //param4.i_tab = &xrefoptions; //LOG("type is {0}", param4.type); //FPParams fnParams; //FPValue result, param1; //FPValue param1_FPValue; //TCHAR* param1_TCHAR = _T("Test Track View"); //param1_FPValue.type = TYPE_STRING, // param1_FPValue.s = param1_TCHAR; //param1.type = (ParamType2)TYPE_FPVALUE, // param1.fpv = ¶m1_FPValue; //fnParams.params.append(¶m1,1); //LOG("type is {0}", param1.type); // auto s_tab = param3.s_tab; // auto count = s_tab->Count(); // LOG("count here is {}\n", count); // for (int i = 0; i < count; i++) // { // auto sp = (*s_tab)[i]; // LOG("Name {} from param3.s_tab ", i); LOG(sp); LOG("\n"); // } // if (s_tab == nullptr) // LOG("this not good\n"); // else // LOG("uha\n"); }