Пример #1
0
 public static void ClearTextures(SharpRenderer renderer, BSPRenderer bspRenderer)
 {
     OpenTXDfiles.Clear();
     OpenTextureFolders.Clear();
     DisposeTextures();
     Textures.Clear();
     ReapplyTextures(renderer, bspRenderer);
 }
Пример #2
0
        public static void ReapplyTextures(SharpRenderer renderer, BSPRenderer bspRenderer)
        {
            List <RenderWareModelFile> models = new List <RenderWareModelFile>();

            models.AddRange(bspRenderer.BSPList);
            models.AddRange(bspRenderer.ShadowColBSPList);
            models.AddRange(renderer.dffRenderer.DFFModels.Values);

            foreach (RenderWareModelFile m in models)
            {
                foreach (SharpMesh mesh in m.meshList)
                {
                    foreach (SharpSubSet sub in mesh.SubSets)
                    {
                        if (Textures.ContainsKey(sub.DiffuseMapName))
                        {
                            if (sub.DiffuseMap != Textures[sub.DiffuseMapName])
                            {
                                if (sub.DiffuseMap != null)
                                {
                                    if (!sub.DiffuseMap.IsDisposed)
                                    {
                                        if (sub.DiffuseMap != SharpRenderer.whiteDefault)
                                        {
                                            sub.DiffuseMap.Dispose();
                                        }
                                    }
                                }

                                sub.DiffuseMap = Textures[sub.DiffuseMapName];
                            }
                        }
                        else
                        {
                            if (sub.DiffuseMap != null)
                            {
                                if (!sub.DiffuseMap.IsDisposed)
                                {
                                    if (sub.DiffuseMap != SharpRenderer.whiteDefault)
                                    {
                                        sub.DiffuseMap.Dispose();
                                    }
                                }
                            }

                            sub.DiffuseMap = SharpRenderer.whiteDefault;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void RunMainLoop(Panel Panel)
        {
            RenderLoop.Run(Panel, () =>
            {
                if (dontRender)
                {
                    return;
                }

                //Resizing
                if (device.MustResize)
                {
                    device.Resize();
                    aspectRatio = (float)Panel.Width / Panel.Height;
                }

                Program.mainForm.KeyboardController();

                sharpFPS.Update();

                Program.mainForm.SetToolStripStatusLabel(Camera.GetInformation() + " FPS: " + sharpFPS.FPS.ToString());

                //clear color
                device.Clear(backgroundColor);

                //Set matrices
                viewProjection = Camera.GenerateLookAtRH() * Matrix.PerspectiveFovRH(fovAngle, aspectRatio, near, far);
                frustum        = new BoundingFrustum(viewProjection);

                if (showCollision)
                {
                    CollisionRendering.RenderCollisionModel(viewProjection, -Camera.GetForward(), Camera.GetUp());
                    BSPRenderer.RenderShadowCollisionModel(viewProjection);
                }
                else
                {
                    BSPRenderer.RenderLevelModel(viewProjection);
                }

                if (showChunkBoxes)
                {
                    VisibilityFunctions.RenderChunkModels(viewProjection);
                }

                if (showObjects == CheckState.Checked)
                {
                    Program.layoutEditor.layoutSystem.RenderAllSetObjects(true);
                }
                else if (showObjects == CheckState.Indeterminate)
                {
                    Program.layoutEditor.layoutSystem.RenderAllSetObjects(false);
                }

                if (showCameras)
                {
                    Program.cameraEditor.RenderAllCameras();
                }

                if (showStartPositions)
                {
                    Program.configEditor.RenderStartPositions();
                }

                if (showSplines)
                {
                    Program.splineEditor.RenderSplines();
                }

                if (showQuadtree)
                {
                    CollisionRendering.RenderQuadTree();
                }

                //present
                device.Present();
            });

            //release resources
            foreach (RenderWareModelFile r in BSPRenderer.BSPStream)
            {
                foreach (SharpMesh mesh in r.meshList)
                {
                    mesh.Dispose();
                }
            }

            foreach (RenderWareModelFile r in BSPRenderer.ShadowCollisionBSPStream)
            {
                foreach (SharpMesh mesh in r.meshList)
                {
                    mesh.Dispose();
                }
            }

            foreach (RenderWareModelFile r in DFFRenderer.DFFStream.Values)
            {
                foreach (SharpMesh mesh in r.meshList)
                {
                    mesh.Dispose();
                }
            }

            CollisionRendering.Dispose();

            if (BSPRenderer.whiteDefault != null)
            {
                BSPRenderer.whiteDefault.Dispose();
            }

            foreach (ShaderResourceView texture in BSPRenderer.TextureStream.Values)
            {
                texture.Dispose();
            }

            Cube.Dispose();
            Pyramid.Dispose();
            Cylinder.Dispose();

            basicBuffer.Dispose();
            basicShader.Dispose();

            defaultBuffer.Dispose();
            defaultShader.Dispose();

            collisionBuffer.Dispose();
            collisionShader.Dispose();

            device.Dispose();
        }
Пример #4
0
 public void ToggleRenderByChunk()
 {
     renderByChunkHToolStripMenuItem.Checked = !renderByChunkHToolStripMenuItem.Checked;
     BSPRenderer.SetRenderByChunk(renderByChunkHToolStripMenuItem.Checked);
 }
Пример #5
0
        public static void LoadTexturesFromTXD(RWSection[] txdFile, SharpRenderer renderer, BSPRenderer bspRenderer)
        {
            foreach (RWSection rw in txdFile)
            {
                if (rw is TextureDictionary_0016 td)
                {
                    foreach (TextureNative_0015 tn in td.textureNativeList)
                    {
                        AddTextureNative(tn.textureNativeStruct, renderer);
                    }
                }
            }

            ReapplyTextures(renderer, bspRenderer);
        }
Пример #6
0
 public static void LoadTexturesFromTXD(byte[] txdData, SharpRenderer renderer, BSPRenderer bspRenderer)
 {
     LoadTexturesFromTXD(ReadFileMethods.ReadRenderWareFile(txdData), renderer, bspRenderer);
 }
Пример #7
0
        public static void LoadTexturesFromTXD(string filePath, SharpRenderer renderer, BSPRenderer bspRenderer)
        {
            if (!Path.GetFileName(filePath).Equals("temp.txd"))
            {
                OpenTXDfiles.Add(filePath);
            }

            try
            {
                if (Path.GetExtension(filePath).ToLower().Equals(".one"))
                {
                    byte[]  oneFile = File.ReadAllBytes(filePath);
                    Archive archive = Archive.FromONEFile(ref oneFile);

                    foreach (ArchiveFile archiveFile in archive.Files)
                    {
                        if (Path.GetExtension(archiveFile.Name).ToLower().Equals(".txd"))
                        {
                            SetupTextureDisplay(archiveFile.DecompressThis(), renderer, bspRenderer);
                        }
                    }
                }
                else if (Path.GetExtension(filePath).ToLower().Equals(".txd"))
                {
                    LoadTexturesFromTXD(File.ReadAllBytes(filePath), renderer, bspRenderer);
                }

                else
                {
                    throw new InvalidDataException(filePath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error opening " + filePath + ": " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                OpenTXDfiles.Remove(filePath);
            }
        }
Пример #8
0
        public static void SetupTextureDisplay(byte[] txdFile, SharpRenderer renderer, BSPRenderer bspRenderer)
        {
            if (!Directory.Exists(tempGcTxdsDir))
            {
                Directory.CreateDirectory(tempGcTxdsDir);
            }
            if (!Directory.Exists(tempPcTxdsDir))
            {
                Directory.CreateDirectory(tempPcTxdsDir);
            }

            File.WriteAllBytes(pathToGcTXD, txdFile);

            PerformTXDConversionExternal();

            LoadTexturesFromTXD(pathToPcTXD, renderer, bspRenderer);
            ReapplyTextures(renderer, bspRenderer);

            File.Delete(pathToGcTXD);
            File.Delete(pathToPcTXD);
        }
Пример #9
0
        public static void SetTextureForAnimation(string diffuseMapName, string newMapName, BSPRenderer bspRenderer, DFFRenderer dffRenderer)
        {
            List <RenderWareModelFile> models = new List <RenderWareModelFile>();

            models.AddRange(bspRenderer.BSPList);
            models.AddRange(bspRenderer.ShadowColBSPList);
            models.AddRange(dffRenderer.DFFModels.Values);

            foreach (RenderWareModelFile m in models)
            {
                foreach (SharpMesh mesh in m.meshList)
                {
                    foreach (SharpSubSet sub in mesh.SubSets)
                    {
                        if (sub.DiffuseMapName == diffuseMapName)
                        {
                            sub.DiffuseMap = Textures[newMapName];
                        }
                    }
                }
            }
        }
Пример #10
0
        public static void LoadTexturesFromFolder(string folderName, SharpRenderer renderer, BSPRenderer bspRenderer)
        {
            OpenTextureFolders.Add(folderName);

            foreach (string i in Directory.GetFiles(folderName))
            {
                if (Path.GetExtension(i).ToLower().Equals(".png"))
                {
                    AddTexturePNG(i, renderer);
                }
            }

            ReapplyTextures(renderer, bspRenderer);
        }