public static Texture CreateFromFile(string path, bool isLinear) { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } System.IO.FileInfo fileInfo = new System.IO.FileInfo(path); if (fileInfo.Exists == false) { return(null); } int textureID = CreateTextureFromFile(path, isLinear); if (textureID >= 0) { Texture texture = new Texture(textureID); texture.filterMode = FilterMode.Bilinear; MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, texture); return(texture); } ; return(null); }
private void OnUpdateFrame(object sender, EventArgs e) { RayTracerNet.RayTracer instance = RayTracerNet.RayTracer.GetInstance(); if (instance != null) { instance.UpdateRayTracerRenderer(); } }
public static RayTracer GetInstance() { if (instance == null) { instance = new RayTracer(); } return(instance); }
private void RayTracerComponent_Load(object sender, EventArgs e) { RayTracerNet.RayTracer instance = RayTracerNet.RayTracer.GetInstance(); if (instance != null) { if (instance.InitRayTracer(Handle, Width, Height)) { m_Timer.Start(); } } }
private void OnMouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int x = e.X; int y = e.Y; RayTracerNet.RayTracer instance = RayTracerNet.RayTracer.GetInstance(); var hitObj = instance.GetScene().GetPrimitiveRaycasted(x, y); if (hitObj != null) { hitObj.Select(); MessageHandler.Broadcast <RayTracerNet.RayTracerObject>(MessageName.SelectSceneObject, hitObj); } } }
public static PBR_StandardShader Create() { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int shaderID = CreatePBRStandardShader(); if (shaderID >= 0) { var shader = new PBR_StandardShader(shaderID); MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, shader); return(shader); } return(null); }
public static Mesh Create(uint vertexCount, uint indexCount) { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int meshID = CreateMesh(vertexCount, indexCount); if (meshID >= 0) { Mesh mesh = new Mesh(meshID); MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, mesh); return(mesh); } ; return(null); }
public static Texture Create(uint width, uint height) { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int textureID = CreateTexture(width, height); if (textureID >= 0) { Texture texture = new Texture(textureID); texture.filterMode = FilterMode.Bilinear; MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, texture); return(texture); } ; return(null); }
internal static Camera Create() { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int cameraID = CreateCamera(); if (cameraID < 0) { return(null); } Camera camera = new Camera(cameraID); MessageHandler.Broadcast <RayTracerObject>(MessageName.AddNewSceneObject, camera); return(camera); }
public static MeshPrimitive Create() { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int primitiveID = CreateMeshPrimitive(); if (primitiveID < 0) { return(null); } MeshPrimitive meshPrimitive = new MeshPrimitive(primitiveID); MessageHandler.Broadcast <RayTracerObject>(MessageName.AddNewSceneObject, meshPrimitive); return(meshPrimitive); }
public static EnvironmentMapSkyLight Create() { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int skyLightID = CreateEnvironmentMapSkyLight(); if (skyLightID < 0) { return(null); } EnvironmentMapSkyLight skylight = new EnvironmentMapSkyLight(skyLightID); MessageHandler.Broadcast <RayTracerObject>(MessageName.AddNewSceneObject, skylight); return(skylight); }
public static Mesh[] CreateFromFile(string path) { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } System.IO.FileInfo fileInfo = new System.IO.FileInfo(path); if (fileInfo.Exists == false) { return(null); } if (fileInfo.Extension.ToLower().EndsWith(".mesh") == true) { Mesh mesh = LoadFromMesh(path); if (mesh != null) { MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, mesh); } return(new Mesh[] { mesh }); } int startMeshID = -1; int endMeshID = -1; CreateMeshesFromFile(path, ref startMeshID, ref endMeshID); if (startMeshID >= 0 && endMeshID >= 0) { Mesh[] results = new Mesh[endMeshID - startMeshID + 1]; for (int i = startMeshID; i <= endMeshID; i++) { Mesh mesh = new Mesh(i); mesh.m_path = path; MessageHandler.Broadcast <ResourceObject>(MessageName.AddNewResource, mesh); results[i - startMeshID] = mesh; } return(results); } return(null); }
public static SunLight Create() { RayTracer instance = RayTracer.GetInstance(); if (!instance.IsInitialized()) { return(null); } int sunLightID = CreateSunLight(); if (sunLightID < 0) { return(null); } SunLight sunLight = new SunLight(sunLightID); sunLight.euler = new Vector3(50, -30, 0); MessageHandler.Broadcast <RayTracerObject>(MessageName.AddNewSceneObject, sunLight); return(sunLight); }
public bool CreateFromFile(string scenePath) { var sceneData = RayTracerNet.Serialization.SceneSerialization.Deserialize(scenePath); if (sceneData == null) { Log.Err("场景序列化失败!"); return(false); } Clear(); RenderSettings renderSettings = RayTracer.GetInstance().renderSettings; int renderWidth = renderSettings.renderWidth; int renderHeight = renderSettings.renderHeight; Camera cam = sceneData.camera.CreateCamera(m_activeCamera, ref renderWidth, ref renderHeight); renderSettings.renderWidth = renderWidth; renderSettings.renderHeight = renderHeight; Dictionary <string, Texture> textures = new Dictionary <string, Texture>(); if (sceneData.textures != null) { for (int i = 0; i < sceneData.textures.Count; i++) { var t = sceneData.textures[i].CreateTexture(scenePath); if (t != null) { //m_resObjects.Add(t); textures.Add(sceneData.textures[i].name, t); } } } Log.Info($"纹理加载完毕:共{textures.Count}张纹理"); Dictionary <string, Mesh[]> meshes = new Dictionary <string, Mesh[]>(); if (sceneData.meshes != null) { for (int i = 0; i < sceneData.meshes.Count; i++) { var m = sceneData.meshes[i].CreateMesh(scenePath); //if (m != null) //{ // m_resObjects.AddRange(m); //} } } var sky = sceneData.sky != null?sceneData.sky.CreateSkyLight(textures) : null; var sun = sceneData.sky != null?sceneData.sky.CreateSunLight() : null; //if (sky != null) // m_sceneObjects.Add(sky); //if (sun != null) // m_sceneObjects.Add(sun); Dictionary <string, MaterialShader> shaders = new Dictionary <string, MaterialShader>(); if (sceneData.shaders != null) { for (int i = 0; i < sceneData.shaders.Count; i++) { var s = sceneData.shaders[i].CreateShader(textures); if (shaders != null) { //m_resObjects.Add(s); shaders.Add(sceneData.shaders[i].name, s); } } } Log.Info($"Shader加载完毕:共{shaders.Count}个Shader"); List <PrimitiveBase> primivites = new List <PrimitiveBase>(); if (sceneData.geometries != null) { for (int i = 0; i < sceneData.geometries.Count; i++) { sceneData.geometries[i].CreatePrimitive(scenePath, shaders, meshes, primivites); } } //for (int i = 0; i < primivites.Count; i++) // m_sceneObjects.Add(primivites[i]); //foreach (var mesh in meshes) //{ // m_resObjects.AddRange(mesh.Value); //} Log.Info($"几何体加载完毕:共{primivites.Count}个几何体"); return(true); }