示例#1
0
        /// <summary>
        /// Initializes new wrapper object for native mesh.
        /// </summary>
        /// <param name="obj">Static object that hosts the mesh.</param>
        public NativeMesh(StaticObject obj)
        {
            if (obj.Disposed)
            {
                throw new ObjectDisposedException("Cannot acquire mesh data from static" +
                                                  " object that has been disposed of.");
            }
            MeshHandles handles = StaticObjectInterop.GetMeshHandles(obj.Handle);

            if (handles.IndexedMeshHandle == IntPtr.Zero || handles.MeshHandle == IntPtr.Zero)
            {
                throw new Exception("Unable to acquire mesh handles for the static object.");
            }
            this.CMeshHandle       = handles.MeshHandle;
            this.IndexedMeshHandle = handles.IndexedMeshHandle;
            this.StaticObject      = obj;

            this.colors0   = new NativeVertexColor0Collection(this);
            this.colors1   = new NativeVertexColor1Collection(this);
            this.faces     = new NativeFaceCollection(this.CMeshHandle);
            this.indices   = new NativeIndicesCollection(this);
            this.positions = new NativeVertexPositionCollection(this);
            this.normals   = new NativeVertexNormalCollection(this);
            this.tangents  = new NativeVertexTangentCollection(this);
            this.qTangents = new NativeVertexQTangentCollection(this);
            this.texCoords = new NativeVertexTextureCoordinatesCollection(this);
        }
示例#2
0
            void End()
            {
                m_Mesh.Clear();

                if (BuiltinMaterials.geometryShadersSupported)
                {
                    for (int i = 0, c = m_Points.Count; i < c; ++i)
                    {
                        m_Indices.Add(i);
                    }

                    m_Mesh.SetVertices(m_Points);

                    // NoAllocHelpers is internal API, and there is no SetIndices overload that accepts a list like
                    // SetVertices or SetUVs.
//#if UNITY_2019_1_OR_NEWER
//                    m_Mesh.SetIndices(NoAllocHelpers.ExtractArrayFromListT(m_Indices), MeshTopology.Points, 0, false);
//#else
                    m_Mesh.SetIndices(m_Indices.ToArray(), MeshTopology.Points, 0, false);
                }
                else
                {
                    MeshHandles.CreatePointBillboardMesh(m_Points, m_Mesh);
                }

                Graphics.DrawMeshNow(m_Mesh, m_Matrix, 0);
            }
            void End()
            {
                m_Mesh.Clear();

                if (BuiltinMaterials.geometryShadersSupported)
                {
                    for (int i = 0, c = m_Points.Count; i < c; ++i)
                    {
                        m_Indices.Add(i);
                    }

                    m_Mesh.SetVertices(m_Points);

#if UNITY_2019_3_OR_NEWER
                    m_Mesh.SetIndices(m_Indices, MeshTopology.Points, 0, false);
#else
                    m_Mesh.SetIndices(m_Indices.ToArray(), MeshTopology.Points, 0, false);
#endif
                }
                else
                {
                    MeshHandles.CreatePointBillboardMesh(m_Points, m_Mesh);
                }

                Graphics.DrawMeshNow(m_Mesh, m_Matrix, 0);
            }
