void Jiggle::RemoveSpring(int sel) { if (sel == 0) { MAXException(_T("Can't remove the first spring")); return; } else if (sel >= GetSpringCount() || sel < 0 ) MAXException(GetString(IDS_OUT_OF_RANGE)); Interface* my_ip = GetCOREInterface(); if (theHold.Holding()) HoldAll(); partsys->GetParticle(0)->DeleteSpring(sel); dyn_pb->Delete(jig_control_node, sel, 1); partsys->Invalidate(); validStart = false; UpdateNodeList(); NotifyDependents(FOREVER, (PartID)PART_ALL, REFMSG_CHANGE); my_ip->RedrawViews(my_ip->GetTime()); }
void Unreal3DExport::WriteModel() { // Progress pInt->ProgressUpdate(Progress, FALSE, GetString(IDS_INFO_WRITE)); // Open data file fMesh = _tfopen(ModelFileName,_T("wb")); if( !fMesh ) { ProgressMsg.printf(GetString(IDS_ERR_FMODEL),ModelFileName); throw MAXException(ProgressMsg.data()); } // Open anim file fAnim = _tfopen(AnimFileName,_T("wb")); if( !fAnim ) { ProgressMsg.printf(GetString(IDS_ERR_FANIM),AnimFileName); throw MAXException(ProgressMsg.data()); } // data headers hData.NumPolys = Tris.Count(); hData.NumVertices = VertsPerFrame; // anim headers hAnim.FrameSize = VertsPerFrame * sizeof(FMeshVert); hAnim.NumFrames = FrameCount; // Progress CheckCancel(); pInt->ProgressUpdate(Progress, FALSE, GetString(IDS_INFO_WMESH)); // Write data fwrite(&hData,sizeof(FJSDataHeader),1,fMesh); if( Tris.Count() > 0 ) { fwrite(Tris.Addr(0),sizeof(FJSMeshTri),Tris.Count(),fMesh); } Progress += U3D_PROGRESS_WMESH; // Progress CheckCancel(); pInt->ProgressUpdate(Progress, FALSE, GetString(IDS_INFO_WANIM)); // Write anim fwrite(&hAnim,sizeof(FJSAnivHeader),1,fAnim); if( Verts.Count() > 0 ) { fwrite(Verts.Addr(0),sizeof(FMeshVert),Verts.Count(),fAnim); } Progress += U3D_PROGRESS_WANIM; }
void Jiggle::SetDampening(int index, float dampening, int absolute, bool update) { if (index < 0 || index >= dyn_pb->Count(jig_control_node)) { MAXException(GetString(IDS_OUT_OF_RANGE)); return; } for (int b=0;b<partsys->GetParticle(0)->GetSprings()->length();b++) { if (index == partsys->GetParticle(0)->GetSpring(b)->GetPointConstraint()->GetIndex()) { if (absolute == 0) dampening += partsys->GetParticle(0)->GetSpring(b)->GetDampening(); partsys->GetParticle(0)->GetSpring(b)->SetDampening(dampening); } } partsys->Invalidate(); if (update) { UpdateNodeList(); NotifyDependents(FOREVER, (PartID)PART_ALL, REFMSG_CHANGE); if(ip) ip->RedrawViews(ip->GetTime()); } }
float Jiggle::GetDampening(int index) { if (index >=0 && index < dyn_pb->Count(jig_control_node)) return partsys->GetParticle(0)->GetSpring(index)->GetDampening(); MAXException(GetString(IDS_OUT_OF_RANGE)); return 0; }
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); }
void Unreal3DExport::GetAnim() { // Export vertex animation int lastvert = 0; FMeshVert nullvert = FMeshVert(); Points.SetCount(VertsPerFrame*FrameCount,TRUE); for( int t=0; t<FrameCount; ++t ) { // Progress CheckCancel(); ProgressMsg.printf(GetString(IDS_INFO_ANIM),t+1,FrameCount); pInt->ProgressUpdate(Progress+((float)t/FrameCount*U3D_PROGRESS_ANIM), FALSE, ProgressMsg.data()); // Set frame int frameverts = 0; int curframe = FrameStart + t; pScene->SetStaticFrame(curframe); // Write mesh verts for( int n=0; n<Nodes.Count(); ++n ) { CheckCancel(); IGameMesh * mesh = (IGameMesh*)Nodes[n]->GetIGameObject(); if( mesh->InitializeData() ) { int vertcount = mesh->GetNumberOfVerts(); for( int i=0; i<vertcount; ++i ) { Point3 p; if( mesh->GetVertex(i,p) ) { Points[lastvert++] = p; } } frameverts += vertcount; } Nodes[n]->ReleaseIGameObject(); } // Check number of verts in this frame if( frameverts != VertsPerFrame ) { ProgressMsg.printf(GetString(IDS_ERR_NOVERTS),curframe,frameverts,VertsPerFrame); throw MAXException(ProgressMsg.data()); } } Progress += U3D_PROGRESS_ANIM; }
void Unreal3DExport::WriteScript() { // Write script file { fScript = _tfopen(ScriptFileName,_T("wb")); if( !fScript ) { ProgressMsg.printf(GetString(IDS_ERR_FSCRIPT),ScriptFileName); throw MAXException(ProgressMsg.data()); } TSTR buf; // Write class def _ftprintf( fScript, _T("class %s extends Object;\n\n"), FileName ); // write import _ftprintf( fScript, _T("#exec MESH IMPORT MESH=%s ANIVFILE=%s_a.3D DATAFILE=%s_d.3D \n"), FileName, FileName, FileName ); // write origin & rotation // TODO: figure out why it's incorrect without -1 Point3 porg = OptOffset * OptScale * -1; _ftprintf( fScript, _T("#exec MESH ORIGIN MESH=%s X=%f Y=%f Z=%f PITCH=%d YAW=%d ROLL=%d \n"), FileName, porg.x, porg.y, porg.z, (int)OptRot.x, (int)OptRot.y, (int)OptRot.z ); // write mesh scale Point3 psc( Point3(1.0f/OptScale.x,1.0f/OptScale.y,1.0f/OptScale.z)); _ftprintf( fScript, _T("#exec MESH SCALE MESH=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write meshmap _ftprintf( fScript, _T("#exec MESHMAP NEW MESHMA=P%s MESH=%smap \n"), FileName, FileName ); // write meshmap scale _ftprintf( fScript, _T("#exec MESHMAP SCALE MESHMAP=%s X=%f Y=%f Z=%f \n"), FileName, psc.x, psc.y, psc.z ); // write sequence _ftprintf( fScript, _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d \n"), FileName, _T("All"), 0, FrameCount-1 ); // Get World NoteTrack ReferenceTarget *rtscene = pInt->GetScenePointer(); for( int t=0; t<rtscene->NumNoteTracks(); ++t ) { DefNoteTrack* notetrack = static_cast<DefNoteTrack*>(rtscene->GetNoteTrack(t)); for( int k=0; k<notetrack->keys.Count(); ++k ) { NoteKey* notekey = notetrack->keys[k]; TSTR text = notekey->note; int notetime = notekey->time / pScene->GetSceneTicks(); while( !text.isNull() ) { TSTR cmd = SplitStr(text,_T('\n')); if( MatchPattern(cmd,TSTR(_T("a *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR seq = SplitStr(cmd,_T(' ')); int end = _ttoi(SplitStr(cmd,_T(' ')));; TSTR rate = SplitStr(cmd,_T(' ')); TSTR group = SplitStr(cmd,_T(' ')); if( seq.isNull() ) { ProgressMsg.printf(_T("Missing animation name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( end <= notetime ) { ProgressMsg.printf(_T("Invalid animation endframe (%d) in notekey #%d"),end,notetime); throw MAXException(ProgressMsg.data()); } int startframe = notetime; int numframes = end - notetime; buf.printf( _T("#exec MESH SEQUENCE MESH=%s SEQ=%s STARTFRAME=%d NUMFRAMES=%d"), FileName, seq, notetime, numframes ); if( !rate.isNull() ) buf.printf( _T("%s RATE=%f"), buf, rate ); if( !group.isNull() ) buf.printf( _T("%s GROUP=%f"), buf, rate ); SeqName = seq; SeqFrame = startframe; buf.printf( _T("%s \n"), buf ); _fputts( buf, fScript ); } else if( MatchPattern(cmd,TSTR(_T("n *")),TRUE) ) { SplitStr(cmd,_T(' ')); TSTR func = SplitStr(cmd,_T(' ')); TSTR time = SplitStr(cmd,_T(' ')); if( func.isNull() ) { ProgressMsg.printf(_T("Missing notify name in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } if( time.isNull() ) { ProgressMsg.printf(_T("Missing notify time in notekey #%d"),notetime); throw MAXException(ProgressMsg.data()); } buf.printf( _T("#exec MESH NOTIFY MESH=%s SEQ=%s TIME=%s FUNCTION=%s"), FileName, SeqName, time, func ); _fputts( buf, fScript ); } } } } // TODO: write materials if( Materials.Count() > 0 ) { for( int i=0; i<Materials.Count(); ++i ) { IGameMaterial* mat = Materials[i].Mat; if( mat == NULL ) continue; _ftprintf( fScript, _T("#exec MESHMAP SETTEXTURE MESHMAP=%s NUM=%d TEXTURE=%s \n"), FileName, i, _T("DefaultTexture") ); } } } }