/// <summary> /// Returns the mesh associated with the object, this will mesh primitives /// and always return a mesh. /// </summary> /// <returns></returns> public Mesh Mesh() { var const_pointer = ConstPointer(); var mesh = UnsafeNativeMethods.Rdk_RenderMesh_Mesh(const_pointer); MeshHolder mh = new MeshHolder(this); return(mesh == IntPtr.Zero ? null : new Mesh(mesh, mh)); }
public void addMesh(Mesh mesh, float atPosition) { MeshHolder meshHolder = new MeshHolder(); meshHolder.setAnimationData(mesh); this.animationMeshes.Add(meshHolder); this.animationKeyframes.Add(atPosition); }
/// <summary> /// Get the mesh for the primitive at the specified index. If the item at /// this index is a primitive type other than a mesh then it mesh /// representation is returned. /// </summary> /// <param name="index"> /// The zero based index of the item in the list. Valid values are greater /// than or equal to 0 and less than Count. /// </param> /// <returns> /// Returns the mesh for the primitive at the specified index. If the item /// at this index is a primitive type other than a mesh then it mesh /// representation is returned. /// </returns> public Mesh Mesh(int index) { var const_ptr_mesh = UnsafeNativeMethods.Rdk_CustomMeshes_Mesh(ConstPointer(), index); if (const_ptr_mesh != IntPtr.Zero) { MeshHolder mh = new MeshHolder(this, index); return(new Mesh(const_ptr_mesh, mh)); } return(null); }
// Start is called before the first frame update void Start() { totalMeshes = new List <MeshHolder>(); totalObjects = new List <GameObject>(); for (int i = 0; i < 5; i++) { MeshHolder tempMesh = new MeshHolder(new Vector3(0, i * 3, 0)); tempMesh.shapeMesh = GenerateCircle(2f, tempMesh.verts, tempMesh.offset); totalMeshes.Add(tempMesh); GameObject pieSlice = Instantiate(emptyMesh); pieSlice.transform.position = new Vector3(0, i * 3, 0); totalObjects.Add(pieSlice); //totalMeshes.Add()); } for (int i = 0; i < totalObjects.Count; i++) { totalObjects[i].GetComponent <MeshFilter>().mesh = totalMeshes[i].shapeMesh; } GameObject testWrap1 = Instantiate(emptyMesh); testWrap1.GetComponent <MeshFilter>().mesh = GenerateWrap(totalMeshes[0], totalMeshes[1]); GameObject testWrap2 = Instantiate(emptyMesh); testWrap2.GetComponent <MeshFilter>().mesh = GenerateWrap(totalMeshes[1], totalMeshes[2]); //Set up a holder for the mesh data, vertices, mesh, offset bottomMesh = new MeshHolder(bottom.transform.position); topMesh = new MeshHolder(top.transform.position); //Generate the actual mesh bottomMesh.shapeMesh = GenerateCircle(2f, bottomMesh.verts, bottomMesh.offset); topMesh.shapeMesh = GenerateCircle(5f, topMesh.verts, topMesh.offset); //Set the mesh bottom.GetComponent <MeshFilter>().mesh = bottomMesh.shapeMesh; top.GetComponent <MeshFilter>().mesh = topMesh.shapeMesh; //Set the positions top.transform.position = Vector3.zero; bottom.transform.position = Vector3.zero; //Create the wrapper method wrapObject.GetComponent <MeshFilter>().mesh = GenerateWrap(bottomMesh, topMesh); }
private static void FillPoints(eTypeOFImage typeOfImage, ref MeshHolder[] meshpoints) { string[] s1MeshFiles; s1MeshFiles = Directory.GetFiles(dictPaths[typeOfImage], "*.txt"); meshpoints = new MeshHolder[s1MeshFiles.Length]; for (int jj = 0; jj < s1MeshFiles.Length; jj++) { meshpoints[jj] = new MeshHolder(); meshpoints[jj].meshList = new List <PointOnGrid>(); meshpoints[jj].FileName = s1MeshFiles[jj]; LoadMeshFile(s1MeshFiles[jj], ref meshpoints[jj].meshList); } }
public static void BuildSpritesData(string folderPath) { string folderName = PathHelper.FullAssetPath2Name(folderPath); string spriteDataPath = folderPath + "/" + folderName + "MeshHolder.asset"; string workPath = EditorUtils.AssetsPath2ABSPath(folderPath); var filePaths = Directory.GetFiles(workPath); MeshHolder data = null; data = AssetDatabase.LoadAssetAtPath <MeshHolder>(spriteDataPath); bool needCreate = false; if (data == null) { data = ScriptableObject.CreateInstance <MeshHolder>(); needCreate = true; } data.ClearAllMesh(); for (int i = 0; i < filePaths.Length; ++i) { string relPath = EditorUtils.ABSPath2AssetsPath(filePaths[i]); UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(relPath); if (objs != null) { for (int j = 0; j < objs.Length; ++j) { Log.i(objs[j].GetType().Name); if (objs[j] is Mesh) { data.AddMesh(objs[j] as Mesh); } } } } if (needCreate && !data.isEmpty) { AssetDatabase.CreateAsset(data, spriteDataPath); } EditorUtility.SetDirty(data); AssetDatabase.SaveAssets(); Log.i("Success Process Mesh Import:" + folderPath); }
private void AssignMeshHolder() { if (mesh == null) { mesh = new Mesh(); } if (meshHolder != null) { return; } meshHolder = new GameObject("road_mesh_holder").AddComponent <MeshHolder>().Init(transform); meshHolder.filter.sharedMesh = mesh; }
public void init(Mesh origMesh, bool destroyOld) { originalMesh = origMesh; paintedMesh = Instantiate(origMesh); if (destroyOld) { DestroyImmediate(origMesh); } paintedMesh.hideFlags = HideFlags.None; paintedMesh.name = "vpp_" + gameObject.name; meshHold = new MeshHolder(); meshHold._vertices = paintedMesh.vertices; meshHold._normals = paintedMesh.normals; meshHold._triangles = paintedMesh.triangles; meshHold._TrianglesOfSubs = new trisPerSubmesh[paintedMesh.subMeshCount]; for (int i = 0; i < paintedMesh.subMeshCount; i++) { meshHold._TrianglesOfSubs[i] = new trisPerSubmesh(); meshHold._TrianglesOfSubs[i].triangles = paintedMesh.GetTriangles(i); } meshHold._bindPoses = paintedMesh.bindposes; meshHold._boneWeights = paintedMesh.boneWeights; meshHold._bounds = paintedMesh.bounds; meshHold._subMeshCount = paintedMesh.subMeshCount; meshHold._tangents = paintedMesh.tangents; meshHold._uv = paintedMesh.uv; meshHold._uv2 = paintedMesh.uv2; meshHold._uv3 = paintedMesh.uv3; meshHold._colors = paintedMesh.colors; meshHold._uv4 = paintedMesh.uv4; GetComponent <MeshFilter> ().sharedMesh = paintedMesh; if (GetComponent <MeshCollider> ()) { GetComponent <MeshCollider> ().sharedMesh = paintedMesh; } }
public void showColumn(MeshHolder bot, MeshHolder top) { for (int i = 0; i < bot.verts.Count; i++) { if ((float)i / bot.verts.Count < .33f) { Debug.DrawRay(bot.verts[i], top.verts[i] * 5, Color.red); } else if ((float)i / bot.verts.Count >= .33f && (float)i / bot.verts.Count <= .66f) { Debug.DrawRay(bot.verts[i], top.verts[i] * 5, Color.green); } else { Debug.DrawRay(bot.verts[i], top.verts[i] * 5, Color.blue); } } }
// Use this for initialization void Start() { xDirCount = xAxisSplitter; yDirCount = yAxisSplitter; zDirCount = zAxisSplitter; GenerateSphereRamdomPos(); addToList(); //foreach (GameObject g in list) //{ // g.GetComponent<Renderer>().enabled = false; //} bounds = DrawBoundingBox(list); meshHolder = new MeshHolder(); mesh = new UnityEngine.Mesh(); subBounds = new BoundHolder[xDirCount * yDirCount * zDirCount]; indicator = GameObject.Find("IndicatorObject"); }
public void init(Mesh origMesh, bool destroyOld) { this.originalMesh = origMesh; this.paintedMesh = UnityEngine.Object.Instantiate <Mesh>(origMesh); if (destroyOld) { UnityEngine.Object.DestroyImmediate(origMesh); } this.paintedMesh.hideFlags = HideFlags.None; this.paintedMesh.name = string.Concat("vpp_", base.gameObject.name); this.meshHold = new MeshHolder() { _vertices = this.paintedMesh.vertices, _normals = this.paintedMesh.normals, _triangles = this.paintedMesh.triangles, _TrianglesOfSubs = new trisPerSubmesh[this.paintedMesh.subMeshCount] }; for (int i = 0; i < this.paintedMesh.subMeshCount; i++) { this.meshHold._TrianglesOfSubs[i] = new trisPerSubmesh(); this.meshHold._TrianglesOfSubs[i].triangles = this.paintedMesh.GetTriangles(i); } this.meshHold._bindPoses = this.paintedMesh.bindposes; this.meshHold._boneWeights = this.paintedMesh.boneWeights; this.meshHold._bounds = this.paintedMesh.bounds; this.meshHold._subMeshCount = this.paintedMesh.subMeshCount; this.meshHold._tangents = this.paintedMesh.tangents; this.meshHold._uv = this.paintedMesh.uv; this.meshHold._uv2 = this.paintedMesh.uv2; this.meshHold._uv3 = this.paintedMesh.uv3; this.meshHold._colors = this.paintedMesh.colors; this.meshHold._uv4 = this.paintedMesh.uv4; base.GetComponent <MeshFilter>().sharedMesh = this.paintedMesh; if (base.GetComponent <MeshCollider>()) { base.GetComponent <MeshCollider>().sharedMesh = this.paintedMesh; } }
public void init(Mesh origMesh, bool destroyOld) { this.originalMesh = origMesh; this.paintedMesh = (Mesh)Object.Instantiate <Mesh>((M0)origMesh); if (destroyOld) { Object.DestroyImmediate((Object)origMesh); } ((Object)this.paintedMesh).set_hideFlags((HideFlags)0); ((Object)this.paintedMesh).set_name("vpp_" + ((Object)((Component)this).get_gameObject()).get_name()); this.meshHold = new MeshHolder(); this.meshHold._vertices = this.paintedMesh.get_vertices(); this.meshHold._normals = this.paintedMesh.get_normals(); this.meshHold._triangles = this.paintedMesh.get_triangles(); this.meshHold._TrianglesOfSubs = new trisPerSubmesh[this.paintedMesh.get_subMeshCount()]; for (int index = 0; index < this.paintedMesh.get_subMeshCount(); ++index) { this.meshHold._TrianglesOfSubs[index] = new trisPerSubmesh(); this.meshHold._TrianglesOfSubs[index].triangles = this.paintedMesh.GetTriangles(index); } this.meshHold._bindPoses = this.paintedMesh.get_bindposes(); this.meshHold._boneWeights = this.paintedMesh.get_boneWeights(); this.meshHold._bounds = this.paintedMesh.get_bounds(); this.meshHold._subMeshCount = this.paintedMesh.get_subMeshCount(); this.meshHold._tangents = this.paintedMesh.get_tangents(); this.meshHold._uv = this.paintedMesh.get_uv(); this.meshHold._uv2 = this.paintedMesh.get_uv2(); this.meshHold._uv3 = this.paintedMesh.get_uv3(); this.meshHold._colors = this.paintedMesh.get_colors(); this.meshHold._uv4 = this.paintedMesh.get_uv4(); ((MeshFilter)((Component)this).GetComponent <MeshFilter>()).set_sharedMesh(this.paintedMesh); if (!Object.op_Implicit((Object)((Component)this).GetComponent <MeshCollider>())) { return; } ((MeshCollider)((Component)this).GetComponent <MeshCollider>()).set_sharedMesh(this.paintedMesh); }
private void sortKeyFrames() { if (keyframes == null) { return; } for (int n = keyframes.Count; n > 1; n--) { for (int i = 0; i < n - 1; i++) { if (keyframes[i] > keyframes[i + 1]) { float tempFloat = keyframes [i]; keyframes [i] = keyframes [i + 1]; keyframes [i + 1] = tempFloat; MeshHolder tempMeshHolder = currentGameObject.GetComponent <VertexColorAnimator> ().animationMeshes [i]; currentGameObject.GetComponent <VertexColorAnimator> ().animationMeshes [i] = currentGameObject.GetComponent <VertexColorAnimator> ().animationMeshes [i + 1]; currentGameObject.GetComponent <VertexColorAnimator> ().animationMeshes [i + 1] = tempMeshHolder; } // ende if } // ende innere for-Schleife } }
// Start is called before the first frame update void Start() { totalMeshes = new List <MeshHolder>(); totalObjects = new List <GameObject>(); for (int i = 0; i < 5; i++) { MeshHolder tempMesh = new MeshHolder(new Vector3(0, i * 3, 0)); tempMesh.shapeMesh = GenerateCircle(2 + i % 2, tempMesh.verts, tempMesh.offset); totalMeshes.Add(tempMesh); GameObject pieSlice = Instantiate(emptyMesh); pieSlice.transform.position = new Vector3(0, i * 3, 0); totalObjects.Add(pieSlice); //totalMeshes.Add()); } for (int i = 0; i < totalObjects.Count; i++) { totalObjects[i].GetComponent <MeshFilter>().mesh = totalMeshes[i].shapeMesh; } for (int i = 0; i < totalObjects.Count - 1; i++) { GameObject testWrap = Instantiate(emptyMesh); testWrap.GetComponent <MeshFilter>().mesh = GenerateWrap(totalMeshes[i], totalMeshes[i + 1]); } //GameObject testWrap1 = Instantiate(emptyMesh); //testWrap1.GetComponent<MeshFilter>().mesh = GenerateWrap(totalMeshes[0], totalMeshes[1]); //GameObject testWrap2 = Instantiate(emptyMesh); //testWrap2.GetComponent<MeshFilter>().mesh = GenerateWrap(totalMeshes[1], totalMeshes[2]); }
/// <summary> /// Get the mesh for the primitive at the specified index. If the item at /// this index is a primitive type other than a mesh then it mesh /// representation is returned. /// </summary> /// <param name="index"> /// The zero based index of the item in the list. Valid values are greater /// than or equal to 0 and less than Count. /// </param> /// <returns> /// Returns the mesh for the primitive at the specified index. If the item /// at this index is a primitive type other than a mesh then it mesh /// representation is returned. /// </returns> public Mesh Mesh(int index) { var const_ptr_mesh = UnsafeNativeMethods.Rdk_CustomMeshes_Mesh(ConstPointer(), index); if (const_ptr_mesh != IntPtr.Zero) { MeshHolder mh = new MeshHolder(this, index); return new Mesh(const_ptr_mesh, mh); } return null; }
public Mesh GenerateWrap(MeshHolder bottom, MeshHolder top) { Mesh wrap = new Mesh(); List <Vector3> vertices = new List <Vector3>(); int[] indices = new int[CircleIndexCount * 4]; for (int i = 0; i < CircleVertexCount - 2; i++) { vertices.Add(bottom.verts[i + 1]); vertices.Add(bottom.verts[i + 2]); vertices.Add(top.verts[i + 2]); vertices.Add(top.verts[i + 1]); int j = i * 4; indices[j + 0] = j + 0; indices[j + 1] = j + 1; indices[j + 2] = j + 2; indices[j + 3] = j + 3; } // create new colors array where the colors will be created. Color[] colors = new Color[vertices.Count]; for (int i = 0; i < vertices.Count; i++) { /* * if ((float)i / vertices.Count < .33f) * { * colors[i] = Color.red; * } * else if ((float)i / vertices.Count >= .33f && (float)i / vertices.Count <= .66f) * { * colors[i] = Color.green; * } * else * { * colors[i] = Color.blue; * } */ if ((float)i < (float)vertices.Count * (1f / 3f)) { colors[i] = Color.red; } else if ((float)i >= (float)vertices.Count * (1f / 3f) && (float)i <= (float)vertices.Count * (2f / 3f)) { colors[i] = Color.green; } else { colors[i] = Color.blue; } } wrap.SetVertices(vertices); wrap.SetIndices(indices, MeshTopology.Quads, 0); wrap.colors = colors; wrap.RecalculateBounds(); wrap.RecalculateNormals(); return(wrap); }