private void LoadMeshes() { // Get embedded meshes foreach (var embeddedMesh in Model.GetEmbeddedMeshes()) { meshRenderers.Add(new MeshRenderer(embeddedMesh, guiContext, skinMaterials)); } // Load referred meshes from file (only load meshes with LoD 1) var referredMeshesAndLoDs = Model.GetReferenceMeshNamesAndLoD(); foreach (var refMesh in referredMeshesAndLoDs.Where(m => (m.LoDMask & 1) != 0)) { var newResource = guiContext.LoadFileByAnyMeansNecessary(refMesh.MeshName + "_c"); if (newResource == null) { continue; } if (!newResource.ContainsBlockType(BlockType.VBIB)) { Console.WriteLine("Old style model, no VBIB!"); continue; } meshRenderers.Add(new MeshRenderer(new Mesh(newResource), guiContext, skinMaterials)); } }
public RenderMaterial GetMaterial(string name) { if (Materials.ContainsKey(name)) { return(Materials[name]); } var resource = VrfGuiContext.LoadFileByAnyMeansNecessary(name + "_c"); var mat = LoadMaterial(resource); Materials.Add(name, mat); return(mat); }
private (int TextureIndex, Texture TextureData) LoadTexture(string textureName, VrfGuiContext vrfGuiContext) { var textureResource = vrfGuiContext.LoadFileByAnyMeansNecessary(textureName + "_c"); if (textureResource == null) { return(vrfGuiContext.MaterialLoader.GetErrorTexture(), null); } return(vrfGuiContext.MaterialLoader.LoadTexture(textureName), (Texture)textureResource.DataBlock); }
public RenderMaterial GetMaterial(string name) { // HL:VR has a world node that has a draw call with no material if (name == null) { return(GetErrorMaterial()); } if (Materials.ContainsKey(name)) { return(Materials[name]); } var resource = VrfGuiContext.LoadFileByAnyMeansNecessary(name + "_c"); var mat = LoadMaterial(resource); Materials.Add(name, mat); return(mat); }
private static IEnumerable <Animation> LoadAnimationFile(string animationFile, IKeyValueCollection decodeKey, VrfGuiContext vrfGuiContext) { var animResource = vrfGuiContext.LoadFileByAnyMeansNecessary(animationFile + "_c"); if (animResource == null) { throw new FileNotFoundException($"Failed to load {animationFile}_c. Did you configure game paths correctly?"); } // Build animation classes return(Animation.FromResource(animResource, decodeKey)); }
private void LoadWorldNodes() { // 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 = guiContext.LoadFileByAnyMeansNecessary(worldNode + ".vwnod_c"); if (newResource == null) { throw new Exception("WTF"); } var worldNodeRenderer = new WorldNodeRenderer(new WorldNode(newResource), guiContext, worldOctree); worldNodeRenderers.Add(worldNodeRenderer); BoundingBox = BoundingBox.IsZero ? worldNodeRenderer.BoundingBox : BoundingBox.Union(worldNodeRenderer.BoundingBox); } } }
public LoadResult Load(Scene scene) { var result = new LoadResult(); // 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 = guiContext.LoadFileByAnyMeansNecessary(worldNode + ".vwnod_c"); if (newResource == null) { continue; } var subloader = new WorldNodeLoader(guiContext, (WorldNode)newResource.DataBlock); subloader.Load(scene); } } foreach (var lumpName in world.GetEntityLumpNames()) { if (lumpName == null) { continue; } var newResource = guiContext.LoadFileByAnyMeansNecessary(lumpName + "_c"); if (newResource == null) { continue; } var entityLump = (EntityLump)newResource.DataBlock; LoadEntitiesFromLump(scene, result, entityLump, "world_layer_base"); // TODO } return(result); }
public void Load(Scene scene) { var data = node.Data; string[] worldLayers; if (data.ContainsKey("m_layerNames")) { worldLayers = data.GetArray <string>("m_layerNames"); } else { worldLayers = Array.Empty <string>(); } var sceneObjectLayerIndices = data.ContainsKey("m_sceneObjectLayerIndices") ? data.GetIntegerArray("m_sceneObjectLayerIndices") : null; 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++] ?? -1; // sceneObject is SceneObject_t var renderableModel = sceneObject.GetProperty <string>("m_renderableModel"); var matrix = sceneObject.GetArray("m_vTransform").ToMatrix4x4(); var tintColorWrongVector = sceneObject.GetSubCollection("m_vTintColor").ToVector4(); Vector4 tintColor; if (tintColorWrongVector.W == 0) { // Ignoring tintColor, it will f**k things up. tintColor = Vector4.One; } else { tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W); } if (renderableModel != null) { var newResource = guiContext.LoadFileByAnyMeansNecessary(renderableModel + "_c"); if (newResource == null) { continue; } var modelNode = new ModelSceneNode(scene, (Model)newResource.DataBlock, null, false) { Transform = matrix, Tint = tintColor, LayerName = worldLayers[layerIndex], }; scene.Add(modelNode, false); } var renderable = sceneObject.GetProperty <string>("m_renderable"); if (renderable != null) { var newResource = guiContext.LoadFileByAnyMeansNecessary(renderable + "_c"); if (newResource == null) { continue; } var meshNode = new MeshSceneNode(scene, new Mesh(newResource)) { Transform = matrix, Tint = tintColor, LayerName = worldLayers[layerIndex], }; scene.Add(meshNode, false); } } }
private void SetupMeshRenderers() { var data = WorldNode.GetData(); var sceneObjectLayerIndices = data.ContainsKey("m_sceneObjectLayerIndices") ? data.GetIntegerArray("m_sceneObjectLayerIndices") : null; 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) { if (sceneObjectLayerIndices != null) { 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; // Copy transform matrix to right type 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) { // Ignoring tintColor, it will f**k things up. tintColor = Vector4.One; } else { tintColor = new Vector4(tintColorWrongVector.X, tintColorWrongVector.Y, tintColorWrongVector.Z, tintColorWrongVector.W); } if (renderableModel != null) { var newResource = guiContext.LoadFileByAnyMeansNecessary(renderableModel + "_c"); if (newResource == null) { continue; } var renderer = new ModelRenderer(new Model(newResource), guiContext, null, false); renderer.SetMeshTransform(matrix); renderer.SetTint(tintColor); meshRenderers.Add(renderer); BoundingBox = BoundingBox.IsZero ? renderer.BoundingBox : BoundingBox.Union(renderer.BoundingBox); meshOctree.Insert(renderer); } var renderable = sceneObject.GetProperty <string>("m_renderable"); if (renderable != null) { var newResource = guiContext.LoadFileByAnyMeansNecessary(renderable + "_c"); if (newResource == null) { continue; } var renderer = new MeshRenderer(new Mesh(newResource), guiContext); renderer.Transform = matrix; renderer.Tint = tintColor; meshRenderers.Add(renderer); BoundingBox = BoundingBox.IsZero ? renderer.BoundingBox : BoundingBox.Union(renderer.BoundingBox); meshOctree.Insert(renderer); } } }