private CSectorData ReadCSectorData() { var temp = new CSectorData() { Unknown1 = ReadUInt32(), Unknown2 = ReadUInt32(), }; var numresources = ReadVLQInt32(); temp.resources = new SSectorDataResource[numresources]; for (int i = 0; i < numresources; i++) { temp.resources[i] = new SSectorDataResource() { box0 = ReadSingle(), box1 = ReadSingle(), box2 = ReadSingle(), box3 = ReadSingle(), box4 = ReadSingle(), box5 = ReadSingle(), patchHash = ReadUInt64(), }; } var numobjects = ReadVLQInt32(); temp.objects = new SSectorDataObject[numobjects]; for (int i = 0; i < numobjects; i++) { temp.objects[i] = new SSectorDataObject() { type = ReadByte(), flags = ReadByte(), radius = ReadUInt16(), offset = ReadUInt64(), positionX = ReadSingle(), positionY = ReadSingle(), positionZ = ReadSingle(), }; } var datasize = ReadVLQInt32(); temp.blockdata = ReadBytes(datasize); return(temp); }
private CSectorData ReadCSectorData() { var temp = new CSectorData(); var Unknown = ReadUInt32(); //Unknown. All w2l files have the value set to 117440512 / 0x07000000. var DataSize = ReadUInt32(); //Size of the whole object including self. var numresources = ReadVLQInt32().Size; temp.resources = ReadStructs <SSectorDataResource>(numresources); var numobjects = ReadVLQInt32().Size; temp.objects = ReadStructs <SSectorDataObject>(numobjects); var datasize = ReadVLQInt32().Size; temp.blockdata = ReadBytes(datasize); return(temp); }
private void PrintCSectorData(CSectorData temp) { Writer.WriteLine("\tUnknown1 {0}", temp.Unknown1); Writer.WriteLine("\tUnknown2 {0}", temp.Unknown2); Writer.WriteLine("\tresources {0}", temp.resources.Length); Writer.WriteLine("\t{"); for (int i = 0; i < temp.resources.Length; i++) { Writer.WriteLine("\t\tId {0}:", i); Writer.WriteLine("\t\t{"); Writer.WriteLine("\t\t\tBox0: {0}", temp.resources[i].box0); Writer.WriteLine("\t\t\tBox1: {0}", temp.resources[i].box1); Writer.WriteLine("\t\t\tBox2: {0}", temp.resources[i].box2); Writer.WriteLine("\t\t\tBox3: {0}", temp.resources[i].box3); Writer.WriteLine("\t\t\tBox4: {0}", temp.resources[i].box4); Writer.WriteLine("\t\t\tBox5: {0}", temp.resources[i].box5); Writer.WriteLine("\t\t\tPatchHash: {0}", temp.resources[i].patchHash); Writer.WriteLine("\t\t}"); } Writer.WriteLine("\t}"); Writer.WriteLine("\tobjects {0}", temp.objects.Length); Writer.WriteLine("\t{"); for (int i = 0; i < temp.objects.Length; i++) { Writer.WriteLine("\t\tId {0}:", i); Writer.WriteLine("\t\t{"); Writer.WriteLine("\t\t\tType: {0}", temp.objects[i].type); Writer.WriteLine("\t\t\tFlags: {0}", temp.objects[i].flags); Writer.WriteLine("\t\t\tRadius: {0}", temp.objects[i].radius); Writer.WriteLine("\t\t\tOffset: {0}", temp.objects[i].offset); Writer.WriteLine("\t\t\tPositionX: {0}", temp.objects[i].positionX); Writer.WriteLine("\t\t\tPositionY: {0}", temp.objects[i].positionY); Writer.WriteLine("\t\t\tPositionZ: {0}", temp.objects[i].positionZ); Writer.WriteLine("\t\t}"); } Writer.WriteLine("\t}"); Writer.WriteLine("\tBlock Data: {0}", temp.blockdata.Length); }
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(); }); } } } } }