public void Update() { float DEGREES_TO_RADIANS = (float)(Math.PI / 180.0); CR2WFile layer; using (var fs = new FileStream(DepotPath, FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(fs)) { layer = new CR2WFile(); layer.Read(reader); fs.Close(); } // update all CSectorData objects foreach (var chunk in layer.chunks) { if (chunk.REDType == "CSectorData") { CSectorData sd = (CSectorData)chunk.data; // only add sector node if there are meshes foreach (var block in sd.BlockData) { if (block.packedObjectType == Enums.BlockDataObjectType.Mesh) { SBlockDataMeshObject mo = (SBlockDataMeshObject)block.packedObject; ushort meshIndex = mo.meshIndex.val; string meshName = Path.GetFileName(sd.Resources[meshIndex].pathHash.val); foreach (SceneNode sn in ModifiedNodes) { string modifiedMeshName = Path.GetFileName(sn.Name); if (meshName.Equals(modifiedMeshName)) { Vector3Df pos = sn.Position; Vector3Df rot = sn.Rotation; // update position and rotation block.position.X.val = -pos.X; // flip this block.position.Y.val = pos.Y; block.position.Z.val = pos.Z; float rx = rot.X * DEGREES_TO_RADIANS; float ry = rot.Y * DEGREES_TO_RADIANS; float rz = -rot.Z * DEGREES_TO_RADIANS; // flip this EulerToMatrix(rx, ry, rz, block.rotationMatrix); break; } } } } } } using (var fs = new FileStream(DepotPath, FileMode.Open, FileAccess.ReadWrite)) using (var writer = new BinaryWriter(fs)) { layer.Write(writer); fs.Close(); } }
private void AddLayer(string layerFileName, string layerName, ref int meshId) { float RADIANS_TO_DEGREES = (float)(180 / Math.PI); CR2WFile layer; using (var fs = new FileStream(layerFileName, FileMode.Open, FileAccess.Read)) using (var reader = new BinaryReader(fs)) { layer = new CR2WFile(); layer.Read(reader); fs.Close(); } TreeNode layerNode = new TreeNode(layerName); foreach (var chunk in layer.chunks) { if (chunk.REDType == "CSectorData") { CSectorData sd = (CSectorData)chunk.data; progressBar.Invoke((MethodInvoker) delegate { progressBar.Maximum = sd.BlockData.Count; }); // only add sector node if there are meshes foreach (var block in sd.BlockData) { if (block.packedObjectType == Enums.BlockDataObjectType.Mesh) { SVector3D position = block.position; CMatrix3x3 rot = block.rotationMatrix; float rx, ry, rz; MatrixToEuler(rot, out rx, out ry, out rz); // radians Vector3Df rotation = new Vector3Df(rx * RADIANS_TO_DEGREES, ry * RADIANS_TO_DEGREES, rz * RADIANS_TO_DEGREES); Vector3Df translation = new Vector3Df(position.X.val, position.Y.val, position.Z.val); SBlockDataMeshObject mo = (SBlockDataMeshObject)block.packedObject; ushort meshIndex = mo.meshIndex.val; if (meshIndex > sd.Resources.Count) { continue; } string meshName = sd.Resources[meshIndex].pathHash.val; if (string.IsNullOrEmpty(meshName)) { continue; } RenderMessage message = new RenderMessage(MessageType.ADD_MESH_NODE, meshName, translation, rotation, layerNode); commandQueue.Enqueue(message); progressBar.Invoke((MethodInvoker) delegate { progressBar.PerformStep(); }); } } } } }