public Model(String meshName, String materialName) { this.Material = Loaders.Materials.MaterialLoader.GetInstance().GetMaterial(materialName); Mesh mesh = MeshLoader.GetInstance().GetMesh(meshName); base.AddComponent(new MeshComponent(this, mesh)); }
public Mesh ToMesh() { MeshLoader.setupMesh(indices.ToArray(), vertices.ToArray(), out int vao, out int vbo, out int ebo); long bytes = sizeof(uint) * indices.Count + Vertex.VERTEX_BYTE_SIZE * vertices.Count; return(new Mesh(ebo, vbo, vao, indices.Count, bytes, false, "MeshFromMeshBuilder+" + MeshIndex++)); }
public void CreateGeometry(string scenePath, List <Geometry> output, Dictionary <string, Shader> shaders) { Vector3 pos = StringUtils.StringToVector3(position); Shader s = null; if (shaders.ContainsKey(shader)) { s = shaders[shader]; } if (type == "Sphere") { output.Add(new Sphere(pos, radius, s)); return; } else if (type == "Mesh") { var fileInfo = new System.IO.FileInfo(scenePath); string p = System.IO.Path.Combine(fileInfo.DirectoryName, path); Vector3 rot = StringUtils.StringToVector3(euler); Vector3 sca = StringUtils.StringToVector3(scale); var triangles = MeshLoader.LoadMesh(p, pos, rot, sca, s); foreach (var tri in triangles) { output.Add(tri); } return; } Log.Warn($"几何体创建失败!不确定的几何体类型:{type}"); }
public Model(String meshName) { this.Material = new Defaults.DefaultMaterial(); Mesh mesh = MeshLoader.GetInstance().GetMesh(meshName); base.AddComponent(new MeshComponent(this, mesh)); }
private void DrawBoundingBox(IObjectAnchorsServiceEventArgs instance) { MultiAnchorObjectPlacement placement; if (!_objectPlacements.TryGetValue(instance.InstanceId, out placement)) { var boundingBox = _objectAnchorsService.GetModelBoundingBox(instance.ModelId); Debug.Assert(boundingBox.HasValue); placement = Instantiate(MultiAnchorPlacementPrefab).GetComponent <MultiAnchorObjectPlacement>(); var bbox = placement.ModelSpaceContent.AddComponent <WireframeBoundingBox>(); bbox.UpdateBounds(boundingBox.Value.Center, Vector3.Scale(boundingBox.Value.Extents, instance.ScaleChange), boundingBox.Value.Orientation, WireframeMaterial); var mesh = new GameObject("Model Mesh"); mesh.AddComponent <MeshRenderer>().sharedMaterial = WireframeMaterial; mesh.transform.SetParent(placement.ModelSpaceContent.transform, false); MeshLoader.AddMesh(mesh, _objectAnchorsService, instance.ModelId); _objectPlacements.Add(instance.InstanceId, placement); } if (instance.SurfaceCoverage > placement.SurfaceCoverage || !instance.Location.HasValue) { placement.UpdatePlacement(instance); } }
void createlayer(List <List <Vector3> > tmpmoves, string meshname, MeshLoader loader) { List <Vector3> newVertices = new List <Vector3>(); List <Vector3> newNormals = new List <Vector3>(); List <Vector2> newUV = new List <Vector2>(); List <int> newTriangles = new List <int>(); List <Dictionary <int, Dictionary <int, int> > > neighbours = new List <Dictionary <int, Dictionary <int, int> > >(); for (int tmpmvn = 0; tmpmvn < tmpmoves.Count; tmpmvn++) { List <Vector3> tmpmove = tmpmoves[tmpmvn]; if (tmpmove.Count > 1) { createMesh(ref newVertices, ref tmpmove, ref newNormals, ref newUV, ref newTriangles); } } MeshCreatorInput mci = new MeshCreatorInput { meshname = meshname, newUV = newUV.ToArray(), newNormals = newNormals.ToArray(), newVertices = newVertices.ToArray(), newTriangles = newTriangles.ToArray() }; meshCreatorInputQueue.Enqueue(mci); createdLayers++; }
public Kh2Map(GraphicsDevice graphics, IDataContent content, string path) { _graphics = graphics; var binarc = content.FileOpen(path).Using(Bar.Read); _skybox0MeshGroup = FromMdlx(graphics, binarc, "SK0") ?? Empty; _skybox1MeshGroup = FromMdlx(graphics, binarc, "SK1") ?? Empty; _mapMeshGroup = FromMdlx(graphics, binarc, "MAP") ?? Empty; _bobEntities = binarc.ForEntry("out", Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? .Select(x => new BobEntity(x))?.ToList() ?? new List <BobEntity>(); var bobModels = binarc.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); var bobTextures = binarc.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); _bobModels = new List <MeshGroup>(bobModels.Count); for (var i = 0; i < bobModels.Count; i++) { _bobModels.Add(new MeshGroup { MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, Textures = bobTextures[i].LoadTextures(graphics).ToArray() }); } }
private void StartRender(object sender, DoWorkEventArgs e) { var renderer = IoC.Resolve <IRenderer>(); var target = new MemoryRenderTarget(result.Width, result.Height); var color = new Color(1, 0.84, 0); var mesh = new MeshLoader().Load("bunny4.mesh"); var world = new NaiveScene(); world.AddGeometry( new Renderable( mesh, new SolidMaterial(color))); _renderMilliseconds = (int)new Stopwatch().Time(() => renderer.RenderScene(new RenderingContext { Target = target, World = world, ImageMatrix = Matrix.Scaling(1d / target.Width * 100, 1d / target.Height * 100, 1), ProjectionMatrix = Matrix.Scaling((double)target.Width / target.Height, 1, 1), SamplesPerPixel = _samplesPerPixel })); _renderedImage = target.ToBitmap(); }
public IEnumerator LoadObjectFromDiskCR(string path, MeshLoader loader, GCodeHandler mc) { int layernum = 0; //create object to put all mesh types in var objectName = loader.GetObjectNameFromPath(path); var rootFolderOfObject = loader.dataPath + "/" + objectName; mc.RootForObject.transform.localPosition = Vector3.zero; mc.RootForObject.transform.localScale = Vector3.one; mc.RootForObject.transform.localRotation = Quaternion.identity; SortedDictionary <int, List <string> > sortedLayers = new SortedDictionary <int, List <string> >(); foreach (var folder in Directory.GetDirectories(rootFolderOfObject)) { var files = Directory.GetFiles(folder); foreach (var file in Directory.GetFiles(folder)) { var l = Convert.ToInt32(file.Substring(file.LastIndexOf(@" ") + 1, file.LastIndexOf(".") - file.LastIndexOf(@" ") - 1)); if (!sortedLayers.ContainsKey(l)) { sortedLayers.Add(l, new List <string>()); sortedLayers[l].Add(file); } else { sortedLayers[l].Add(file); } } } foreach (var layers in sortedLayers) { foreach (var file in layers.Value) { var typeString = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf(' ') - file.LastIndexOf(@"\") - 1); mc.CreateTypeObject(typeString); var layername = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf(".") - file.LastIndexOf(@"\") - 1); //get mesh from file var mesh = MeshSerializer.DeserializeMesh(File.ReadAllBytes(file)); //get the biggest layer number var l = mc.createLayerObject(layername, typeString, mesh); if (l > layernum) { layernum = l; } } yield return(null); } mc.endloading(layernum); }
public void Init() { carMaterial = new MaterialBuilder() .Build() .SetName("Car Material") .Attach(new Shader("Shaders\\Cars\\vert.glsl", ShaderType.VertexShader)) .Attach(new Shader("Shaders\\Cars\\Frag.glsl", ShaderType.FragmentShader)) .Link() .GetMaterial(); testMesh = MeshLoader.LoadAsset("Content\\Cars\\" + car + "\\model.obj"); wheelMesh = MeshLoader.LoadAsset("Content\\Cars\\wheel01.obj"); testTexture = TextureLoader.LoadAsset("Content\\Cars\\" + car + "\\texture.png"); decalTexture = TextureLoader.LoadAsset("Content\\Cars\\" + car + "\\decal.png"); decalTexture.textureUnit = TextureUnit.Texture1; using (var streamReader = new StreamReader("Content\\Cars\\" + car + "\\data.json")) data = Newtonsoft.Json.JsonConvert.DeserializeObject <VehicleData>(streamReader.ReadToEnd()); engineSound = TrackLoader.LoadAsset("Content\\Cars\\" + car + "\\engine.wav"); engineSound.OnPlaybackStop += (s, e) => { engineSound.PlayBeginning(); }; engineSound.Play(); // Rolling resistance is always (max speed) * drag, with max speed in metres per second data.rollingResistance = (data.maxSpeed / MPH_CONST) * data.drag; }
private void LoadMap(int worldIndex, int placeIndex) { Log.Info($"Map={worldIndex},{placeIndex}"); var fileName = Kernel.GetMapFileName(worldIndex, placeIndex); var entries = _dataContent.FileOpen(fileName).Using(Bar.Read); AddMesh(FromMdlx(_graphics.GraphicsDevice, entries, "SK0")); AddMesh(FromMdlx(_graphics.GraphicsDevice, entries, "SK1")); AddMesh(FromMdlx(_graphics.GraphicsDevice, entries, "MAP")); _bobEntities = entries.ForEntry("out", Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? .Select(x => new BobEntity(x))?.ToList() ?? new List <BobEntity>(); var bobModels = entries.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); var bobTextures = entries.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); for (var i = 0; i < bobModels.Count; i++) { _bobModels.Add(new MeshGroup { MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, Textures = bobTextures[i].LoadTextures(_graphics.GraphicsDevice).ToArray() }); } }
public WorldData(Accelerator device) { this.device = device; worldBuffer = new hWorldBuffer(device); worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(0, -1.5, 2), this, "Assets/defaultcube/defaultcube")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(), this, "Assets/Tree/LowPolyTree")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(0, 0.5, 0), this, "Assets/cat/cat")); //worldBuffer.addGPUMesh(MeshLoader.LoadMeshFromFile(new Vec3(), this, "Assets/cornellbox/cornellbox")); worldBuffer.addSphere(new Sphere(new Vec3(0, -1000, 0), 1, worldBuffer.addMaterial(MaterialData.makeLight(new Vec3(1, 1, 1))))); //worldBuffer.addSphere(new Sphere(new Vec3(0, 1000.5, -1), 1000, worldBuffer.addMaterial(MaterialData.makeDiffuse(new Vec3(0.99f, 0.99f, 0.99f))))); worldBuffer.addSphere(new Sphere(new Vec3(1.5, -1, -1), 0.5f, worldBuffer.addMaterial(MaterialData.makeGlass(new Vec3(0.99f, 0.99f, 0.99f), 1.3f)))); worldBuffer.addSphere(new Sphere(new Vec3(-1.5, -1, -1), 0.5f, worldBuffer.addMaterial(MaterialData.makeMirror(new Vec3(0.99f, 0.99f, 0.99f), 0f)))); Random random = new Random(5); for (int i = 0; i < 25; i++) { float size = (float)((random.NextDouble() * 0.25f) + 0.25f); Vec3 pos = new Vec3((random.NextDouble() * 10f) - 5f, (size / 2f) - 1f, (random.NextDouble() * 10f) - 5f); worldBuffer.addSphere(new Sphere(pos, size, worldBuffer.addMaterial(MaterialData.makeDiffuse(new Vec3( random.NextDouble() > 0.5 ? 0 : 1, random.NextDouble() > 0.5 ? 0 : 1, random.NextDouble() > 0.5 ? 0 : 1))))); } }
private void OnFileLoaded(params object[] args) { MaterialAsset x = args[0] as MaterialAsset; if (x == null) { return; } this.oSelfAsset = x; if (this.matchMono is SkinMeshLoader) { SkinMeshLoader skinMeshLoader = this.matchMono as SkinMeshLoader; if (skinMeshLoader != null) { skinMeshLoader.CombineRender(this.oSelfAsset); } } else if (this.matchMono is MeshLoader) { MeshLoader meshLoader = this.matchMono as MeshLoader; if (meshLoader != null) { meshLoader.CombineRender(this.oSelfAsset); } } }
private static MeshGroup FromMdlx( GraphicsDevice graphics, ArchiveManager archiveManager, string modelName, string textureName) { Log.Info($"Load model={modelName} texture={textureName}"); return(MeshLoader.FromKH2(graphics, archiveManager.Get <Mdlx>(modelName), archiveManager.Get <ModelTexture>(textureName))); }
internal void Update(GCodeHandler source, MeshLoader loader) { if (meshCreatorInputQueue.Count > 0) { MeshCreatorInput mci = meshCreatorInputQueue.Dequeue(); source.createmesh(mci.meshname, mci.newVertices, mci.newNormals, mci.newUV, mci.newTriangles, source.RootForObject.transform); } }
public void Invalidate() { MeshGroup = new MeshGroup { MeshDescriptors = MeshLoader.FromKH2(_model).MeshDescriptors, Textures = _kingdomTextures }; }
public override void GenerateGeometry(string scenePath, Scene scene, List <Material> materials, List <Geometry> output) { var fileInfo = new System.IO.FileInfo(scenePath); string p = System.IO.Path.Combine(fileInfo.DirectoryName, path); var triangles = MeshLoader.LoadMesh(p, position, euler, scale, materials); output.AddRange(triangles); }
void OnEnable() { // Register event callbacks for MESH events: PatientEventSystem.startListening(PatientEventSystem.Event.MESH_LoadedSingle, meshLoaded); PatientEventSystem.startListening(PatientEventSystem.Event.PATIENT_Closed, patientClosed); mMeshLoader = GameObject.Find("GlobalScript").GetComponent <MeshLoader>(); activate(); }
/* internal void CreateObjectFromGCode(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler)//takes ages and munches on all that juicy cpu, only use if absolutely necessary * { * }*/ internal void CreateObjectFromGCode(string[] Lines, MeshLoader loader, GCodeHandler gcodeHandler) { if (Lines[0].Contains("Cura")) { CreateObjectFromGCodeCura(Lines, loader, gcodeHandler); } else if (Lines[0].Contains("Prusa")) { CreateObjectFromGCodePrusa(Lines, loader, gcodeHandler); } }
/// <summary>Load a binary STL file.</summary> /// <seealso href="https://en.wikipedia.org/wiki/STL_%28file_format%29" /> public static Task <IndexedMesh> loadStlAsync(this IRenderDevice device, Stream stream, float?minCosAngle, string name = null) { if (null == Dispatcher.currentDispatcher) { throw new ApplicationException("You must call loadStlAsync on the GUI thread."); // CPU-bound heavy lifting is offloaded to the pool, however once it all done we have to resume on the thread which can create GPU resources. // To resume on the correct thread, the calling code, here, need to be on the thread with the dispatcher. } return(MeshLoader.loadStlAsync(device, stream, minCosAngle, name)); }
public void TestOptimizeMesh() { //TODO: better test //var fileName = TWDir.GameData + "\\Core\\TileSet\\ts001sg001.obj"; var fileName = TWDir.GameData + "\\TileSet01\\GreyBrick_RoofX_01\\GreyBrick_RoofX_01.obj"; var mesh = MeshLoader.LoadMeshFromObj(new System.IO.FileInfo(fileName)); var optimizer = new MeshOptimizer(); var optimized = optimizer.CreateOptimized(mesh); }
static void TestMissingMesh() { try { var mesh = MeshLoader.Load("does_not_exists.obj", DefaultOptions); Assert(false, "Expected exception for files that don't exist"); } catch (Exception e) { Assert(true, $"Caught expected error {e.Message}"); } }
private void proccessNode(ai.Node node, ai.Scene scene, MeshLoader loader) { foreach (int index in node.MeshIndices) { ai.Mesh mesh = scene.Meshes[index]; Meshes.Add(loader(mesh, scene)); } foreach (ai.Node child in node.Children) { proccessNode(child, scene, loader); } }
void OnEnable() { // Register event callbacks for MESH events: PatientEventSystem.startListening(PatientEventSystem.Event.MESH_LoadedAll, createContent); PatientEventSystem.startListening(PatientEventSystem.Event.PATIENT_Closed, clearContent); mMeshLoader = GameObject.Find("GlobalScript").GetComponent <MeshLoader>(); defaultLine.SetActive(false); if (mMeshLoader.MeshGameObjectContainers.Count != 0) { createContent(); } }
/* * loadPatient() starts the loading of a patient. The event Event.PATIENT_Loaded calls this methode and the loading will be finished */ private static void loadPatientFinish(object obj = null) { // Start parsing the DICOM directory: //PatientDICOMLoader mPatientDICOMLoader = GameObject.Find("GlobalScript").GetComponent<PatientDICOMLoader>(); //mPatientDICOMLoader.loadDirectory(entry.dicomPath); DICOMLoader.instance.setDirectory(entry.dicomPath); // Load model in the directory: MeshLoader mModelLoader = GameObject.Find("GlobalScript").GetComponent <MeshLoader>(); mModelLoader.LoadFile(entry.meshPath); loadingLock = false; }
public MeshGroup this[int objId] { get { if (_meshGroups.TryGetValue(objId, out var meshGroup)) { return(meshGroup); } var objEntryName = _objEntryLookupReversed[objId]; var modelPath = Path.Combine(_objPath, objEntryName); var modelFileName = modelPath + ".mdlx"; if (File.Exists(modelFileName)) { var mdlxEntries = File.OpenRead(modelFileName).Using(Bar.Read); var modelEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.Model); if (modelEntry != null) { var model = Mdlx.Read(modelEntry.Stream); ModelTexture textures = null; var textureEntry = mdlxEntries.FirstOrDefault(x => x.Type == Bar.EntryType.ModelTexture); if (textureEntry != null) { textures = ModelTexture.Read(textureEntry.Stream); } var modelMotion = MeshLoader.FromKH2(model); modelMotion.ApplyMotion(modelMotion.InitialPose); meshGroup = new MeshGroup { MeshDescriptors = modelMotion.MeshDescriptors, Textures = textures == null ? new IKingdomTexture[0] : textures.LoadTextures(_graphics).ToArray() }; } else { meshGroup = EmptyMeshGroup; } } else { meshGroup = EmptyMeshGroup; } _meshGroups[objId] = meshGroup; return(meshGroup); } }
public void LoadMesh(GraphicsDevice graphics) { var objEntry = Kernel.ObjEntries.FirstOrDefault(x => x.ObjectId == ObjectId); if (objEntry == null) { Log.Warn("Object ID {0} not found.", ObjectId); return; } IsPlayer = objEntry.ObjectType == Objentry.Type.PLAYER; var modelName = $"obj/{objEntry.ModelName}.mdlx"; using var stream = Kernel.DataContent.FileOpen(modelName); var entries = Bar.Read(stream); _model = entries.ForEntry(x => x.Type == Bar.EntryType.Model, Mdlx.Read); Model = MeshLoader.FromKH2(_model); var texture = entries.ForEntry("tim_", Bar.EntryType.ModelTexture, ModelTexture.Read); Textures = texture.LoadTextures(graphics).ToArray(); ObjectCollisions = entries.ForEntry(x => x.Type == Bar.EntryType.ModelCollision && x.Stream.Length > 0, ObjectCollision.Read) ?? new List <ObjectCollision>(); try { var msetName = $"obj/{objEntry.AnimationName}"; if (Kernel.DataContent.FileExists(msetName)) { var msetEntries = Kernel.DataContent.FileOpen(msetName).Using(Bar.Read); Motion = new Kh2MotionEngine(msetEntries) { CurrentAnimationIndex = 0 }; } else { Motion = new Kh2MotionEngine(); Log.Warn("MSET {0} does not exist", objEntry.AnimationName); } } catch (System.NotImplementedException) { Motion = null; } }
// Use this for initialization void Start() { Runner = GameObject.Find("Runner"); FiveCell = GameObject.Find("5-Cell"); A = FiveCell.GetComponent <Renderer> (); EightCell = GameObject.Find("8-Cell"); B = EightCell.GetComponent <Renderer> (); RP2 = GameObject.Find("RP2"); C = RP2.GetComponent <Renderer> (); RP2cut = GameObject.Find("RP2 Cut Open"); D = RP2cut.GetComponent <Renderer> (); Torus = GameObject.Find("Torus"); E = Torus.GetComponent <Renderer> (); M = Runner.GetComponent <MeshLoader>(); }
private void LoadAsset(string strMeshName) { if (MeshLoader.monLoadAsset != null) { MeshLoader.monLoadAsset(strMeshName, new AssetCallBack(this.OnFileLoaded)); } else { UnityEngine.Object @object = Resources.Load(this.strAssetName); this.OnFileLoaded(new object[] { @object }); } }
public void Load(ContentManager content) { _debugScreen = new DebugScreen(); _debugScreen.LoadContent(content); _transitionManager = new TransitionManager(); _transitionManager.Load(content); _guiRenderer = new GUIRenderer(); _guiRenderer.Load(content); _mainMenuLogic = new MainMenuLogic(); _mainMenuLogic.Load(content); _radialBlurLogic = new RadialBlurLogic(); _radialBlurLogic.Load(content); _radialBlurRenderer = new RadialBlurRenderer(); _radialBlurRenderer.Load(content); _pixelizerLogic = new PixelizerLogic(); _pixelizerLogic.Load(content); _pixelizerRenderer = new PixelizerRenderer(); _pixelizerRenderer.Load(content); _bokehLogic = new BokehLogic(); _bokehLogic.Load(content); _bokehRenderer = new BokehRenderer(); _bokehRenderer.Load(content); _particlePhysicsLogic = new ParticlePhysicsLogic(); _particlePhysicsLogic.Load(content); _particlePhysicsRenderer = new ParticlePhysicsRenderer(); _particlePhysicsRenderer.Load(content); _ssLogic = new SubsurfaceLogic(); _ssLogic.Load(content); _ssRenderer = new SubsurfaceRenderer(); _ssRenderer.Load(content); _ftLogic = new FTLogic(); _ftLogic.Load(content); _ftRenderer = new FTRenderer(); _ftRenderer.Load(content); _meshLoader = new MeshLoader(); _meshLoader.Load(content); }