示例#4
0
        void RebuildSelectedHandlesInternal(IEnumerable<ProBuilderMesh> meshes, SelectMode selectionMode)
        {
            ClearHandles();

            foreach (var mesh in meshes)
            {
                switch (selectionMode)
                {
                    case SelectMode.Vertex:
                    case SelectMode.TextureVertex:
                    {
                        RebuildMeshHandle(mesh, m_VertexHandles, MeshHandles.CreateVertexMesh);
                        var handle = GetMeshHandle(mesh, m_SelectedVertexHandles);
                        MeshHandles.CreateVertexMesh(mesh, handle.mesh, mesh.selectedIndexesInternal);
                        goto default;
                    }

                    case SelectMode.Edge:
                    case SelectMode.TextureEdge:
                    {
                        if(m_ForceEdgeLinesGL || BuiltinMaterials.geometryShadersSupported)
                            RebuildMeshHandle(mesh, m_WireHandles, MeshHandles.CreateEdgeMesh);
                        else
                            RebuildMeshHandle(mesh, m_WireHandles, MeshHandles.CreateEdgeBillboardMesh);

                        var handle = GetMeshHandle(mesh, m_SelectedEdgeHandles);

                        if(m_ForceEdgeLinesGL || BuiltinMaterials.geometryShadersSupported)
                            MeshHandles.CreateEdgeMesh(mesh, handle.mesh, mesh.selectedEdgesInternal);
                        else
                            MeshHandles.CreateEdgeBillboardMesh(mesh, handle.mesh, mesh.selectedEdgesInternal);

                        break;
                    }

                    case SelectMode.Face:
                    case SelectMode.TextureFace:
                    {
                        RebuildMeshHandle(mesh, m_SelectedFaceHandles, MeshHandles.CreateFaceMesh);
                        goto default;
                    }

                    default:
                        if(m_ForceWireframeLinesGL || BuiltinMaterials.geometryShadersSupported)
                            RebuildMeshHandle(mesh, m_WireHandles, MeshHandles.CreateEdgeMesh);
                        else
                            RebuildMeshHandle(mesh, m_WireHandles, MeshHandles.CreateEdgeBillboardMesh);
                        break;
                }
            }
        }
        void RebuildSelectedHandlesInternal(IEnumerable <ProBuilderMesh> meshes, SelectMode selectionMode, bool selectionOrVertexCountChanged = true)
        {
            if (!selectionOrVertexCountChanged)
            {
                foreach (var handle in m_WireHandles)
                {
                    handle.Value.mesh.vertices = handle.Key.positionsInternal;
                }

                switch (selectionMode)
                {
                case SelectMode.Vertex:
                case SelectMode.TextureVertex:
                {
                    if (BuiltinMaterials.geometryShadersSupported)
                    {
                        foreach (var handle in m_VertexHandles)
                        {
                            handle.Value.mesh.vertices = handle.Key.positionsInternal;
                        }
                        foreach (var handle in m_SelectedVertexHandles)
                        {
                            handle.Value.mesh.vertices = handle.Key.positionsInternal;
                        }
                    }
                    else
                    {
                        foreach (var handle in m_VertexHandles)
                        {
                            MeshHandles.CreateVertexMesh(handle.Key, handle.Value.mesh);
                        }
                        foreach (var handle in m_SelectedVertexHandles)
                        {
                            MeshHandles.CreateVertexMesh(handle.Key, handle.Value.mesh, handle.Key.selectedIndexesInternal);
                        }
                    }

                    break;
                }

                case SelectMode.Edge:
                case SelectMode.TextureEdge:
                {
                    foreach (var handle in m_SelectedEdgeHandles)
                    {
                        handle.Value.mesh.vertices = handle.Key.positionsInternal;
                    }
                    break;
                }

                case SelectMode.Face:
                case SelectMode.TextureFace:
                {
                    foreach (var handle in m_SelectedFaceHandles)
                    {
                        handle.Value.mesh.vertices = handle.Key.positionsInternal;
                    }
                    break;
                }
                }

                return;
            }

            ClearHandles();

            foreach (var mesh in meshes)
            {
                // always do wireframe
                RebuildMeshHandle(mesh, m_WireHandles, MeshHandles.CreateEdgeMesh);

                switch (selectionMode)
                {
                case SelectMode.Vertex:
                case SelectMode.TextureVertex:
                {
                    RebuildMeshHandle(mesh, m_VertexHandles, MeshHandles.CreateVertexMesh);
                    RebuildMeshHandle(mesh, m_SelectedVertexHandles,
                                      (x, y) => { MeshHandles.CreateVertexMesh(x, y, x.selectedIndexesInternal); });
                    break;
                }

                case SelectMode.Edge:
                case SelectMode.TextureEdge:
                {
                    RebuildMeshHandle(mesh, m_SelectedEdgeHandles,
                                      (x, y) => { MeshHandles.CreateEdgeMesh(x, y, x.selectedEdgesInternal); });
                    break;
                }

                case SelectMode.Face:
                case SelectMode.TextureFace:
                {
                    RebuildMeshHandle(mesh, m_SelectedFaceHandles, MeshHandles.CreateFaceMesh);
                    break;
                }
                }
            }
        }