public MeshBuilder(MeshTopology topology) { this.meshes = new List<Mesh> (); this.currentIndices = new List<int> (); this.currentVertices = new List<Vector3> (); this.currentUv = new List<Vector2> (); this.currentNormals = new List<Vector3> (); this.topology = topology; }
/// <summary> /// Creates a single view with dimensions x, y, z /// </summary> /// <param name="dobjs"></param> /// <param name="DimensionX"></param> /// <param name="DimensionY"></param> /// <param name="DimensionZ"></param> /// <param name="topology"></param> /// <param name="LinkIndex"> the linking field to create a graph; pass a negative value to ignore</param> /// <returns></returns> public Tuple <GameObject, View> CreateSingle2DView(DataObject dobjs, int DimensionX, int DimensionY, int DimensionZ, int LinkIndex, MeshTopology topology, Material m, bool parallel = false) { // @todo remove the parallel bool for a better implementation string viewName = ""; if (DimensionX >= 0) { viewName += dobjs.indexToDimension(DimensionX) + "-"; } if (DimensionY >= 0) { viewName += dobjs.indexToDimension(DimensionY) + "-"; } if (DimensionZ >= 0) { viewName += dobjs.indexToDimension(DimensionZ); } MeshTopology mtp; if (LinkIndex > 0) { mtp = MeshTopology.Lines; //double the } else { mtp = MeshTopology.Points; } View v = new View(mtp, viewName); GameObject view = new GameObject(viewName); //view.transform.parent = transform; if (!parallel) { v.initialiseDataView(dobjs.DataPoints, view); if (DimensionX >= 0) { float[] xpts = dobjs.getDimension(DimensionX); v.setDataDimension(xpts, View.VIEW_DIMENSION.X); } if (DimensionY >= 0) { v.setDataDimension(dobjs.getDimension(DimensionY), View.VIEW_DIMENSION.Y); } if (DimensionZ >= 0) { v.setDataDimension(dobjs.getDimension(DimensionZ), View.VIEW_DIMENSION.Z); } } else { if (DimensionX >= 0 && DimensionY >= 0) { v.initialiseDataView(dobjs.DataPoints * 2, view); List <float> data = new List <float>(); List <float> range = new List <float>(); float[] dimx = dobjs.getDimension(DimensionX); float[] dimy = dobjs.getDimension(DimensionY); for (int i = 0; i < dobjs.DataPoints; i++) { data.Add(dimx[i]); data.Add(dimy[i]); range.Add(-1); range.Add(1); } v.setDataDimension(data.ToArray(), View.VIEW_DIMENSION.Y); v.setDataDimension(range.ToArray(), View.VIEW_DIMENSION.X); } } if (LinkIndex < 0) { v.updateView(null); } else { v.updateView(dobjs.getDimension(LinkIndex)); } view.AddComponent <MeshFilter>(); view.AddComponent <MeshRenderer>(); view.GetComponent <MeshFilter>().mesh = v.MyMesh; view.GetComponent <Renderer>().material = m; return(new Tuple <GameObject, View>(view, v)); }
/// <summary> Apply to the mesh with given policy </summary> public void Apply(Mesh m, VertexProfiles profile, MeshTopology topology = MeshTopology.Triangles) { m.Clear(); if (m_Verts.Count == 0) { return; } #if !(UNITY_5 || UNITY_2017_1 || UNITY_2017_2) if (m_Verts.Count >= 0xFFFF) { m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } #endif m.SetVertices(m_Verts); m.subMeshCount = m_Tris.Count; for (int i = 0; i < m_Tris.Count; i++) { if (topology == MeshTopology.Triangles) { m.SetTriangles(m_Tris[i], i, false); } else { Reflected.SetIndices(m, m_Tris[i], topology, i, false); } } m.RecalculateBounds(); if (topology <= MeshTopology.Quads) { m.RecalculateNormals(); m.RecalculateTangents(); if (profile > 0) { var uv = (int)profile; if ((uv & 1) > 0) { m.SetUVs(0, m_Uv0); } if ((uv & 2) > 0) { m.SetUVs(1, m_Uv2); } if ((uv & 4) > 0) { m.SetUVs(2, m_Uv3); } } } if ((profile & VertexProfiles.Color) > 0) { m.SetColors(m_Colors); } }
extern private static void Internal_DrawProceduralIndirect(MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset);
public static extern void DrawProceduralIndirect(MeshTopology topology, ComputeBuffer bufferWithArgs, [DefaultValue("0")] int argsOffset);
public static void DrawProcedural(MeshTopology topology, int vertexCount){}
private static extern void INTERNAL_CALL_DrawProcedural(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount, MaterialPropertyBlock properties);
public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset, MaterialPropertyBlock properties) { if (material == null) { throw new ArgumentNullException("material"); } if (bufferWithArgs == null) { throw new ArgumentNullException("bufferWithArgs"); } ValidateAgainstExecutionFlags(CommandBufferExecutionFlags.None, CommandBufferExecutionFlags.AsyncCompute); Internal_DrawProceduralIndirect(matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, properties); }
public void SetIndices(int[] indices, MeshTopology meshTopology) { Indices = indices; MeshTopology = meshTopology; viewMesh.SetIndices(Indices, MeshTopology, 0); }
public SubMesh(int indexOffset, int indexCount, MeshTopology topology = MeshTopology.TriangleList) { IndexOffset = indexOffset; IndexCount = indexCount; Topology = topology; }
/// <summary> /// Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described /// by the mesh data exactly. Mesh will have no sub-meshes. /// </summary> /// <param name="data">Vertex and index data to initialize the mesh with.</param> /// <param name="topology">Determines how should the provided indices be interpreted by the pipeline. Default option /// is a triangle list, where three indices represent a single triangle.</param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> public Mesh(MeshData data, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Default) { int numIndices = 0; IntPtr dataPtr = IntPtr.Zero; if (data != null) { numIndices = data.IndexCount; dataPtr = data.GetCachedPtr(); } SubMesh[] subMeshes = { new SubMesh(0, numIndices, topology) }; Internal_CreateInstanceMeshData(this, dataPtr, subMeshes, usage); }
/// <summary> /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. All indices /// will be part of a single sub-mesh. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices">Number of indices in the mesh. </param> /// <param name="topology">Determines how should the provided indices be interpreted by the pipeline. Default option /// is a triangle list, where three indices represent a single triangle.</param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index">Size of indices, use smaller size for better performance, however be careful not to go over /// the number of vertices limited by the size.</param> public Mesh(int numVertices, int numIndices, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Default, VertexType vertex = VertexType.Position, IndexType index = IndexType.Index32) { SubMesh[] subMeshes = {new SubMesh(0, numIndices, topology)}; Internal_CreateInstance(this, numVertices, numIndices, subMeshes, usage, vertex, index); }
public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, [DefaultValue("0")] int argsOffset, [DefaultValue("null")] MaterialPropertyBlock properties) { INTERNAL_CALL_DrawProceduralIndirect(this, ref matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, properties); }
public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount, MaterialPropertyBlock properties) { if (material == null) { throw new ArgumentNullException("material"); } ValidateAgainstExecutionFlags(CommandBufferExecutionFlags.None, CommandBufferExecutionFlags.AsyncCompute); Internal_DrawProcedural(matrix, material, shaderPass, topology, vertexCount, instanceCount, properties); }
public void CreateView(Vector3[] vertices, int[] indices, Color[] colours, Vector3[] normals, Vector4[] uv0, MeshTopology meshTopology, Material material) { // Store variables MeshTopology = meshTopology; Vertices = vertices; Indices = indices; Colours = colours; Normals = normals; UV0 = uv0; Material = material; // Create mesh viewMesh = new Mesh(); viewMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; viewMesh.MarkDynamic(); viewMesh.SetVertices(Vertices); viewMesh.SetIndices(Indices, MeshTopology, 0); viewMesh.SetColors(Colours); viewMesh.SetNormals(Normals); viewMesh.SetUVs(0, UV0); viewMesh.SetUVs(1, Vertices); viewMesh.SetUVs(2, Array.ConvertAll(Colours, x => (Vector4)x)); // Assign mesh viewMeshFilter = gameObject.GetComponent <MeshFilter>(); if (viewMeshFilter == null) { viewMeshFilter = gameObject.AddComponent <MeshFilter>(); } viewMeshRenderer = gameObject.GetComponent <MeshRenderer>(); if (viewMeshRenderer == null) { viewMeshRenderer = gameObject.AddComponent <MeshRenderer>(); } viewMeshFilter.mesh = viewMesh; viewMeshRenderer.material = material; viewMesh.RecalculateBounds(); }
public void DrawProcedural(GraphicsBuffer indexBuffer, Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int indexCount, int instanceCount, MaterialPropertyBlock properties) { if (indexBuffer == null) { throw new ArgumentNullException("indexBuffer"); } if (material == null) { throw new ArgumentNullException("material"); } Internal_DrawProceduralIndexed(indexBuffer, matrix, material, shaderPass, topology, indexCount, instanceCount, properties); }
/// <summary> /// Upload the inputData (mesh geometry) into the input node with inputNodeID. /// </summary> /// <param name="session">Session that the input node exists in</param> /// <param name="inputNodeID">ID of the input node</param> /// <param name="inputData">Container of the mesh geometry</param> /// <returns>True if successfully uploaded data</returns> public bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputData inputData) { HEU_InputDataMeshes inputDataMeshes = inputData as HEU_InputDataMeshes; if (inputDataMeshes == null) { Debug.LogError("Expected HEU_InputDataMeshes type for inputData, but received unsupported type."); return false; } List<Vector3> vertices = new List<Vector3>(); List<Vector3> normals = new List<Vector3>(); List<Vector2> uvs = new List<Vector2>(); List<Color> colors = new List<Color>(); List<int> pointIndexList = new List<int>(); List<int> vertIndexList = new List<int>(); int numMaterials = 0; int numMeshes = inputDataMeshes._inputMeshes.Count; // Get the parent's world transform, so when there are multiple child meshes, // can merge and apply their local transform after subtracting their parent's world transform Matrix4x4 rootInvertTransformMatrix = Matrix4x4.identity; if (numMeshes > 1) { rootInvertTransformMatrix = inputDataMeshes._inputObject.transform.worldToLocalMatrix; } // Always using the first submesh topology. This doesn't support mixed topology (triangles and quads). MeshTopology meshTopology = inputDataMeshes._inputMeshes[0]._mesh.GetTopology(0); int numVertsPerFace = 3; if (meshTopology == MeshTopology.Quads) { numVertsPerFace = 4; } // For all meshes: // Accumulate vertices, normals, uvs, colors, and indices. // Keep track of indices start and count for each mesh for later when uploading material assignments and groups. // Find shared vertices, and use unique set of vertices to use as point positions. // Need to reindex indices for both unique vertices, as well as vertex attributes. for (int i = 0; i < numMeshes; ++i) { Vector3[] meshVertices = inputDataMeshes._inputMeshes[i]._mesh.vertices; Matrix4x4 localToWorld = rootInvertTransformMatrix * inputDataMeshes._inputMeshes[i]._transform.localToWorldMatrix; List<Vector3> uniqueVertices = new List<Vector3>(); // Keep track of old vertex positions (old vertex slot points to new unique vertex slot) int[] reindexVertices = new int[meshVertices.Length]; Dictionary<Vector3, int> reindexMap = new Dictionary<Vector3, int>(); // For each vertex, check against subsequent vertices for shared positions. for (int a = 0; a < meshVertices.Length; ++a) { Vector3 va = meshVertices[a]; if (!reindexMap.ContainsKey(va)) { if (numMeshes > 1 && !inputDataMeshes._hasLOD) { // For multiple meshes that are not LODs, apply local transform on vertices to get the merged mesh. uniqueVertices.Add(localToWorld.MultiplyPoint(va)); } else { uniqueVertices.Add(va); } // Reindex to point to unique vertex slot reindexVertices[a] = uniqueVertices.Count - 1; reindexMap[va] = uniqueVertices.Count - 1; } else { reindexVertices[a] = reindexMap[va]; } } int vertexOffset = vertices.Count; vertices.AddRange(uniqueVertices); Vector3[] meshNormals = inputDataMeshes._inputMeshes[i]._mesh.normals; Vector2[] meshUVs = inputDataMeshes._inputMeshes[i]._mesh.uv; Color[] meshColors = inputDataMeshes._inputMeshes[i]._mesh.colors; inputDataMeshes._inputMeshes[i]._indexStart = new uint[inputDataMeshes._inputMeshes[i]._numSubMeshes]; inputDataMeshes._inputMeshes[i]._indexCount = new uint[inputDataMeshes._inputMeshes[i]._numSubMeshes]; // For each submesh: // Generate face to point index -> pointIndexList // Generate face to vertex attribute index -> vertIndexList for (int j = 0; j < inputDataMeshes._inputMeshes[i]._numSubMeshes; ++j) { int indexStart = pointIndexList.Count; int vertIndexStart = vertIndexList.Count; // Indices have to be re-indexed with our own offset // (using GetIndices to generalize triangles and quad indices) int[] meshIndices = inputDataMeshes._inputMeshes[i]._mesh.GetIndices(j); int numIndices = meshIndices.Length; for (int k = 0; k < numIndices; ++k) { int originalIndex = meshIndices[k]; meshIndices[k] = reindexVertices[originalIndex]; pointIndexList.Add(vertexOffset + meshIndices[k]); vertIndexList.Add(vertIndexStart + k); if (meshNormals != null && (originalIndex < meshNormals.Length)) { normals.Add(meshNormals[originalIndex]); } if (meshUVs != null && (originalIndex < meshUVs.Length)) { uvs.Add(meshUVs[originalIndex]); } if (meshColors != null && (originalIndex < meshColors.Length)) { colors.Add(meshColors[originalIndex]); } } inputDataMeshes._inputMeshes[i]._indexStart[j] = (uint)indexStart; inputDataMeshes._inputMeshes[i]._indexCount[j] = (uint)(pointIndexList.Count) - inputDataMeshes._inputMeshes[i]._indexStart[j]; } numMaterials += inputDataMeshes._inputMeshes[i]._materials != null ? inputDataMeshes._inputMeshes[i]._materials.Length : 0; } // It is possible for some meshes to not have normals/uvs/colors while others do. // In the case where an attribute is missing on some meshes, we clear out those attributes so we don't upload // partial attribute data. int totalAllVertexCount = vertIndexList.Count; if (normals.Count != totalAllVertexCount) { normals = null; } if (uvs.Count != totalAllVertexCount) { uvs = null; } if (colors.Count != totalAllVertexCount) { colors = null; } HAPI_PartInfo partInfo = new HAPI_PartInfo(); partInfo.faceCount = vertIndexList.Count / numVertsPerFace; partInfo.vertexCount = vertIndexList.Count; partInfo.pointCount = vertices.Count; partInfo.pointAttributeCount = 1; partInfo.vertexAttributeCount = 0; partInfo.primitiveAttributeCount = 0; partInfo.detailAttributeCount = 0; //Debug.LogFormat("Faces: {0}; Vertices: {1}; Verts/Face: {2}", partInfo.faceCount, partInfo.vertexCount, numVertsPerFace); if (normals != null && normals.Count > 0) { partInfo.vertexAttributeCount++; } if (uvs != null && uvs.Count > 0) { partInfo.vertexAttributeCount++; } if (colors != null && colors.Count > 0) { partInfo.vertexAttributeCount++; } if (numMaterials > 0) { partInfo.primitiveAttributeCount++; } if (numMeshes > 0) { partInfo.primitiveAttributeCount++; } if (inputDataMeshes._hasLOD) { partInfo.primitiveAttributeCount++; partInfo.detailAttributeCount++; } HAPI_GeoInfo displayGeoInfo = new HAPI_GeoInfo(); if (!session.GetDisplayGeoInfo(inputNodeID, ref displayGeoInfo)) { return false; } HAPI_NodeId displayNodeID = displayGeoInfo.nodeId; if (!session.SetPartInfo(displayNodeID, 0, ref partInfo)) { Debug.LogError("Failed to set input part info. "); return false; } int[] faceCounts = new int[partInfo.faceCount]; for (int i = 0; i < partInfo.faceCount; ++i) { faceCounts[i] = numVertsPerFace; } int[] faceIndices = pointIndexList.ToArray(); if (!HEU_GeneralUtility.SetArray2Arg(displayNodeID, 0, session.SetFaceCount, faceCounts, 0, partInfo.faceCount)) { Debug.LogError("Failed to set input geometry face counts."); return false; } if (!HEU_GeneralUtility.SetArray2Arg(displayNodeID, 0, session.SetVertexList, faceIndices, 0, partInfo.vertexCount)) { Debug.LogError("Failed to set input geometry indices."); return false; } if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_POSITION, 3, vertices.ToArray(), ref partInfo, true)) { Debug.LogError("Failed to set input geometry position."); return false; } int[] vertIndices = vertIndexList.ToArray(); //if(normals != null && !SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_NORMAL, 3, normals.ToArray(), ref partInfo, true)) if (normals != null && !HEU_InputMeshUtility.SetMeshVertexAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_NORMAL, 3, normals.ToArray(), vertIndices, ref partInfo, true)) { Debug.LogError("Failed to set input geometry normals."); return false; } if (uvs != null && uvs.Count > 0) { Vector3[] uvs3 = new Vector3[uvs.Count]; for (int i = 0; i < uvs.Count; ++i) { uvs3[i][0] = uvs[i][0]; uvs3[i][1] = uvs[i][1]; uvs3[i][2] = 0; } //if(!SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_UV, 3, uvs3, ref partInfo, false)) if (!HEU_InputMeshUtility.SetMeshVertexAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_UV, 3, uvs3, vertIndices, ref partInfo, false)) { Debug.LogError("Failed to set input geometry UVs."); return false; } } if (colors != null && colors.Count > 0) { Vector3[] rgb = new Vector3[colors.Count]; float[] alpha = new float[colors.Count]; for (int i = 0; i < colors.Count; ++i) { rgb[i][0] = colors[i].r; rgb[i][1] = colors[i].g; rgb[i][2] = colors[i].b; alpha[i] = colors[i].a; } //if(!SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_COLOR, 3, rgb, ref partInfo, false)) if (!HEU_InputMeshUtility.SetMeshVertexAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_COLOR, 3, rgb, vertIndices, ref partInfo, false)) { Debug.LogError("Failed to set input geometry colors."); return false; } //if(!SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_ALPHA, 1, alpha, ref partInfo, false)) if (!HEU_InputMeshUtility.SetMeshVertexFloatAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_ALPHA, 1, alpha, vertIndices, ref partInfo)) { Debug.LogError("Failed to set input geometry color alpha."); return false; } } // Set material names for round-trip perservation of material assignment // Each HEU_UploadMeshData might have a list of submeshes and materials // These are all combined into a single mesh, with group names if (numMaterials > 0) { bool bFoundAtleastOneValidMaterial = false; string[] materialIDs = new string[partInfo.faceCount]; for (int g = 0; g < inputDataMeshes._inputMeshes.Count; ++g) { if (inputDataMeshes._inputMeshes[g]._numSubMeshes != inputDataMeshes._inputMeshes[g]._materials.Length) { // Number of submeshes should equal number of materials since materials determine submeshes continue; } for (int i = 0; i < inputDataMeshes._inputMeshes[g]._materials.Length; ++i) { string materialName = HEU_AssetDatabase.GetAssetPathWithSubAssetSupport(inputDataMeshes._inputMeshes[g]._materials[i]); if (materialName == null) { materialName = ""; } else if (materialName.StartsWith(HEU_Defines.DEFAULT_UNITY_BUILTIN_RESOURCES)) { materialName = HEU_AssetDatabase.GetUniqueAssetPathForUnityAsset(inputDataMeshes._inputMeshes[g]._materials[i]); } bFoundAtleastOneValidMaterial |= !string.IsNullOrEmpty(materialName); int faceStart = (int)inputDataMeshes._inputMeshes[g]._indexStart[i] / numVertsPerFace; int faceEnd = faceStart + ((int)inputDataMeshes._inputMeshes[g]._indexCount[i] / numVertsPerFace); for (int m = faceStart; m < faceEnd; ++m) { materialIDs[m] = materialName; } } } if (bFoundAtleastOneValidMaterial) { HAPI_AttributeInfo materialIDAttrInfo = new HAPI_AttributeInfo(); materialIDAttrInfo.exists = true; materialIDAttrInfo.owner = HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM; materialIDAttrInfo.storage = HAPI_StorageType.HAPI_STORAGETYPE_STRING; materialIDAttrInfo.count = partInfo.faceCount; materialIDAttrInfo.tupleSize = 1; materialIDAttrInfo.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID; if (!session.AddAttribute(displayNodeID, 0, HEU_PluginSettings.UnityMaterialAttribName, ref materialIDAttrInfo)) { Debug.LogError("Failed to add input geometry unity material name attribute."); return false; } if (!HEU_GeneralUtility.SetAttributeArray(displayNodeID, 0, HEU_PluginSettings.UnityMaterialAttribName, ref materialIDAttrInfo, materialIDs, session.SetAttributeStringData, partInfo.faceCount)) { Debug.LogError("Failed to set input geometry unity material name."); return false; } } } // Set mesh name attribute HAPI_AttributeInfo attrInfo = new HAPI_AttributeInfo(); attrInfo.exists = true; attrInfo.owner = HAPI_AttributeOwner.HAPI_ATTROWNER_PRIM; attrInfo.storage = HAPI_StorageType.HAPI_STORAGETYPE_STRING; attrInfo.count = partInfo.faceCount; attrInfo.tupleSize = 1; attrInfo.originalOwner = HAPI_AttributeOwner.HAPI_ATTROWNER_INVALID; if (session.AddAttribute(displayNodeID, 0, HEU_PluginSettings.UnityInputMeshAttr, ref attrInfo)) { string[] primitiveNameAttr = new string[partInfo.faceCount]; for (int g = 0; g < inputDataMeshes._inputMeshes.Count; ++g) { for (int i = 0; i < inputDataMeshes._inputMeshes[g]._numSubMeshes; ++i) { int faceStart = (int)inputDataMeshes._inputMeshes[g]._indexStart[i] / numVertsPerFace; int faceEnd = faceStart + ((int)inputDataMeshes._inputMeshes[g]._indexCount[i] / numVertsPerFace); for (int m = faceStart; m < faceEnd; ++m) { primitiveNameAttr[m] = inputDataMeshes._inputMeshes[g]._meshPath; } } } if (!HEU_GeneralUtility.SetAttributeArray(displayNodeID, 0, HEU_PluginSettings.UnityInputMeshAttr, ref attrInfo, primitiveNameAttr, session.SetAttributeStringData, partInfo.faceCount)) { Debug.LogError("Failed to set input geometry unity mesh name."); return false; } } else { return false; } // Set LOD group membership if (inputDataMeshes._hasLOD) { int[] membership = new int[partInfo.faceCount]; for (int g = 0; g < inputDataMeshes._inputMeshes.Count; ++g) { if (g > 0) { // Clear array for (int m = 0; m < partInfo.faceCount; ++m) { membership[m] = 0; } } // Set 1 for faces belonging to this group for (int s = 0; s < inputDataMeshes._inputMeshes[g]._numSubMeshes; ++s) { int faceStart = (int)inputDataMeshes._inputMeshes[g]._indexStart[s] / numVertsPerFace; int faceEnd = faceStart + ((int)inputDataMeshes._inputMeshes[g]._indexCount[s] / numVertsPerFace); for (int m = faceStart; m < faceEnd; ++m) { membership[m] = 1; } } if (!session.AddGroup(displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_PRIM, inputDataMeshes._inputMeshes[g]._meshName)) { Debug.LogError("Failed to add input geometry LOD group name."); return false; } if (!session.SetGroupMembership(displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_PRIM, inputDataMeshes._inputMeshes[g]._meshName, membership, 0, partInfo.faceCount)) { Debug.LogError("Failed to set input geometry LOD group name."); return false; } } } return session.CommitGeo(displayNodeID); }
/// <summary> /// <para>Add a "draw procedural geometry" command.</para> /// </summary> /// <param name="matrix">Transformation matrix to use.</param> /// <param name="material">Material to use.</param> /// <param name="shaderPass">Which pass of the shader to use (or -1 for all passes).</param> /// <param name="topology">Topology of the procedural geometry.</param> /// <param name="vertexCount">Vertex count to render.</param> /// <param name="instanceCount">Instance count to render.</param> /// <param name="properties">Additional material properties to apply just before rendering. See MaterialPropertyBlock.</param> public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, [DefaultValue("1")] int instanceCount, [DefaultValue("null")] MaterialPropertyBlock properties) { CommandBuffer.INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties); }
private static extern void Internal_create(Mesh managedInstance, int numVertices, int numIndices, MeshTopology topology, MeshUsage usage, VertexLayout vertex, IndexType index);
private static extern void INTERNAL_CALL_DrawProceduralIndirect(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset, MaterialPropertyBlock properties);
private static extern void Internal_create1(Mesh managedInstance, MeshData data, MeshTopology topology, MeshUsage usage);
public static extern void DrawProcedural(MeshTopology topology, int vertexCount, [DefaultValue("1")] int instanceCount);
/// <summary> /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. All indices will /// be part of a single sub-mesh. /// </summary> /// <param name="numVertices">Number of vertices in the mesh.</param> /// <param name="numIndices"> /// Number of indices in the mesh. Must be a multiple of primitive size as specified by provided topology. /// </param> /// <param name="topology"> /// Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where /// three indices represent a single triangle. /// </param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> /// <param name="vertex">Controls how are vertices organized in the vertex buffer and what data they contain.</param> /// <param name="index"> /// Size of indices, use smaller size for better performance, however be careful not to go over the number of vertices /// limited by the data type size. /// </param> public Mesh(int numVertices, int numIndices, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Static, VertexLayout vertex = VertexLayout.Position, IndexType index = IndexType.Index32) { Internal_create(this, numVertices, numIndices, topology, usage, vertex, index); }
public extern void SetIndices(int[] indices, MeshTopology topology, int submesh);
/// <summary> /// Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described by the /// mesh data exactly. Mesh will have no sub-meshes. /// </summary> /// <param name="data">Vertex and index data to initialize the mesh with.</param> /// <param name="topology"> /// Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where /// three indices represent a single triangle. /// </param> /// <param name="usage">Optimizes performance depending on planned usage of the mesh.</param> public Mesh(MeshData data, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Static) { Internal_create1(this, data, topology, usage); }
private static void uploadMeshFilter(List <Vector3> tempVertices, List <int> tempIndices, MeshGroup[] groups, float[] vertices, int[] indices, ref int vertexOffset, ref int indexOffset, ref int groupOffset, Mesh mesh, ONSPPropagationMaterial[] materials, Matrix4x4 matrix) { // Get the mesh vertices. tempVertices.Clear(); mesh.GetVertices(tempVertices); // Copy the Vector3 vertices into a packed array of floats for the API. int meshVertexCount = tempVertices.Count; for (int i = 0; i < meshVertexCount; i++) { // Transform into the parent space. Vector3 v = matrix.MultiplyPoint3x4(tempVertices[i]); int offset = (vertexOffset + i) * 3; vertices[offset + 0] = v.x; vertices[offset + 1] = v.y; vertices[offset + 2] = v.z; } // Copy the data for each submesh. for (int i = 0; i < mesh.subMeshCount; i++) { MeshTopology topology = mesh.GetTopology(i); if (topology == MeshTopology.Triangles || topology == MeshTopology.Quads) { // Get the submesh indices. tempIndices.Clear(); mesh.GetIndices(tempIndices, i); int subMeshIndexCount = tempIndices.Count; // Copy and adjust the indices. for (int j = 0; j < subMeshIndexCount; j++) { indices[indexOffset + j] = tempIndices[j] + vertexOffset; } // Initialize the group. if (topology == MeshTopology.Triangles) { groups[groupOffset + i].faceType = FaceType.TRIANGLES; groups[groupOffset + i].faceCount = (UIntPtr)(subMeshIndexCount / 3); } else if (topology == MeshTopology.Quads) { groups[groupOffset + i].faceType = FaceType.QUADS; groups[groupOffset + i].faceCount = (UIntPtr)(subMeshIndexCount / 4); } groups[groupOffset + i].indexOffset = (UIntPtr)indexOffset; if (materials != null && materials.Length != 0) { int matIndex = i; if (matIndex >= materials.Length) { matIndex = materials.Length - 1; } materials[matIndex].StartInternal(); groups[groupOffset + i].material = materials[matIndex].materialHandle; } else { groups[groupOffset + i].material = IntPtr.Zero; } indexOffset += subMeshIndexCount; } } vertexOffset += meshVertexCount; groupOffset += mesh.subMeshCount; }
public static void quick_test_2() { DMesh3 target = TestUtil.LoadTestInputMesh("cylinder_orig.obj"); DMeshAABBTree3 targetSpatial = new DMeshAABBTree3(target, true); DMesh3 mesh = TestUtil.LoadTestInputMesh("cylinder_approx.obj"); DMeshAABBTree3 meshSpatial = new DMeshAABBTree3(mesh, true); double search_dist = 10.0; MeshTopology topo = new MeshTopology(target); topo.Compute(); RemesherPro r = new RemesherPro(mesh); r.SetTargetEdgeLength(2.0); r.SmoothSpeedT = 0.5; r.SetProjectionTarget(MeshProjectionTarget.Auto(target)); MeshConstraints cons = new MeshConstraints(); r.SetExternalConstraints(cons); int set_id = 1; foreach (var loop in topo.Loops) { DCurveProjectionTarget curveTarget = new DCurveProjectionTarget(loop.ToCurve(target)); set_id++; // pick a set of points we will find paths between. We will chain // up those paths and constrain them to target loops. // (this part is the hack!) List <int> target_verts = new List <int>(); List <int> mesh_verts = new List <int>(); for (int k = 0; k < loop.VertexCount; k += 5) { target_verts.Add(loop.Vertices[k]); Vector3d vCurve = target.GetVertex(loop.Vertices[k]); int mesh_vid = meshSpatial.FindNearestVertex(vCurve, search_dist); mesh_verts.Add(mesh_vid); } int NT = target_verts.Count; // find the paths to assemble the edge chain // [TODO] need to filter out junction vertices? or will they just handle themselves // because they can be collapsed away? List <int> vert_seq = new List <int>(); for (int k = 0; k < NT; k++) { EdgeSpan e = find_edge_path(mesh, mesh_verts[k], mesh_verts[(k + 1) % NT]); int n = e.Vertices.Length; for (int i = 0; i < n - 1; ++i) { vert_seq.Add(e.Vertices[i]); } } // now it's easy, just add the loop constraint EdgeLoop full_loop = EdgeLoop.FromVertices(mesh, vert_seq); MeshConstraintUtil.ConstrainVtxLoopTo(cons, mesh, full_loop.Vertices, curveTarget, set_id); } r.FastestRemesh(); TestUtil.WriteTestOutputMesh(mesh, "curves_test_out.obj"); }
public SubMesh(uint indexOffset, uint indexCount, MeshTopology drawOp) { this.indexOffset = indexOffset; this.indexCount = indexCount; this.drawOp = drawOp; }
void OnGUI() { GUILayout.BeginHorizontal(); { obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject), true); if (obj == null) { mesh = null; SMR = null; } else if (obj.GetComponent <MeshFilter>() && (mesh == null || obj != oldObject)) { SMR = null; mesh = obj.GetComponent <MeshFilter>().sharedMesh; topo = mesh.GetTopology(0); } else if (obj.GetComponent <SkinnedMeshRenderer>() && (mesh == null || obj != oldObject)) { SMR = obj.GetComponent <SkinnedMeshRenderer>(); mesh = SMR.sharedMesh; topo = mesh.GetTopology(0); } oldObject = obj; linkScroll = GUILayout.Toggle(linkScroll, "Link scroll bars"); GUILayout.Label("Mesh Topology: ", GUILayout.Width(92)); topo = (MeshTopology)EditorGUILayout.EnumPopup(topo); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { showVerts = GUILayout.Toggle(showVerts, "Show Vertices"); showNorm = GUILayout.Toggle(showNorm, "Show Normals"); showTangents = GUILayout.Toggle(showTangents, "Show Tangents"); showIndices = GUILayout.Toggle(showIndices, "Show Indices"); showUVs = GUILayout.Toggle(showUVs, "Show UVs"); showUV2s = GUILayout.Toggle(showUV2s, "Show UV2s"); showBoneWeights = GUILayout.Toggle(showBoneWeights, "Show BoneWeights"); showBindPoses = GUILayout.Toggle(showBindPoses, "Show BindPoses"); showBones = GUILayout.Toggle(showBones, "Show Bones"); } GUILayout.EndHorizontal(); if (mesh) { GUILayout.BeginHorizontal(); { if (showVerts) { BeginScroll(ref vertScroll); vertices = mesh.vertices; for (int i = 0; i < mesh.vertexCount && i < MAX_DISPLAY; i++) { vertices[i] = EditorGUILayout.Vector3Field(i + ":", vertices[i]); } mesh.vertices = vertices; GUILayout.EndScrollView(); } if (showNorm) { BeginScroll(ref normScroll); normals = mesh.normals; for (int i = 0; i < mesh.normals.Length && i < MAX_DISPLAY; i++) { normals[i] = EditorGUILayout.Vector3Field(i + ":", normals[i]); } mesh.normals = normals; GUILayout.EndScrollView(); } if (showTangents) { BeginScroll(ref tangentScroll); tangents = mesh.tangents; for (int i = 0; i < mesh.tangents.Length && i < MAX_DISPLAY; i++) { tangents[i] = EditorGUILayout.Vector3Field(i + ":", tangents[i]); } mesh.tangents = tangents; GUILayout.EndScrollView(); } if (showBoneWeights) { BeginScroll(ref boneWeightScroll); boneWeights = mesh.boneWeights; for (int i = 0; i < mesh.boneWeights.Length && i < MAX_DISPLAY; i++) { GUILayout.Label(i + ":"); boneWeights[i].boneIndex0 = EditorGUILayout.IntField("Bone 0 idx: ", boneWeights[i].boneIndex0); boneWeights[i].boneIndex1 = EditorGUILayout.IntField("Bone 1 idx: ", boneWeights[i].boneIndex1); boneWeights[i].boneIndex2 = EditorGUILayout.IntField("Bone 2 idx: ", boneWeights[i].boneIndex2); boneWeights[i].boneIndex3 = EditorGUILayout.IntField("Bone 3 idx: ", boneWeights[i].boneIndex3); boneWeights[i].weight0 = EditorGUILayout.FloatField("Bone 0 Weight: ", boneWeights[i].weight0); boneWeights[i].weight1 = EditorGUILayout.FloatField("Bone 1 Weight: ", boneWeights[i].weight1); boneWeights[i].weight2 = EditorGUILayout.FloatField("Bone 2 Weight: ", boneWeights[i].weight2); boneWeights[i].weight3 = EditorGUILayout.FloatField("Bone 3 Weight: ", boneWeights[i].weight3); } //mesh.boneWeights = boneWeights; GUILayout.EndScrollView(); } if (showIndices) { BeginScroll(ref triScroll); triangles = mesh.GetIndices(0); int jump = 1; switch (topo) { case MeshTopology.Quads: jump = 4; break; case MeshTopology.Triangles: jump = 3; break; case MeshTopology.Lines: jump = 2; break; } for (int i = 0; i < triangles.Length && i < MAX_DISPLAY; i += jump) { GUILayout.BeginHorizontal(); { triangles[i] = EditorGUILayout.IntField(i + ":", triangles[i]); if (topo == MeshTopology.Lines || topo == MeshTopology.Triangles || topo == MeshTopology.Quads) { triangles[i + 1] = EditorGUILayout.IntField(i + 1 + ":", triangles[i + 1]); } if (topo == MeshTopology.Triangles || topo == MeshTopology.Quads) { triangles[i + 2] = EditorGUILayout.IntField(i + 2 + ":", triangles[i + 2]); } if (topo == MeshTopology.Quads) { triangles[i + 3] = EditorGUILayout.IntField(i + 3 + ":", triangles[i + 3]); } } GUILayout.EndHorizontal(); } mesh.SetIndices(triangles, topo, 0); GUILayout.EndScrollView(); } if (showUVs) { BeginScroll(ref UVScroll); uv = mesh.uv; for (int i = 0; i < mesh.uv.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { uv[i] = EditorGUILayout.Vector2Field(i + ":", uv[i]); } GUILayout.EndHorizontal(); } mesh.uv = uv; GUILayout.EndScrollView(); } if (showUV2s) { BeginScroll(ref UV2Scroll); uv2 = mesh.uv2; for (int i = 0; i < mesh.uv2.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { uv2[i] = EditorGUILayout.Vector2Field(i + ":", uv2[i]); } GUILayout.EndHorizontal(); } mesh.uv2 = uv2; GUILayout.EndScrollView(); } if (showBindPoses) { BeginScroll(ref bindPoseScroll); bindPoses = mesh.bindposes; for (int i = 0; i < bindPoses.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { Matrix4x4Field(i + ":", ref bindPoses[i]); } GUILayout.EndHorizontal(); } mesh.bindposes = bindPoses; GUILayout.EndScrollView(); } if (SMR && showBones) { BeginScroll(ref boneWeightScroll); bones = SMR.bones; for (int i = 0; i < bones.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { bones[i] = EditorGUILayout.ObjectField(bones[i], typeof(Transform)) as Transform; } GUILayout.EndHorizontal(); } SMR.bones = bones; GUILayout.EndScrollView(); } } GUILayout.EndHorizontal(); } }
public virtual void initSlice(int t, int depth, Vector3 [] sPoints, Vector3 [] pPoints, int [] indices, Color [] colors, MeshTopology meshTopology) { pointGroups [t][depth] = new GameObject(); pointGroups [t][depth].AddComponent <MeshFilter> (); pointGroups [t][depth].AddComponent <MeshRenderer> (); spherePoints [depth] = sPoints; planePoints [depth] = pPoints; Mesh mesh = new Mesh(); mesh.vertices = sPoints; mesh.colors = colors; mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; mesh.SetIndices(indices, meshTopology, 0); pointGroups [t][depth].GetComponent <MeshFilter> ().mesh = mesh; pointGroups [t][depth].GetComponent <MeshRenderer> ().motionVectorGenerationMode = MotionVectorGenerationMode.Object; Renderer rend = pointGroups [t][depth].GetComponent <Renderer> (); rend.material.shader = shader; pointGroups [t][depth].transform.parent = transform; pointGroups [t][depth].SetActive(false); }
/// <summary> /// Create submeshes from a set of faces. Currently only Quads and Triangles are supported. /// </summary> /// <param name="faces">The faces to be included in the resulting submeshes. This method handles groups submeshes by comparing the material property of each face.</param> /// <param name="submeshCount">How many submeshes to create. Usually you will just want to pass the length of the MeshRenderer.sharedMaterials array.</param> /// <param name="preferredTopology">Should the resulting submeshes be in quads or triangles. Note that quads are not guaranteed; ie, some faces may not be able to be represented in quad format and will fall back on triangles.</param> /// <returns>An array of Submeshes.</returns> /// <exception cref="NotImplementedException">Thrown in the event that a MeshTopology other than Quads or Triangles is passed.</exception> /// <see cref="MeshUtility.GetMaterialCount"/> public static Submesh[] GetSubmeshes(IEnumerable <Face> faces, int submeshCount, MeshTopology preferredTopology = MeshTopology.Triangles) { if (preferredTopology != MeshTopology.Triangles && preferredTopology != MeshTopology.Quads) { throw new System.NotImplementedException("Currently only Quads and Triangles are supported."); } if (faces == null) { throw new ArgumentNullException("faces"); } bool wantsQuads = preferredTopology == MeshTopology.Quads; List <int>[] quads = wantsQuads ? new List <int> [submeshCount] : null; List <int>[] tris = new List <int> [submeshCount]; int maxSubmeshIndex = submeshCount - 1; for (int i = 0; i < submeshCount; i++) { if (wantsQuads) { quads[i] = new List <int>(); } tris[i] = new List <int>(); } foreach (var face in faces) { if (face.indexesInternal == null || face.indexesInternal.Length < 1) { continue; } int submeshIndex = Math.Clamp(face.submeshIndex, 0, maxSubmeshIndex); if (wantsQuads && face.IsQuad()) { quads[submeshIndex].AddRange(face.ToQuad()); } else { tris[submeshIndex].AddRange(face.indexesInternal); } } var submeshes = new Submesh[submeshCount]; switch (preferredTopology) { case MeshTopology.Triangles: { for (int submeshIndex = 0; submeshIndex < submeshCount; submeshIndex++) { submeshes[submeshIndex] = new Submesh(submeshIndex, MeshTopology.Triangles, tris[submeshIndex]); } break; } case MeshTopology.Quads: { for (int submeshIndex = 0; submeshIndex < submeshCount; submeshIndex++) { // If a submesh is a mix of triangles and quads, fall back to triangles. if (tris[submeshIndex].Count > 0) { var tri = tris[submeshIndex]; var quad = quads[submeshIndex]; int triCount = tri.Count; int quadCount = quad.Count; int[] triangles = new int[triCount + ((quadCount / 4) * 6)]; for (int i = 0; i < triCount; i++) { triangles[i] = tri[i]; } for (int i = 0, n = triCount; i < quadCount; i += 4, n += 6) { triangles[n + 0] = quad[i + 0]; triangles[n + 1] = quad[i + 1]; triangles[n + 2] = quad[i + 2]; triangles[n + 3] = quad[i + 2]; triangles[n + 4] = quad[i + 3]; triangles[n + 5] = quad[i + 0]; } submeshes[submeshIndex] = new Submesh(submeshIndex, MeshTopology.Triangles, triangles); } else { submeshes[submeshIndex] = new Submesh(submeshIndex, MeshTopology.Quads, quads[submeshIndex]); } } break; } } return(submeshes); }
public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount) { DrawProcedural(matrix, material, shaderPass, topology, vertexCount, 1); }
/// <summary> /// Creates a mesh. /// </summary> /// <returns>The mesh.</returns> /// <param name="vertices">Vertices.</param> /// <param name="indices">Indices.</param> /// <param name="colours">Colours.</param> /// <param name="normals">Normals.</param> /// <param name="MeshTopology">Mesh topology.</param> /// <param name="material">Material.</param> private static GameObject createMesh(Vector3[] vertices, int[] indices, Color[] colours, Vector3[] normals, Vector3[] uvs, MeshTopology meshTopology, Material material) { GameObject meshObject = new GameObject(); MeshTopology mtp = meshTopology; // if (mtp == MeshTopology.Lines) mtp = MeshTopology.LineStrip; // Create the mesh Mesh mesh = new Mesh(); //enables bigmesh mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; mesh.vertices = vertices; mesh.SetIndices(indices, mtp, 0); mesh.normals = normals; mesh.colors = colours; mesh.SetUVs(0, uvs.ToList()); mesh.RecalculateBounds(); if (normals == null || normals.Length == 0) { mesh.RecalculateNormals(); } // Assign to GameObject MeshFilter meshFilter = meshObject.AddComponent<MeshFilter>(); MeshRenderer meshRenderer = meshObject.AddComponent<MeshRenderer>(); meshFilter.mesh = mesh; meshRenderer.material = material; mesh.RecalculateBounds(); return meshObject; }
public void DrawProcedural(GraphicsBuffer indexBuffer, Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int indexCount) { DrawProcedural(indexBuffer, matrix, material, shaderPass, topology, indexCount, 1); }
public static Mesh ExtractSubmesh(Mesh mesh, int submeshIndex) { MeshTopology topology = mesh.GetTopology(submeshIndex); if (topology != MeshTopology.Triangles) { Debug.LogWarningFormat("Extract Submesh method could handle triangle topology only. Current topology is {0}. Mesh name {1} submeshIndex {2}", topology, mesh, submeshIndex); return(mesh); } int[] triangles = mesh.GetTriangles(submeshIndex); int[] newTriangles = new int[triangles.Length]; Dictionary <int, int> remapping = new Dictionary <int, int>(); int newIndex = 0; for (int i = 0; i < triangles.Length; ++i) { int index = triangles[i]; if (!remapping.ContainsKey(index)) { newTriangles[i] = newIndex; remapping.Add(index, newIndex); newIndex++; } else { newTriangles[i] = remapping[index]; } } Vector3[] vertices = mesh.vertices; Vector3[] newVertices = new Vector3[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newVertices[kvp.Value] = vertices[kvp.Key]; } Mesh result = new Mesh(); result.vertices = newVertices; Color[] colors = mesh.colors; if (colors.Length == vertices.Length) { Color[] newColors = new Color[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newColors[kvp.Value] = colors[kvp.Key]; } result.colors = newColors; } else { if (colors.Length != 0) { Debug.LogWarning("colors.Length != vertices.Length"); } } Color32[] colors32 = mesh.colors32; if (colors32.Length == vertices.Length) { Color32[] newColors32 = new Color32[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newColors32[kvp.Value] = colors32[kvp.Key]; } result.colors32 = newColors32; } else { if (colors32.Length != 0) { Debug.LogWarning("colors32.Length != vertices.Length"); } } BoneWeight[] boneWeights = mesh.boneWeights; if (boneWeights.Length == vertices.Length) { BoneWeight[] newBoneWeights = new BoneWeight[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newBoneWeights[kvp.Value] = boneWeights[kvp.Key]; } result.boneWeights = newBoneWeights; } else { if (boneWeights.Length != 0) { Debug.LogWarning("boneWeights.Length != vertices.Length"); } } Vector3[] normals = mesh.normals; if (normals.Length == vertices.Length) { Vector3[] newNormals = new Vector3[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newNormals[kvp.Value] = normals[kvp.Key]; } result.normals = newNormals; } else { if (normals.Length != 0) { Debug.LogWarning("normals.Length != vertices.Length"); } } Vector4[] tangents = mesh.tangents; if (tangents.Length == vertices.Length) { Vector4[] newTangents = new Vector4[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newTangents[kvp.Value] = tangents[kvp.Key]; } result.tangents = newTangents; } else { if (tangents.Length != 0) { Debug.LogWarning("tangents.Length != vertices.Length"); } } Vector2[] uv = mesh.uv; if (uv.Length == vertices.Length) { Vector2[] newUv = new Vector2[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newUv[kvp.Value] = uv[kvp.Key]; } result.uv = newUv; } else { if (uv.Length != 0) { Debug.LogWarning("uv.Length != vertices.Length"); } } Vector2[] uv2 = mesh.uv2; if (uv2.Length == vertices.Length) { Vector2[] newUv2 = new Vector2[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newUv2[kvp.Value] = uv2[kvp.Key]; } result.uv2 = newUv2; } else { if (uv2.Length != 0) { Debug.LogWarning("uv2.Length != vertices.Length"); } } Vector2[] uv3 = mesh.uv3; if (uv3.Length == vertices.Length) { Vector2[] newUv3 = new Vector2[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newUv3[kvp.Value] = uv3[kvp.Key]; } result.uv3 = newUv3; } else { if (uv3.Length != 0) { Debug.LogWarning("uv3.Length != vertices.Length"); } } Vector2[] uv4 = mesh.uv4; if (uv4.Length == vertices.Length) { Vector2[] newUv4 = new Vector2[newIndex]; foreach (KeyValuePair <int, int> kvp in remapping) { newUv4[kvp.Value] = uv4[kvp.Key]; } result.uv4 = newUv4; } else { if (uv4.Length != 0) { Debug.LogWarning("uv4.Length != vertices.Length"); } } result.triangles = newTriangles; return(result); }
public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset) { DrawProceduralIndirect(matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, null); }
public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, [DefaultValue("1")] int instanceCount, [DefaultValue("null")] MaterialPropertyBlock properties) { INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties); }
public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount) { MaterialPropertyBlock properties = (MaterialPropertyBlock) null; int instanceCount = 1; CommandBuffer.INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties); }
public void DrawProcedural(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount) { MaterialPropertyBlock properties = null; int instanceCount = 1; INTERNAL_CALL_DrawProcedural(this, ref matrix, material, shaderPass, topology, vertexCount, instanceCount, properties); }
public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs) { MaterialPropertyBlock properties = (MaterialPropertyBlock) null; int argsOffset = 0; CommandBuffer.INTERNAL_CALL_DrawProceduralIndirect(this, ref matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, properties); }
private static void INTERNAL_CALL_DrawProcedural(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, int vertexCount, int instanceCount, MaterialPropertyBlock properties) { throw new NotImplementedException("なにこれ"); }
public void SetIndices(Int32[] indices, MeshTopology topology, int submesh){}
public void DrawProceduralIndirect(Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs) { MaterialPropertyBlock properties = null; int argsOffset = 0; INTERNAL_CALL_DrawProceduralIndirect(this, ref matrix, material, shaderPass, topology, bufferWithArgs, argsOffset, properties); }
public static void DrawProceduralIndirect(MeshTopology topology, ComputeBuffer bufferWithArgs){}
private static void INTERNAL_CALL_DrawProceduralIndirect(CommandBuffer self, ref Matrix4x4 matrix, Material material, int shaderPass, MeshTopology topology, ComputeBuffer bufferWithArgs, int argsOffset, MaterialPropertyBlock properties) { throw new NotImplementedException("なにこれ"); }
public static void DrawProcedural(MeshTopology topology, int vertexCount) { int instanceCount = 1; Graphics.DrawProcedural(topology, vertexCount, instanceCount); }
extern private static void Internal_DrawProcedural(MeshTopology topology, int vertexCount, int instanceCount);
public static void DrawProceduralIndirect(MeshTopology topology, ComputeBuffer bufferWithArgs) { int argsOffset = 0; Graphics.DrawProceduralIndirect(topology, bufferWithArgs, argsOffset); }
void OnGUI() { GUILayout.BeginHorizontal(); { obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject), true); if (obj == null) { mesh = null; SMR = null; } else if (obj.GetComponent<MeshFilter>() && (mesh == null || obj != oldObject)) { SMR = null; mesh = obj.GetComponent<MeshFilter>().sharedMesh; topo = mesh.GetTopology(0); } else if (obj.GetComponent<SkinnedMeshRenderer>() && (mesh == null || obj != oldObject)) { SMR = obj.GetComponent<SkinnedMeshRenderer>(); mesh = SMR.sharedMesh; topo = mesh.GetTopology(0); } oldObject = obj; linkScroll = GUILayout.Toggle(linkScroll, "Link scroll bars"); GUILayout.Label("Mesh Topology: ", GUILayout.Width(92)); topo = (MeshTopology)EditorGUILayout.EnumPopup(topo); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { showVerts = GUILayout.Toggle(showVerts, "Show Vertices"); showNorm = GUILayout.Toggle(showNorm, "Show Normals"); showTangents = GUILayout.Toggle(showTangents, "Show Tangents"); showIndices = GUILayout.Toggle(showIndices, "Show Indices"); showUVs = GUILayout.Toggle(showUVs, "Show UVs"); showUV2s = GUILayout.Toggle(showUV2s, "Show UV2s"); showBoneWeights = GUILayout.Toggle(showBoneWeights, "Show BoneWeights"); showBindPoses = GUILayout.Toggle(showBindPoses, "Show BindPoses"); showBones = GUILayout.Toggle(showBones, "Show Bones"); } GUILayout.EndHorizontal(); if (mesh) { GUILayout.BeginHorizontal(); { if (showVerts) { BeginScroll(ref vertScroll); vertices = mesh.vertices; for (int i = 0; i < mesh.vertexCount && i < MAX_DISPLAY; i++) { vertices[i] = EditorGUILayout.Vector3Field(i + ":", vertices[i]); } mesh.vertices = vertices; GUILayout.EndScrollView(); } if (showNorm) { BeginScroll(ref normScroll); normals = mesh.normals; for (int i = 0; i < mesh.normals.Length && i < MAX_DISPLAY; i++) { normals[i] = EditorGUILayout.Vector3Field(i + ":", normals[i]); } mesh.normals = normals; GUILayout.EndScrollView(); } if (showTangents) { BeginScroll(ref tangentScroll); tangents = mesh.tangents; for (int i = 0; i < mesh.tangents.Length && i < MAX_DISPLAY; i++) { tangents[i] = EditorGUILayout.Vector3Field(i + ":", tangents[i]); } mesh.tangents = tangents; GUILayout.EndScrollView(); } if (showBoneWeights) { BeginScroll(ref boneWeightScroll); boneWeights = mesh.boneWeights; for (int i = 0; i < mesh.boneWeights.Length && i < MAX_DISPLAY; i++) { GUILayout.Label(i + ":"); boneWeights[i].boneIndex0 = EditorGUILayout.IntField("Bone 0 idx: ", boneWeights[i].boneIndex0); boneWeights[i].boneIndex1 = EditorGUILayout.IntField("Bone 1 idx: ", boneWeights[i].boneIndex1); boneWeights[i].boneIndex2 = EditorGUILayout.IntField("Bone 2 idx: ", boneWeights[i].boneIndex2); boneWeights[i].boneIndex3 = EditorGUILayout.IntField("Bone 3 idx: ", boneWeights[i].boneIndex3); boneWeights[i].weight0 = EditorGUILayout.FloatField("Bone 0 Weight: ", boneWeights[i].weight0); boneWeights[i].weight1 = EditorGUILayout.FloatField("Bone 1 Weight: ", boneWeights[i].weight1); boneWeights[i].weight2 = EditorGUILayout.FloatField("Bone 2 Weight: ", boneWeights[i].weight2); boneWeights[i].weight3 = EditorGUILayout.FloatField("Bone 3 Weight: ", boneWeights[i].weight3); } //mesh.boneWeights = boneWeights; GUILayout.EndScrollView(); } if (showIndices) { BeginScroll(ref triScroll); triangles = mesh.GetIndices(0); int jump = 1; switch (topo) { case MeshTopology.Quads: jump = 4; break; case MeshTopology.Triangles: jump = 3; break; case MeshTopology.Lines: jump = 2; break; } for (int i = 0; i < triangles.Length && i < MAX_DISPLAY; i += jump) { GUILayout.BeginHorizontal(); { triangles[i] = EditorGUILayout.IntField(i + ":", triangles[i]); if (topo == MeshTopology.Lines || topo == MeshTopology.Triangles || topo == MeshTopology.Quads) triangles[i + 1] = EditorGUILayout.IntField(i + 1 + ":", triangles[i + 1]); if (topo == MeshTopology.Triangles || topo == MeshTopology.Quads) triangles[i + 2] = EditorGUILayout.IntField(i + 2 + ":", triangles[i + 2]); if (topo == MeshTopology.Quads) triangles[i + 3] = EditorGUILayout.IntField(i + 3 + ":", triangles[i + 3]); } GUILayout.EndHorizontal(); } mesh.SetIndices(triangles, topo, 0); GUILayout.EndScrollView(); } if (showUVs) { BeginScroll(ref UVScroll); uv = mesh.uv; for (int i = 0; i < mesh.uv.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { uv[i] = EditorGUILayout.Vector2Field(i + ":", uv[i]); } GUILayout.EndHorizontal(); } mesh.uv = uv; GUILayout.EndScrollView(); } if (showUV2s) { BeginScroll(ref UV2Scroll); uv2 = mesh.uv2; for (int i = 0; i < mesh.uv2.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { uv2[i] = EditorGUILayout.Vector2Field(i + ":", uv2[i]); } GUILayout.EndHorizontal(); } mesh.uv2 = uv2; GUILayout.EndScrollView(); } if (showBindPoses) { BeginScroll(ref bindPoseScroll); bindPoses = mesh.bindposes; for (int i = 0; i < bindPoses.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { Matrix4x4Field(i + ":", ref bindPoses[i]); } GUILayout.EndHorizontal(); } mesh.bindposes = bindPoses; GUILayout.EndScrollView(); } if (SMR && showBones) { BeginScroll(ref boneWeightScroll); bones = SMR.bones; for (int i = 0; i < bones.Length && i < MAX_DISPLAY; i++) { GUILayout.BeginHorizontal(); { bones[i] = EditorGUILayout.ObjectField(bones[i], typeof(Transform)) as Transform; } GUILayout.EndHorizontal(); } SMR.bones = bones; GUILayout.EndScrollView(); } } GUILayout.EndHorizontal(); } }