internal void AddObjects(Renderer.Renderer renderer, string path, Package package) { var data = Resource.Blocks[BlockType.DATA] as NTRO; // Output is World_t we need to iterate m_worldNodes inside it. var worldNodes = (NTROArray)data.Output["m_worldNodes"]; if (worldNodes.Count > 0) { var nodeData = ((NTROValue <NTROStruct>)worldNodes[0]).Value; //TODO: Not be 0. var worldNode = ((NTROValue <string>)nodeData["m_worldNodePrefix"]).Value; if (worldNode != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(worldNode + ".vwnod_c", path, package); if (newResource == null) { Console.WriteLine("unable to load model " + worldNode + ".vwnod_c"); throw new Exception("WTF"); } var node = new WorldNode(newResource); node.AddMeshes(renderer, path, package); } } var entityLumps = (NTROArray)data.Output["m_entityLumps"]; foreach (var lump in entityLumps) { LoadEntities(lump, renderer, path, package); } }
public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null) { var data = (NTRO)Resource.Blocks[BlockType.DATA]; var refMeshes = (NTROArray)data.Output["m_refMeshes"]; var materialGroups = (NTROArray)data.Output["m_materialGroups"]; for (var i = 0; i < refMeshes.Count; i++) { var refMesh = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value; var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage); if (newResource == null) { Console.WriteLine("unable to load mesh " + refMesh.Name); continue; } if (!newResource.Blocks.ContainsKey(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } var skinMaterials = new List <string>(); if (!string.IsNullOrEmpty(skin)) { foreach (var materialGroup2 in materialGroups) { var materialGroup = ((NTROValue <NTROStruct>)materialGroup2).Value; if (((NTROValue <string>)materialGroup["m_name"]).Value == skin) { var materials = (NTROArray)materialGroup["m_materials"]; foreach (var material in materials) { skinMaterials.Add(((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name); } break; } } } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = transform, TintColor = tintColor, SkinMaterials = skinMaterials }); // TODO: Only first, again. break; } }
internal void AddObjects(Renderer.Renderer renderer, string path, Package package) { // Output is World_t we need to iterate m_worldNodes inside it. var worldNodes = world.GetWorldNodeNames(); foreach (var worldNode in worldNodes) { if (worldNode != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(worldNode + ".vwnod_c", path, package); if (newResource == null) { Console.WriteLine("unable to load model " + worldNode + ".vwnod_c"); throw new Exception("WTF"); } var renderWorldNode = new RenderWorldNode(newResource); renderWorldNode.AddMeshes(renderer, path, package); } } foreach (var lump in world.GetEntityLumpNames()) { LoadEntities(lump, renderer, path, package); } }
public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null) { var data = (NTRO)Resource.Blocks[BlockType.DATA]; var refMeshes = (NTROArray)data.Output["m_refMeshes"]; var materialGroups = (NTROArray)data.Output["m_materialGroups"]; for (var i = 0; i < refMeshes.Count; i++) { var refMesh = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)refMeshes[i]).Value; var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh.Name + "_c", path, currentPackage); if (newResource == null) { Console.WriteLine("unable to load mesh " + refMesh.Name); continue; } if (!newResource.Blocks.ContainsKey(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } var skinMaterials = new List<string>(); if (!string.IsNullOrEmpty(skin)) { foreach (var materialGroup2 in materialGroups) { var materialGroup = ((NTROValue<NTROStruct>)materialGroup2).Value; if (((NTROValue<string>)materialGroup["m_name"]).Value == skin) { var materials = (NTROArray)materialGroup["m_materials"]; foreach (var material in materials) { skinMaterials.Add(((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)material).Value.Name); } break; } } } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = transform, TintColor = tintColor, SkinMaterials = skinMaterials }); // TODO: Only first, again. break; } }
public void LoadMeshes(Renderer.Renderer renderer, string path, Matrix4 transform, Vector4 tintColor, Package currentPackage = null, string skin = null) { var data = model.GetData(); var refMeshes = data.GetArray <string>("m_refMeshes"); var materialGroups = data.GetArray("m_materialGroups"); for (var i = 0; i < refMeshes.Length; i++) { var refMesh = refMeshes[i]; var newResource = FileExtensions.LoadFileByAnyMeansNecessary(refMesh + "_c", path, currentPackage); if (newResource == null) { Console.WriteLine("unable to load mesh " + refMesh); continue; } if (!newResource.Blocks.ContainsKey(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } var skinMaterials = new List <string>(); if (!string.IsNullOrEmpty(skin)) { foreach (var materialGroup in materialGroups) { if (materialGroup.GetProperty <string>("m_name") == skin) { var materials = materialGroup.GetArray <string>("m_materials"); skinMaterials.AddRange(materials); break; } } } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = transform, TintColor = tintColor, SkinMaterials = skinMaterials, }); // TODO: Only first, again. break; } }
internal void AddMeshes(Renderer.Renderer renderer, string path, Package package) { var data = worldNode.GetData(); var sceneObjectLayerIndices = data.GetIntegerArray("m_sceneObjectLayerIndices"); var sceneObjects = data.GetArray("m_sceneObjects"); var i = 0; // Output is WorldNode_t we need to iterate m_sceneObjects inside it foreach (var sceneObject in sceneObjects) { var layerIndex = sceneObjectLayerIndices[i]; i++; // TODO: We want UI for this if (layerIndex == 2 || layerIndex == 4) { continue; } // sceneObject is SceneObject_t var renderableModel = sceneObject.GetProperty <string>("m_renderableModel"); var transform = sceneObject.GetArray("m_vTransform"); var matrix = Matrix4.Identity; // what is this for (var x = 0; x < transform.Length; x++) { var a = transform[x].ToVector4(); switch (x) { case 0: matrix.Column0 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 1: matrix.Column1 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 2: matrix.Column2 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 3: matrix.Column3 = new Vector4(a.X, a.Y, a.Z, a.W); break; } } var tintColorWrongVector = sceneObject.GetSubCollection("m_vTintColor").ToVector4(); Vector4 tintColor; if (tintColorWrongVector.W == 0) { tintColor = Vector4.One; Console.WriteLine("Ignoring tintColor, it will f**k things up."); } else { tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W); } if (renderableModel != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load model " + renderableModel + "_c"); continue; } var model = new Model(newResource); var modelEntry = new RenderModel(model); modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package); } var renderable = sceneObject.GetProperty <string>("m_renderable"); if (renderable != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load renderable " + renderable + "_c"); continue; } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = matrix, TintColor = tintColor, }); } } }
internal void AddMeshes(Renderer.Renderer renderer, string path, Package package) { var data = Resource.Blocks[BlockType.DATA] as NTRO; // Output is WorldNode_t we need to iterate m_sceneObjects inside it. var sceneObjectLayerIndices = (NTROArray)data.Output["m_sceneObjectLayerIndices"]; var sceneObjects = (NTROArray)data.Output["m_sceneObjects"]; var i = 0; foreach (var entry in sceneObjects) { var layerIndice = ((NTROValue<byte>)sceneObjectLayerIndices[i]).Value; i++; // TODO: We want UI for this if (layerIndice == 2 || layerIndice == 4) { continue; } // sceneObject is SceneObject_t var sceneObject = ((NTROValue<NTROStruct>)entry).Value; var renderableModel = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderableModel"]).Value; var transform = (NTROArray)sceneObject["m_vTransform"]; var matrix = default(Matrix4); // what is this for (var x = 0; x < 4; x++) { var a = ((NTROValue<Vector4>)transform[x]).Value; switch (x) { case 0: matrix.Column0 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break; case 1: matrix.Column1 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break; case 2: matrix.Column2 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break; case 3: matrix.Column3 = new OpenTK.Vector4(a.X, a.Y, a.Z, a.W); break; } } var tintColorWrongVector = ((NTROValue<Vector4>)sceneObject["m_vTintColor"]).Value; OpenTK.Vector4 tintColor; if (tintColorWrongVector.W == 0) { tintColor = OpenTK.Vector4.One; Console.WriteLine("Ignoring tintColor, it will f**k things up."); } else { tintColor = new OpenTK.Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W); } if (renderableModel != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load model " + renderableModel.Name + "_c"); continue; } var modelEntry = new Model(newResource); modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package); } var renderable = ((NTROValue<ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderable"]).Value; if (renderable != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load renderable " + renderable.Name + "_c"); continue; } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = matrix, TintColor = tintColor }); } } }
private static void LoadEntities(NTROValue lump, Renderer.Renderer renderer, string path, Package package) { var reference = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)lump).Value; if (reference == null) { return; } var newResource = FileExtensions.LoadFileByAnyMeansNecessary(reference.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load entity lump " + reference.Name + "_c"); return; } var entityLump = newResource.Blocks[BlockType.DATA] as EntityLump; var childLumps = (NTROArray)entityLump.Output["m_childLumps"]; foreach (var lump2 in childLumps) { var lol = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)lump).Value; // TODO: Should be controlled in UI with world layers if (lol.Name.Contains("_destruction")) { continue; } LoadEntities(lump2, renderer, path, package); } foreach (var entity in entityLump.Datas) { var scale = string.Empty; var position = string.Empty; var angles = string.Empty; var model = string.Empty; var skin = string.Empty; var colour = new byte[0]; var classname = string.Empty; var name = string.Empty; foreach (var property in entity) { //metadata switch (property.Item2) { case 3368008710: //World Model model = property.Item3 as string; break; case 3827302934: //Position position = property.Item3 as string; break; case 3130579663: //Angles angles = property.Item3 as string; break; case 432137260: //Scale scale = property.Item3 as string; break; case 2020856412: //Skin skin = property.Item3 as string; break; case 588463423: //Colour colour = property.Item3 as byte[]; break; case 3323665506: //Classname classname = property.Item3 as string; break; case 1094168427: name = property.Item3 as string; break; } } if (scale == string.Empty || position == string.Empty || angles == string.Empty) { continue; } var isCamera = classname == "info_player_start" || classname == "worldspawn" || classname == "sky_camera" || classname == "point_devshot_camera" || classname == "point_camera"; if (!isCamera && model == string.Empty) { continue; } var scaleMatrix = Matrix4.CreateScale(ParseCoordinates(scale)); var positionVector = ParseCoordinates(position); var positionMatrix = Matrix4.CreateTranslation(positionVector); var pitchYawRoll = ParseCoordinates(angles); var rollMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pitchYawRoll.Z)); // Roll var pitchMatrix = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(pitchYawRoll.X)); // Pitch var yawMatrix = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(pitchYawRoll.Y)); // Yaw var rotationMatrix = rollMatrix * pitchMatrix * yawMatrix; var transformationMatrix = scaleMatrix * rotationMatrix * positionMatrix; if (isCamera) { if (classname == "worldspawn") { renderer.SetDefaultWorldCamera(positionVector); } else { renderer.AddCamera(name == string.Empty ? $"{classname} #{anonymousCameraCount++}" : name, transformationMatrix); } continue; } var objColor = Vector4.One; // Parse colour if present if (colour.Length == 4) { for (var i = 0; i < 4; i++) { objColor[i] = colour[i] / 255.0f; } } var newEntity = FileExtensions.LoadFileByAnyMeansNecessary(model + "_c", path, package); if (newEntity == null) { Console.WriteLine($"unable to load entity {model}_c"); continue; } var entityModel = new Model(newEntity); entityModel.LoadMeshes(renderer, path, transformationMatrix, objColor, package, skin); } }
private void LoadEntities(string entityName, Renderer.Renderer renderer, string path, Package package) { if (entityName == null) { return; } var newResource = FileExtensions.LoadFileByAnyMeansNecessary(entityName + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load entity lump " + entityName + "_c"); return; } var entityLump = new EntityLump(newResource); var childEntities = entityLump.GetChildEntityNames(); foreach (var childEntityName in childEntities) { // TODO: Should be controlled in UI with world layers if (childEntityName.Contains("_destruction")) { continue; } LoadEntities(childEntityName, renderer, path, package); } var worldEntities = entityLump.GetEntities(); foreach (var entity in worldEntities) { var scale = string.Empty; var position = string.Empty; var angles = string.Empty; var model = string.Empty; var skin = string.Empty; var colour = new byte[0]; var classname = string.Empty; var name = string.Empty; foreach (var property in entity.Properties) { //metadata switch (property.MiscType) { case 3368008710: //World Model model = property.Data as string; break; case 3827302934: //Position position = property.Data as string; break; case 3130579663: //Angles angles = property.Data as string; break; case 432137260: //Scale scale = property.Data as string; break; case 2020856412: //Skin skin = property.Data as string; break; case 588463423: //Colour colour = property.Data as byte[]; break; case 3323665506: //Classname classname = property.Data as string; break; case 1094168427: name = property.Data as string; break; } } if (scale == string.Empty || position == string.Empty || angles == string.Empty) { continue; } var isGlobalLight = classname == "env_global_light"; var isCamera = classname == "info_player_start" || classname == "worldspawn" || classname == "sky_camera" || classname == "point_devshot_camera" || classname == "point_camera"; if (!isGlobalLight && !isCamera && model == string.Empty) { continue; } var scaleMatrix = Matrix4.CreateScale(ParseCoordinates(scale)); var positionVector = ParseCoordinates(position); var positionMatrix = Matrix4.CreateTranslation(positionVector); var pitchYawRoll = ParseCoordinates(angles); var rollMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pitchYawRoll.Z)); // Roll var pitchMatrix = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(pitchYawRoll.X)); // Pitch var yawMatrix = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(pitchYawRoll.Y)); // Yaw var rotationMatrix = rollMatrix * pitchMatrix * yawMatrix; var transformationMatrix = scaleMatrix * rotationMatrix * positionMatrix; if (isCamera) { if (classname == "worldspawn") { renderer.SetDefaultWorldCamera(positionVector); } else { renderer.AddCamera(name == string.Empty ? $"{classname} #{anonymousCameraCount++}" : name, transformationMatrix); } continue; } else if (isGlobalLight) { renderer.SetWorldGlobalLight(positionVector); // TODO: set light angle continue; } var objColor = Vector4.One; // Parse colour if present if (colour.Length == 4) { for (var i = 0; i < 4; i++) { objColor[i] = colour[i] / 255.0f; } } var newEntity = FileExtensions.LoadFileByAnyMeansNecessary(model + "_c", path, package); if (newEntity == null) { Console.WriteLine($"unable to load entity {model}_c"); continue; } var newModel = new Model(newEntity); var entityModel = new RenderModel(newModel); entityModel.LoadMeshes(renderer, path, transformationMatrix, objColor, package, skin); } }
internal void AddMeshes(Renderer.Renderer renderer, string path, Package package) { var data = Resource.Blocks[BlockType.DATA] as NTRO; var sceneObjectLayerIndices = (NTROArray)data.Output["m_sceneObjectLayerIndices"]; var sceneObjects = (NTROArray)data.Output["m_sceneObjects"]; var i = 0; // Output is WorldNode_t we need to iterate m_sceneObjects inside it foreach (var entry in sceneObjects) { var layerIndice = ((NTROValue <byte>)sceneObjectLayerIndices[i]).Value; i++; // TODO: We want UI for this if (layerIndice == 2 || layerIndice == 4) { continue; } // sceneObject is SceneObject_t var sceneObject = ((NTROValue <NTROStruct>)entry).Value; var renderableModel = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderableModel"]).Value; var transform = (NTROArray)sceneObject["m_vTransform"]; var matrix = default(Matrix4); // what is this for (var x = 0; x < 4; x++) { var a = ((NTROValue <System.Numerics.Vector4>)transform[x]).Value; switch (x) { case 0: matrix.Column0 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 1: matrix.Column1 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 2: matrix.Column2 = new Vector4(a.X, a.Y, a.Z, a.W); break; case 3: matrix.Column3 = new Vector4(a.X, a.Y, a.Z, a.W); break; } } var tintColorWrongVector = ((NTROValue <System.Numerics.Vector4>)sceneObject["m_vTintColor"]).Value; Vector4 tintColor; if (tintColorWrongVector.W == 0) { tintColor = Vector4.One; Console.WriteLine("Ignoring tintColor, it will f**k things up."); } else { tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W); } if (renderableModel != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderableModel.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load model " + renderableModel.Name + "_c"); continue; } var modelEntry = new Model(newResource); modelEntry.LoadMeshes(renderer, path, matrix, tintColor, package); } var renderable = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)sceneObject["m_renderable"]).Value; if (renderable != null) { var newResource = FileExtensions.LoadFileByAnyMeansNecessary(renderable.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load renderable " + renderable.Name + "_c"); continue; } renderer.AddMeshObject(new MeshObject { Resource = newResource, Transform = matrix, TintColor = tintColor, }); } } }
private static void LoadEntities(NTROValue lump, Renderer.Renderer renderer, string path, Package package) { var reference = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)lump).Value; if (reference == null) { return; } var newResource = FileExtensions.LoadFileByAnyMeansNecessary(reference.Name + "_c", path, package); if (newResource == null) { Console.WriteLine("unable to load entity lump " + reference.Name + "_c"); return; } var entityLump = newResource.Blocks[BlockType.DATA] as EntityLump; var childLumps = (NTROArray)entityLump.Output["m_childLumps"]; foreach (var lump2 in childLumps) { var lol = ((NTROValue <ResourceExtRefList.ResourceReferenceInfo>)lump).Value; // TODO: Should be controlled in UI with world layers if (lol.Name.Contains("_destruction")) { continue; } LoadEntities(lump2, renderer, path, package); } foreach (var entity in entityLump.Datas) { var scale = string.Empty; var position = string.Empty; var angles = string.Empty; var model = string.Empty; var skin = string.Empty; var colour = new byte[0]; var classname = string.Empty; var name = string.Empty; foreach (var property in entity) { //metadata switch (property.Item2) { case 3368008710: //World Model model = property.Item3 as string; break; case 3827302934: //Position position = property.Item3 as string; break; case 3130579663: //Angles angles = property.Item3 as string; break; case 432137260: //Scale scale = property.Item3 as string; break; case 2020856412: //Skin skin = property.Item3 as string; break; case 588463423: //Colour colour = property.Item3 as byte[]; break; case 3323665506: //Classname classname = property.Item3 as string; break; case 1094168427: name = property.Item3 as string; break; } } if (scale == string.Empty || position == string.Empty || angles == string.Empty) { continue; } if (classname == "point_camera" || classname == "vr_teleport_marker" || model != string.Empty) { var scaleMatrix = Matrix4.CreateScale(ParseCoordinates(scale)); var positionMatrix = Matrix4.CreateTranslation(ParseCoordinates(position)); var rotationVector = ParseCoordinates(angles); var rotationMatrix = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(rotationVector.Z)); rotationMatrix *= Matrix4.CreateRotationY(MathHelper.DegreesToRadians(rotationVector.X)); rotationMatrix *= Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(rotationVector.Y)); var megaMatrix = scaleMatrix * rotationMatrix * positionMatrix; var objColor = Vector4.One; // Parse colour if present if (colour.Length == 4) { for (var i = 0; i < 4; i++) { objColor[i] = colour[i] / 255.0f; } } //This model is hardcoded into the FGD if (classname == "vr_teleport_marker") { model = "models/effects/teleport/teleport_marker.vmdl"; } if (classname == "point_camera") { renderer.AddCamera(name == string.Empty ? $"Camera {anonymousCameraCount++}" : name, megaMatrix); } else { var newEntity = FileExtensions.LoadFileByAnyMeansNecessary(model + "_c", path, package); if (newEntity == null) { Console.WriteLine("unable to load entity " + model + "_c"); continue; } var entityModel = new Model(newEntity); entityModel.LoadMeshes(renderer, path, megaMatrix, objColor, package, skin); } } } }