public BasicMesh GetBasicMesh() { BasicMesh mesh = m_mesher.GetBasicMesh(this); if (mesh != null) m_volume = mesh.Volume * Prim.Scale.X * Prim.Scale.Y * Prim.Scale.Z; return mesh; }
public static Mesh GenerateMeshFromScriptableObject(CScriptableCharacter character) { Mesh mesh = new Mesh(); CCubeMesh[] cubesMesh = new CCubeMesh[character.CubePositions.Length]; for (int amount = 0; amount < cubesMesh.Length; amount++) { cubesMesh[amount] = new CCubeMesh(character.CubePositions[amount]); } List <BasicMesh> cubesMeshData = new List <BasicMesh>(); foreach (var cubeMesh in cubesMesh) { bool[] neighbours = HasNeighbours(cubeMesh.Position, character); cubesMeshData.Add(cubeMesh.GetMeshData(!neighbours[0], !neighbours[1], !neighbours[2], !neighbours[3], !neighbours[4], !neighbours[5])); } BasicMesh complete = new BasicMesh(); foreach (var basicMesh in cubesMeshData) { CombineBasicMeshes(ref complete, basicMesh, character); } if (cubesMesh != null) { mesh.Clear(); mesh.vertices = complete.Vertices.ToArray(); mesh.triangles = complete.Triangles.ToArray(); mesh.RecalculateNormals(); } return(mesh); }
private void CreateComponentMesh(GameObject component, Turtle turtle) { BasicMesh bm = component.GetComponent <BasicMesh>(); //if (bm == null) Debug.Log("bm null"); //else Debug.Log("bm not null"); bm.CreateMesh(new Turtle(turtle)); }
private static void CombineBasicMeshes(ref BasicMesh first, BasicMesh second, CScriptableCharacter character) { int triOffset = first.Vertices.Count; foreach (var vert in second.Vertices) { first.Vertices.Add((vert - character.Offset) / character.CharacterScaling); } foreach (var tri in second.Triangles) { first.Triangles.Add(tri + triOffset); } }
public Mesh CreateGrid(float width, float length, int xTiles, int zTiles, bool originAtCentre) { Mesh mesh = new BasicMesh(); mesh.Vertices = new Vertex[(xTiles+1) * (zTiles+1)]; float xOffset = 0; float yOffset = 0; if (originAtCentre) { xOffset = -width / 2; yOffset = -length/2; } for (int x = 0; x < xTiles+1; x++) { float xf = (float)x / ((float)xTiles); for (int y = 0; y < zTiles+1; y++) { float yf = 0; float zf = (float)y / ((float)xTiles); VertexTypes.PositionNormalTextured vert = new VertexTypes.PositionNormalTextured(); vert.Pos = new Vector3(xf * width + xOffset, yf, zf * length + yOffset); vert.TexCoord = new Vector2(xf, zf); vert.Normal = new Vector3(xf, yf / 10.0f, zf); mesh.Vertices[y * (xTiles+1) + x] = vert; } } mesh.Indices = new int[(xTiles) * (zTiles) * 6]; int i = 0; for (int x = 0; x < xTiles; x++) for (int y = 0; y < zTiles; y++) { int v0 = IndexFromCoord(x, y, xTiles+1); int v1 = IndexFromCoord(x, y + 1, xTiles+1); int v2 = IndexFromCoord(x + 1, y + 1, xTiles+1); int v3 = IndexFromCoord(x + 1, y, xTiles+1); mesh.Indices[i++] = v0; mesh.Indices[i++] = v1; mesh.Indices[i++] = v2; mesh.Indices[i++] = v0; mesh.Indices[i++] = v2; mesh.Indices[i++] = v3; } return mesh; }
public static Mesh CreateFromStream(Stream stream) { Mesh mesh = new BasicMesh(); mesh.Vertices = new Vertex[Width * Height]; using (BinaryReader reader = new BinaryReader(stream)) { for (int x = 0; x < Width; x++) { float xf = (float)x / ((float)Width - 1.0f); for (int y = 0; y < Height; y++) { ushort val = reader.ReadUInt16(); float yf = (float)val; float zf = (float)y / ((float)Width - 1.0f); VertexTypes.PositionNormalTextured vert = new VertexTypes.PositionNormalTextured(); vert.Pos = new Vector3(xf*10, yf/100000.0f, (1.0f-zf)*10); vert.TexCoord = new Vector2(xf, zf); vert.Normal = new Vector3(xf, yf/10.0f, zf); mesh.Vertices[y * Width + x] = vert; } } } mesh.Indices = new int[(Width-1)*(Height-1)*6]; int i = 0; for (int x = 0; x < Width - 1; x++) for (int y = 0; y < Height - 1; y++) { int v0 = IndexFromCoord(x,y+1); int v1 = IndexFromCoord(x,y); int v2 = IndexFromCoord(x+1,y); int v3 = IndexFromCoord(x+1,y+1); mesh.Indices[i++] = v0; mesh.Indices[i++] = v1; mesh.Indices[i++] = v2; mesh.Indices[i++] = v0; mesh.Indices[i++] = v2; mesh.Indices[i++] = v3; } return mesh; }
public void BasicMeshSerializationTest() { const int VERTICES = 499; const int INDICES = 1009; BasicMesh mesh = new BasicMesh(); mesh.Volume = 42f; mesh.Vertices = new Vector3[VERTICES]; for (int i = 0; i < VERTICES; i++) { mesh.Vertices[i] = RandomVector(); } mesh.Indices = new ushort[INDICES]; for (int i = 0; i < INDICES; i++) { mesh.Indices[i] = (ushort)m_rng.Next(VERTICES); } byte[] data = mesh.Serialize(); BasicMesh mesh2 = BasicMesh.Deserialize(data); Assert.AreEqual(mesh.Volume, mesh2.Volume); Assert.AreEqual(mesh.Vertices.Length, mesh2.Vertices.Length); Assert.AreEqual(mesh.Indices.Length, mesh2.Indices.Length); for (int i = 0; i < mesh.Vertices.Length; i++) { Assert.AreEqual(mesh.Vertices[i], mesh2.Vertices[i]); } for (int i = 0; i < mesh.Indices.Length; i++) { Assert.AreEqual(mesh.Indices[i], mesh2.Indices[i]); } }
public Vector3 llGetCenterOfMass(IScriptInstance script) { ISceneEntity host = script.Host; ISceneEntity[] linkset = GetFullLinkset(host); // Find the center of mass for all triangles in all linked entities Vector3 center = Vector3.Zero; float volume = 0.0f; foreach (ISceneEntity entity in linkset) { if (entity is LLPrimitive) { LLPrimitive prim = (LLPrimitive)entity; BasicMesh mesh = prim.GetBasicMesh(); // Formula adapted from Stan Melax's algorithm: <http://www.melax.com/volint.html> for (int i = 0; i < mesh.Indices.Length; i += 3) { Vector3 v0 = mesh.Vertices[mesh.Indices[i + 0]]; Vector3 v1 = mesh.Vertices[mesh.Indices[i + 1]]; Vector3 v2 = mesh.Vertices[mesh.Indices[i + 2]]; float det = Determinant3x3(v0, v1, v2); center += (v0 + v1 + v2) * det; volume += det; } } } center /= (float)(volume * 4.0); return(center * GetSceneTransform(GetRootEntity(host))); }
public BasicMesh GetBasicMesh(LLPrimitive prim) { BasicMesh mesh; OpenMetaverseMesh omvMesh = null; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetBasicMesh(physicsKey, BASIC_MESH_LOD, out mesh)) { return(mesh); } // Can't go any further without a prim renderer if (m_renderer == null) { return(null); } if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) { omvMesh = m_renderer.GenerateSimpleSculptMesh(prim.Prim, sculptTexture, OpenMetaverse.Rendering.DetailLevel.Low); } } else { // Basic prim meshing omvMesh = m_renderer.GenerateSimpleMesh(prim.Prim, OpenMetaverse.Rendering.DetailLevel.Medium); } if (omvMesh == null) { return(null); } #if DEBUG for (int i = 0; i < omvMesh.Indices.Count; i++) { System.Diagnostics.Debug.Assert(omvMesh.Indices[i] < omvMesh.Vertices.Count, "Mesh index is out of range"); } #endif // Convert the OpenMetaverse.Rendering mesh to a BasicMesh mesh = new BasicMesh(); mesh.Vertices = new Vector3[omvMesh.Vertices.Count]; for (int i = 0; i < omvMesh.Vertices.Count; i++) { mesh.Vertices[i] = omvMesh.Vertices[i].Position; } mesh.Indices = omvMesh.Indices.ToArray(); mesh.Volume = Util.GetMeshVolume(mesh, Vector3.One); // Store the result in the mesh cache, if we have one if (m_meshCache != null) { m_meshCache.StoreBasicMesh(physicsKey, BASIC_MESH_LOD, mesh); } return(mesh); }
public void AfterStart() { //yield return new WaitForEndOfFrame(); // remove old one BasicMesh oldMesh = blade.GetComponent <BasicMesh>(); if (oldMesh != null) { DestroyImmediate(oldMesh); } //if (blade.GetComponent<BasicMesh>() == null) Debug.Log("null"); blade1.SetActive(false); guard.SetActive(false); // make new one switch (myUI.currentType) { case UIManager.WeaponTypes.刀: blade.AddComponent <Knife>(); guard.SetActive(true); break; case UIManager.WeaponTypes.槍: blade.AddComponent <Sword>(); break; case UIManager.WeaponTypes.劍: blade.AddComponent <Sword>(); guard.SetActive(true); break; case UIManager.WeaponTypes.戟: blade.AddComponent <Sword>(); blade1.SetActive(true); break; case UIManager.WeaponTypes.斧鉞: blade.AddComponent <Axe>(); break; case UIManager.WeaponTypes.尖刀: blade.AddComponent <TridentSword>(); guard.SetActive(true); break; //case UIManager.WeaponTypes.自訂: // guard.SetActive(true); // break; default: break; } meshReady = true; //yield return new WaitForEndOfFrame(); if (meshReady) { MakeWeapon(); } }
public Mesh CreateSquare(float width, float length) { Mesh ret = new BasicMesh(); ret.Vertices = new Vertex[]{ new VertexTypes.PositionNormalTextured(){ Pos = new Vector3(0, 0, 0), Normal = new Vector3(0,1,0), TexCoord = new Vector2(0,0)}, new VertexTypes.PositionNormalTextured(){ Pos = new Vector3(0, 0, width), Normal = new Vector3(0,1,0), TexCoord = new Vector2(1,0)}, new VertexTypes.PositionNormalTextured(){ Pos = new Vector3(length, 0, width), Normal = new Vector3(0,1,0), TexCoord = new Vector2(0,1)}, new VertexTypes.PositionNormalTextured(){ Pos = new Vector3(length, 0, 0), Normal = new Vector3(0,1,0), TexCoord = new Vector2(1,1)} }; ret.Indices = new int[] { 0, 1, 2, 0, 2, 3, 2, 1, 0, 3, 2, 0 }; return ret; }
public static Mesh CreateSimpleMesh() { Mesh mesh = new BasicMesh(); Vector3[] pos = new Vector3[] { new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector3(0, 0, 2), new Vector3(1, 0, 2), new Vector3(2, 0, 1), new Vector3(2, 0, 0), new Vector3(1, 0, -1), new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(-1, 0, 1)}; mesh.Vertices = new Vertex[pos.Length]; for (int i = 0; i < pos.Length; i++) mesh.Vertices[i] = new VertexTypes.PositionTexture() { Pos = pos[i], TexCoord = new Vector2(pos[i].X, pos[i].Z) }; mesh.Indices = new int[] { 0,1,2, 0,2,3, 1,4,2, 4,5,2, 2,6,7, 2,7,3, 3,8,0, 0,8,9, 0,10,11, 0,11,1 }; return mesh; }
public BasicMesh GetBasicMesh(LLPrimitive prim) { BasicMesh mesh; OpenMetaverseMesh omvMesh = null; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetBasicMesh(physicsKey, BASIC_MESH_LOD, out mesh)) return mesh; // Can't go any further without a prim renderer if (m_renderer == null) return null; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) omvMesh = m_renderer.GenerateSimpleSculptMesh(prim.Prim, sculptTexture, OpenMetaverse.Rendering.DetailLevel.Low); } else { // Basic prim meshing omvMesh = m_renderer.GenerateSimpleMesh(prim.Prim, OpenMetaverse.Rendering.DetailLevel.Medium); } if (omvMesh == null) return null; #if DEBUG for (int i = 0; i < omvMesh.Indices.Count; i++) System.Diagnostics.Debug.Assert(omvMesh.Indices[i] < omvMesh.Vertices.Count, "Mesh index is out of range"); #endif // Convert the OpenMetaverse.Rendering mesh to a BasicMesh mesh = new BasicMesh(); mesh.Vertices = new Vector3[omvMesh.Vertices.Count]; for (int i = 0; i < omvMesh.Vertices.Count; i++) mesh.Vertices[i] = omvMesh.Vertices[i].Position; mesh.Indices = omvMesh.Indices.ToArray(); mesh.Volume = Util.GetMeshVolume(mesh, Vector3.One); // Store the result in the mesh cache, if we have one if (m_meshCache != null) m_meshCache.StoreBasicMesh(physicsKey, BASIC_MESH_LOD, mesh); return mesh; }
public _3dCursor() { cursor = new BasicMesh(); cursor.Init(new List <BasicVertex>() { new BasicVertex(new Vector3(0.000000F, 0.000000F, 0.000000F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.000000F, 0.000000F, 0.000000F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.000000F, 1.993729F, -1.000000F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.781832F, 1.993729F, -0.623490F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.974928F, 1.993729F, 0.222521F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.433884F, 1.993729F, 0.900969F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.433884F, 1.993729F, 0.900969F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.974928F, 1.993729F, 0.222521F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.781832F, 1.993729F, -0.623490F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.232554F, 2.165461F, 0.053079F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.186494F, 2.165461F, -0.148724F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.103496F, 2.165461F, 0.214912F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.103496F, 2.165461F, 0.214912F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.142345F, 5.531382F, 0.295583F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.142345F, 5.531382F, 0.295583F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.186494F, 2.165461F, -0.148724F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.232554F, 2.165461F, 0.053079F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.000000F, 2.165461F, -0.238535F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.256496F, 5.531382F, -0.204548F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.000000F, 5.531382F, -0.328070F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.256496F, 5.531382F, -0.204548F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(-0.319846F, 5.531382F, 0.073004F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)), new BasicVertex(new Vector3(0.319846F, 5.531382F, 0.073004F), new Vector3(0, 0, 0), new Vector3(0, 0, 0)) }, new List <int>() { 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5, 6, 1, 6, 7, 7, 10, 8, 1, 7, 8, 1, 8, 2, 11, 13, 14, 5, 11, 6, 4, 15, 16, 3, 17, 15, 8, 17, 2, 6, 9, 7, 5, 16, 12, 21, 14, 13, 15, 22, 16, 10, 19, 17, 9, 14, 21, 16, 13, 12, 15, 19, 18, 9, 20, 10, 7, 9, 10, 11, 12, 13, 5, 12, 11, 4, 3, 15, 3, 2, 17, 8, 10, 17, 6, 11, 9, 5, 4, 16, 22, 18, 13, 18, 19, 13, 19, 20, 13, 20, 21, 13, 15, 18, 22, 10, 20, 19, 9, 11, 14, 16, 22, 13, 15, 17, 19, 9, 21, 20, }); cursorPosition = new Buffer(Renderer.viewport.Device, new BufferDescription { Usage = ResourceUsage.Default, SizeInBytes = sizeof(float) * 4, BindFlags = BindFlags.ConstantBuffer }); InitRadiusView(); }