private void Init() { //Block of code came from Spline asset string generatedName = "generated by " + GetType().Name; var generatedTranform = transform.Find(generatedName); generatedModelGameObject = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject, typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshBender)); generatedModelGameObject.GetComponent <MeshRenderer>().material = material; meshBender = generatedModelGameObject.GetComponent <MeshBender>(); spline = GetComponent <Spline>(); meshBender.Source = SourceMesh.Build(mesh) .Rotate(Quaternion.Euler(rotation)) .Scale(scale); meshBender.Mode = MeshBender.FillingMode.StretchToInterval; meshBender.SetInterval(spline, 0, 0.01f); }
private void Init() { if (m_Spline != null && m_Mesh != null && m_Material != null) { string generatedName = "Mesh"; var generatedTranform = transform.Find(generatedName); m_Generated = generatedTranform != null ? generatedTranform.gameObject : UOUtility.Create(generatedName, gameObject, typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshBender)); m_Generated.GetComponent <MeshRenderer>().material = m_Material; meshBender = m_Generated.GetComponent <MeshBender>(); // m_Spline = GetComponent<Spline>(); meshBender.Source = SourceMesh.Build(m_Mesh) .Rotate(Quaternion.Euler(m_Rotation)) .Scale(m_Scale); meshBender.Mode = MeshBender.FillingMode.Once; meshBender.SetInterval(m_Spline, 0); } }
private void GenerateMeshes() { /* * Get the set of all meshes to combine. All of this must be done on * the main thread. */ GameObject origObject = m_tile.GameObject.GetComponent <GameObject>(); Observable.Start( () => { Component[] components = origObject.GetComponentsInChildren <MeshFilter>(); foreach (MeshFilter meshFilter in components) { if (m_manager.FilterInfoNodes && meshFilter.name.StartsWith("info Node")) { continue; } SourceMesh sourceMesh = new SourceMesh(); /* * Ignore partial buildings for mesh reduction, we don't * handle these properly. */ var parent = meshFilter.transform.parent; if (parent != null && parent.name.Contains("building:part:yes")) { sourceMesh.type = MeshType.Other; } else { switch (meshFilter.name) { case "water": sourceMesh.type = MeshType.Water; break; case "wall": sourceMesh.type = MeshType.Wall; break; case "floor": sourceMesh.type = MeshType.Floor; break; default: sourceMesh.type = MeshType.Other; break; } } sourceMesh.mesh = meshFilter.mesh; sourceMesh.transform = meshFilter.transform.localToWorldMatrix; sourceMesh.vertexCount = meshFilter.mesh.vertexCount; m_sourceMeshes.Add(sourceMesh); } }, Scheduler.MainThread).Wait(); int vertexReduction = 0; /* * Try to combine all the meshes into smaller meshes. Basic bin * packing problem, use a greedy first-fit algorithm. */ foreach (SourceMesh sourceMesh in m_sourceMeshes) { /* Reduce the complexity of the mesh. */ if (m_manager.EnableMeshReduction) { int vertexCount; sourceMesh.mesh = new MeshReducer().Reduce(sourceMesh.mesh, sourceMesh.type, out vertexCount); vertexReduction += sourceMesh.vertexCount - vertexCount; sourceMesh.vertexCount = vertexCount; } /* Find a mesh that can fit this one. */ CombinedMesh combinedMesh = null; foreach (CombinedMesh existingMesh in m_meshes) { if (existingMesh.type != sourceMesh.type) { continue; } else if (existingMesh.totalVertexCount + sourceMesh.vertexCount > 65534) { continue; } combinedMesh = existingMesh; break; } if (combinedMesh == null) { combinedMesh = new CombinedMesh(); combinedMesh.type = sourceMesh.type; m_meshes.Add(combinedMesh); } CombineInstance combine = new CombineInstance(); combine.mesh = sourceMesh.mesh; combine.transform = sourceMesh.transform; combinedMesh.combines.Add(combine); combinedMesh.totalVertexCount += sourceMesh.vertexCount; } if (m_manager.EnableMeshReduction) { Debug.LogWarning("Reduced total vertex count by " + vertexReduction); } }