public void OpenMtl(string mtlPath) { var mtl = new MaterialLoader(); var mats = mtl.LoadMaterials(mtlPath); var lib = new BsdfLibrary(); lib.Populate(mats); foreach (var mat in lib) { CurrentVault.Add(mat.Name, mat); } this.CurrentDirectory = Path.GetDirectoryName(mtlPath); }
protected void ParseFile(MaterialLoader.ParseHandler parser, string filename) { StreamReader reader = new StreamReader(filename); while (!reader.EndOfStream) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) continue; string[] tokens = line.Split(omitchars, StringSplitOptions.RemoveEmptyEntries); if (tokens == null || tokens[0].StartsWith("#")) continue; parser(line, tokens); } }
public GLRenderer() { frameParsers = new Dictionary<Type, Action<IFrameElement>>(); frameParsers.Add(typeof(FrameCamera), cameraItem => { var item = (FrameCamera)cameraItem; /*Camera = new PinholeCamera(width, height){ Fov = 40f}; Camera.LookAt(item.Position, item.Target, item.Up);*/ Camera = new BasicPerspectiveCamera((Point) item.Position, item.Target, -item.Up, Width, Height) { Fov = 40 }; }); frameParsers.Add(typeof(FrameObjFileReference), item => { var objFileRef = (FrameObjFileReference)item; var loader = new GlobalIndexObjLoader(); scene = loader.Load(objFileRef.ObjFilePath); var mload = new MaterialLoader(); mats = mload.LoadMaterials(objFileRef.MtlFilePath); foreach (var materialInfo in mats) { if (materialInfo.Name.ToLower().Contains("glass") || materialInfo.Name.ToLower().Contains("wire_134006006") ) { materialInfo.Kt = materialInfo.DiffuseReflectance; materialInfo.DiffuseReflectance = RgbSpectrum.ZeroSpectrum(); //materialInfo.MediumInfo = Glass; } if (materialInfo.Name.ToLower().Contains("metal")) { materialInfo.SpecularReflectance = materialInfo.DiffuseReflectance; } } }); frameParsers.Add(typeof(Frame3DsFileReference), item => { var sceneFileRef = (Frame3DsFileReference)item; var loader = new SceneLoader(); scene = loader.Load(sceneFileRef.FilePath); mats = loader.LoadMaterials(sceneFileRef.FilePath); foreach (var materialInfo in mats) { if (materialInfo.Name.ToLower().Contains("glass") || materialInfo.Name.ToLower().Contains("wire_134006006") ) { materialInfo.Kt = materialInfo.DiffuseReflectance; materialInfo.DiffuseReflectance = RgbSpectrum.ZeroSpectrum(); //materialInfo.MediumInfo = Glass; } if (materialInfo.Name.ToLower().Contains("metal")) { materialInfo.SpecularReflectance = materialInfo.DiffuseReflectance; } } if (scene.Cameras != null && scene.Cameras.Any()) { Camera = new BasicPerspectiveCamera((Point) scene.Cameras[0].Position, scene.Cameras[0].Direction, scene.Cameras[0].Up, Width, Height) { Fov = scene.Cameras[0].Fov }; } }); frameParsers.Add(typeof(FrameLightsource), item => { if (lights == null) { lights = new List<ILight>(); } var lightsource = (FrameLightsource)item; switch (lightsource.LightType) { case LightSourceTypes.Point: lights.Add(new PointLight(lightsource)); break; case LightSourceTypes.EnvironmentMap: lights.Add(envMap = new InfiniteLight(lightsource)); break; case LightSourceTypes.Area: //if (AreaLightAsMeshLight) lights.Add(new MeshLight(lightsource)); break; } }); }