public override Asset Import(string path) { HIE hie = HIE.Load(path); Model model = new Model(); Model mshses = new Model(); foreach (string mesh in hie.Meshes) { Model mshs = SceneManager.Current.Content.Load <Model, MSHSImporter>(Path.GetFileNameWithoutExtension(mesh), Path.GetDirectoryName(path)); foreach (ModelMesh part in mshs.Meshes) { mshses.AddMesh(part); } } foreach (string texture in hie.Textures) { SceneManager.Current.Content.Load <Material, TXImporter>(texture, Path.GetDirectoryName(path), true); } processNode(hie.Root, model, mshses, hie); ModelManipulator.FlipAxis(model, Axis.X, true); return(model); }
public static void TravelTree(ModelBone bone, HIE hie, bool root = false) { //hie.Name = bone.Name; //hie.Transform = new Matrix3D( // bone.Transform.M11, bone.Transform.M12, bone.Transform.M13, // bone.Transform.M21, bone.Transform.M22, bone.Transform.M23, // bone.Transform.M31, bone.Transform.M32, bone.Transform.M33, // bone.Transform.M41, bone.Transform.M42, bone.Transform.M43 // ); //switch (bone.Type) //{ // case BoneType.Mesh: // cnt.Section = CNT.NodeType.MODL; // cnt.Model = bone.Mesh.Name; // break; // case BoneType.Light: // cnt.Section = CNT.NodeType.LITg; // cnt.EmbeddedLight = (bone.AttachmentFile == null); // if (cnt.EmbeddedLight) // { // cnt.Light = (LIGHT)bone.Attachment; // } // else // { // cnt.LightName = bone.AttachmentFile; // if (bone.Attachment is LIGHT light) // { // light.Save(Path.Combine(rootPath, cnt.LightName + ".light")); // } // } // break; // case BoneType.VFX: // cnt.Section = CNT.NodeType.VFXI; // cnt.VFXFile = bone.AttachmentFile; // break; // default: // cnt.Section = CNT.NodeType.NULL; // break; //} foreach (ModelBone b in bone.Children) { TravelTree(b, hie); } //if (!root) { parent.Children.Add(hie); } }
public override void Export(Asset asset, string path) { rootPath = Path.GetDirectoryName(path); Model model = asset as Model; HIE hie = new HIE(); TravelTree(model.Root, hie, true); hie.Save(path); }
static void processNode(TDRNode node, Model model, Model mshses, HIE hie, int parentBoneIndex = 0) { int boneIndex = parentBoneIndex; switch (node.Type) { case TDRNode.NodeType.Matrix: boneIndex = model.AddMesh(null, boneIndex); model.SetName(node.Name, boneIndex); model.SetTransform(node.Transform, boneIndex); break; case TDRNode.NodeType.Mesh: int index = node.Index; mshses.Meshes[index].MeshParts[0].Material = material; if (model.Bones[parentBoneIndex].Mesh == null) { model.SetMesh(mshses.Meshes[index], boneIndex); } else { boneIndex = model.AddMesh(mshses.Meshes[index], parentBoneIndex); model.SetName(mshses.Meshes[index].Name, boneIndex); } break; case TDRNode.NodeType.Texture: if (node.Index > -1) { material = SceneManager.Current.Content.Load <Material, TXImporter>(hie.Textures[node.Index]); } else { material = null; } break; } foreach (TDRNode child in node.Children) { processNode(child, model, mshses, hie, boneIndex); } }
static void ProcessNode(TDRNode node, Model model, Model mshses, HIE hie, int ParentBoneIndex = 0) { int boneIndex = ParentBoneIndex; if (exit) { return; } switch (node.Type) { case TDRNode.NodeType.Matrix: boneIndex = model.AddMesh(null, boneIndex); model.SetName(node.Name, boneIndex); model.SetTransform( new Matrix4( node.Transform.M11, node.Transform.M12, node.Transform.M13, 0, node.Transform.M21, node.Transform.M22, node.Transform.M23, 0, node.Transform.M31, node.Transform.M32, node.Transform.M33, 0, node.Transform.M41, node.Transform.M42, node.Transform.M43, 1 ), boneIndex); break; case TDRNode.NodeType.Mesh: int index = node.Index; mshses.Meshes[index].MeshParts[0].Material = material; if (model.Bones[ParentBoneIndex].Mesh == null) { model.SetMesh(mshses.Meshes[index], boneIndex); //exit = true; //Console.WriteLine("Adding mesh #{0} \"{1}\" to bone #{2} \"{3}\"", index, mshses.Meshes[index].Name, boneIndex, model.Bones[boneIndex].Name); } else { boneIndex = model.AddMesh(mshses.Meshes[index], ParentBoneIndex); model.SetName(mshses.Meshes[index].Name, boneIndex); //model.SetName(mshses.Meshes[index].Name, model.AddMesh(mshses.Meshes[index], ParentBoneIndex)); //Console.WriteLine("Adding mesh #{0} \"{1}\" to brand new bone", index, mshses.Meshes[index].Name); } break; case TDRNode.NodeType.Texture: if (node.Index > -1) { material = SceneManager.Current.Content.Load <Material, TXImporter>(hie.Textures[node.Index]); } else { material = null; } break; } foreach (var child in node.Children) { ProcessNode(child, model, mshses, hie, boneIndex); } }
public override Asset Import(string path) { HIE hie = HIE.Load(path); Model model = new Model(); Model mshses = new Model(); foreach (string mesh in hie.Meshes) { var mshs = SceneManager.Current.Content.Load <Model, MSHSImporter>(Path.GetFileNameWithoutExtension(mesh), Path.GetDirectoryName(path) + "\\"); foreach (var part in mshs.Meshes) { mshses.AddMesh(part); } } foreach (string texture in hie.Textures) { SceneManager.Current.Content.Load <Material, TXImporter>(texture, Path.GetDirectoryName(path) + "\\", true); } ProcessNode(hie.Root, model, mshses, hie); //ModelMesh mesh = new ModelMesh(); //mesh.Name = "DEFAULT"; //foreach (var tdrmesh in mshs.Meshes) //{ // ModelMeshPart meshpart = new ModelMeshPart(); // meshpart.PrimitiveType = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; // SceneManager.Current.UpdateProgress(string.Format("Processing {0}", mesh.Name)); // for (int i = 0; i < tdrmesh.Faces.Count; i++) // { // var face = tdrmesh.Faces[i]; // var v1 = tdrmesh.Vertexes[face.V1]; // var v2 = tdrmesh.Vertexes[face.V2]; // var v3 = tdrmesh.Vertexes[face.V3]; // meshpart.AddFace( // new OpenTK.Vector3[] { // new OpenTK.Vector3(v1.Position.X, v1.Position.Y, v1.Position.Z), // new OpenTK.Vector3(v2.Position.X, v2.Position.Y, v2.Position.Z), // new OpenTK.Vector3(v3.Position.X, v3.Position.Y, v3.Position.Z) // }, // new OpenTK.Vector3[] { // new OpenTK.Vector3(v1.Normal.X, v1.Normal.Y, v1.Normal.Z), // new OpenTK.Vector3(v2.Normal.X, v2.Normal.Y, v2.Normal.Z), // new OpenTK.Vector3(v3.Normal.X, v3.Normal.Y, v3.Normal.Z) // }, // new OpenTK.Vector2[] { // new OpenTK.Vector2(v1.UV.X, v1.UV.Y), // new OpenTK.Vector2(v2.UV.X, v2.UV.Y), // new OpenTK.Vector2(v3.UV.X, v3.UV.Y) // } // ); // } // mesh.AddModelMeshPart(meshpart); //} //model.SetName(mesh.Name, model.AddMesh(mesh)); return(model); }
private void Loop() { bool morePeers = (StateLog.Instance.Nodes.NodeCount > 0); bool timerActive = CurrentState.Instance.Timer.Active; (State State, bool TimePassed)state = CurrentState.Instance.Get_State; if (!morePeers && timerActive) { CurrentState.Instance.Timer.End(); _sleepingTimer.Begin(); CurrentState.Instance.ActAsSleeper(); // Logger.Write(Logger.Tag.WARN, state.State.ToString()); } else if (morePeers && !timerActive) { CurrentState.Instance.Timer.Begin(); _sleepingTimer.End(); } if (Utils.IsCandidate(state.State) || (CurrentState.Instance.CandidateResolve && state.State == State.SLEEPER)) // && !ElectionTerm) { // CurrentState.Instance.SetReceivedVote(false); List <Call> batch = new List <Call> { new Call() { Type = Call._Type.VOTE, ID = Utils.GenerateUUID(), Data = Encoder.EncodeVote(new Vote() { ID = Params.ID, LogCount = StateLog.Instance.LogCount }) } }; VoteResponseHandler handler = new VoteResponseHandler() { Quorum = StateLog.Instance.Nodes.NodeCount }; Task[] tasks; StateLog.Instance.Nodes.ForEachAsync((p) => { ProcedureCallBatch rb = new ProcedureCallBatch() { Batch = batch, Sender = Credentials.Self }; p.Client.StartClient(rb, handler, true); }, out tasks); Parallel.ForEach <Task>(tasks, (t) => { t.Start(); }); Task.WaitAll(tasks); // ElectionTerm = true; } if (CurrentState.Instance.IsLeader || (CurrentState.Instance.CandidateResolve && state.State == State.SLEEPER)) { bool connectionsLost = false; StateLog.Instance.Nodes.ForEachPeer((p) => { if (p.Heartbeat.Value >= Params.MAX_RETRIES) { connectionsLost = true; if (StateLog.Instance.Nodes.NodeCount > 1) { StateLog.Instance.AddBehindToAllButOne(p.Client.ID, new Call() { Type = Call._Type.NODE_DEL, ID = Utils.GenerateUUID(), Data = Encoder.EncodeNode(p.AsNode) }); } Node peer = null; bool success = StateLog.Instance.Nodes.TryGetNode(p.Client.ID, out peer); Dictionary <string, DataRequest> _rescheduledActions = new Dictionary <string, DataRequest>(); if (success && !CurrentState.Instance.CandidateResolve) { peer.ForEachEntry((a) => { if (!_rescheduledActions.ContainsKey(a.ID)) { DataRequest action = a; action.Assigned = StateLog.Instance.Nodes.ScheduleRequest(p.Client.ID); action.ID = Utils.GenerateUUID(); StateLog.Instance.AddBehindToAllButOne(p.Client.ID, new Call() { Type = Call._Type.DATA_REQUEST, ID = Utils.GenerateUUID(), Data = Encoder.EncodeDataRequest(action) }); _rescheduledActions.Add(a.ID, action); } }); } else if (success && CurrentState.Instance.CandidateResolve) { peer.ForEachEntry((a) => { if (!_rescheduledActions.ContainsKey(a.ID)) { DataRequest action = a; action.Assigned = Params.ID; action.ID = Utils.GenerateUUID(); StateLog.Instance.AddBehindToAllButOne(p.Client.ID, new Call() { Type = Call._Type.DATA_REQUEST, ID = Utils.GenerateUUID(), Data = Encoder.EncodeDataRequest(action) }); _rescheduledActions.Add(a.ID, action); } }); } StateLog.Instance.ClearPeerLog(p.Client.ID); StateLog.Instance.Nodes.TryRemoveNode(p.Client.ID); if (StateLog.Instance.Nodes.NodeCount < 1) { CurrentState.Instance.SetCandidateResolve(false); } foreach (var action in _rescheduledActions.Values) { StateLog.Instance.AppendAction(action); } } else { connectionsLost = StateLog.Instance.BatchesBehindCount(p.Client.ID) > 0; } }); if (CurrentState.Instance.IsLeader) { bool ready = StateLog.Instance.NotAnyBatchOrCompleteBehind(); bool passed = CurrentState.Instance.Timer.HasTimePassed(((int)(Params.HEARTBEAT_MS / 2))); if (!ready || passed || connectionsLost || StateLog.Instance.Nodes.PeerLogCount > StateLog.Instance.Nodes.NodeCount) { Task[] tasks; StateLog.Instance.Nodes.ForEachAsync((p) => { HashSet <string> acp = StateLog.Instance.Leader_GetActionsCompleted(p.Client.ID); ProcedureCallBatch rb = new ProcedureCallBatch() { Batch = StateLog.Instance.GetBatchesBehind(p.Client.ID), Completed = acp, Sender = Credentials.Self }; p.Client.StartClient(rb, new DefaultHandler()); }, out tasks); Parallel.ForEach <Task>(tasks, (t) => { t.Start(); }); Task t = Task.WhenAll(tasks); try { t.Wait(); } catch {} } if (passed) { Producer.Instance.Broadcast(); CurrentState.Instance.Timer.Reset(); } if (wait < Utils.Millis) { ready = StateLog.Instance.NotAnyBatchOrCompleteBehind(); _consumer.MarkReady(ready); } } } if (state.State == State.SLEEPER && _sleepingTimer.HasTimePassed(((int)(Params.HEARTBEAT_MS / 2)))) { try { Producer.Instance.Broadcast(); _sleepingTimer.Reset(); } catch {} } if (state.State == State.SLEEPER) { _consumer.MarkReady(true); } if (Params.RUN_HIE) { int balance = StateLog.Instance.Nodes.NodeCount * 2; if (balance < 1) { balance = 1; } for (int bs = 0; bs < balance; bs++) { DataRequest prioritizedAction = StateLog.Instance.PriorityQueue.Dequeue(); if (prioritizedAction != null) { List <Driver> requiredDriver = HIE.GetOrCreateDriver(prioritizedAction); requiredDriver.ForEach((dr0) => { dr0.AddRequestBehind(prioritizedAction); }); } } List <Task> tasks = new List <Task>(); HIE.ForEachDriver((d) => { Task t = new Task( () => { d.Write(); } ); tasks.Add(t); }); Parallel.ForEach <Task>(tasks, (t) => { t.Start(); }); // Task ta = Task.WhenAll(tasks); // try { // ta.Wait(); // } // catch {} // List<Task> tasks0 = new List<Task>(); // List<Driver> driver_replacements = new List<Driver>(); // HIE.ForEachDriver((d) => { // Task t = new Task( // ()=>{ // if (d.Heartbeat.Value > Params.MAX_RETRIES+1) // { // Driver d0 = Driver.MakeDriver(d.Image, d.Config.Replica+1); // driver_replacements.Add(d0); // } // } // ); // tasks0.Add(t); // }); // Parallel.ForEach<Task>(tasks0, (t) => { t.Start(); }); // Task ta1 = Task.WhenAll(tasks0); // try { // ta.Wait(); // } // catch {} TestReceiverClient.Instance.StartClient(); } // if (FileLogger.Instance.IsEnabled && Utils.Millis > FileLogTS+1000 && !CurrentState.Instance.IsLeader) // { // long f = Utils.Millis; // int i0 = StateLog.Instance.ActionCount; // int lc = StateLog.Instance.LogCount; // int i1 = StateLog.Instance.PriorityQueue.Count; // int i2 = StateLog.Instance.Peers.NodeCount; // string ram = Utils.MemoryUsage.ToString(); // string cpu = Utils.CPUUsage.ToString(); // FileLogger.Instance.WriteToFile( // string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", // f.ToString(), i0.ToString(), lc.ToString(), i1.ToString(), i2.ToString(), state.State.ToString(), cpu, ram) // ); // FileLogTS = Utils.Millis; // } }