Beispiel #1
0
        public void AddPoint(Vector3Df point)
        {
            points.Add(point);

            // add front line
            Vertex3D v1front = new Vertex3D(point, new Vector3Df(0), new Color(0));
            Vertex3D v2front = new Vertex3D((point - Center).Normalize() * height, new Vector3Df(0), FrontColor);

            vertFront.Add(v1front);
            vertFront.Add(v2front);

            // add back line
            Vertex3D v1back = v1front;
            Vertex3D v2back = new Vertex3D(v2front);

            v2back.Color = BackColor;
            vertBack.Add(v1back);
            vertBack.Add(v2back);

            // add connection line if possible (front and back)
            if (vertFront.Count >= 4)
            {
                vertFront.Add(vertFront.Get(vertFront.Count - 3));
                vertFront.Add(v2front);

                vertBack.Add(vertBack.Get(vertBack.Count - 3));
                vertBack.Add(v2back);
            }

            // update indices "used" count
            indBoth.SetCount(vertFront.Count);
        }
Beispiel #2
0
        public void CreateBufferAccessorAndAdd(int accessorIndex, VertexBuffer b, string key)
        {
            var a = CreateAccessor(accessorIndex);

            if (a != null)
            {
                b.Add(key, a);
            }
        }
        static void CreateBufferAccessorAndAdd(GltfSerialization.GltfStorage storage, int accessorIndex,
                                               VertexBuffer b, string key)
        {
            var a = storage.AccessorFromGltf(accessorIndex);

            if (a != null)
            {
                b.Add(key, a);
            }
        }
Beispiel #4
0
        public static VertexBuffer FromGltf(this global::Google.Protobuf.Collections.MapField <string, int> attributes,
                                            Vrm10Storage storage)
        {
            var b = new VertexBuffer();

            foreach (var kv in attributes)
            {
                var accessor = storage.CreateAccessor(kv.Value);
                b.Add(kv.Key, accessor);
            }
            return(b);
        }
Beispiel #5
0
        public static VertexBuffer FromGltf(this GltfAttributes attributes, GltfSerialization.GltfStorage storage)
        {
            var b = new VertexBuffer();

            b.Add(VertexBuffer.PositionKey, storage.AccessorFromGltf(attributes.POSITION));
            CreateBufferAccessorAndAdd(storage, attributes.NORMAL, b, VertexBuffer.NormalKey);
            CreateBufferAccessorAndAdd(storage, attributes.TEXCOORD_0, b, VertexBuffer.TexCoordKey);
            CreateBufferAccessorAndAdd(storage, attributes.TANGENT, b, VertexBuffer.TangentKey);
            CreateBufferAccessorAndAdd(storage, attributes.COLOR_0, b, VertexBuffer.ColorKey);
            CreateBufferAccessorAndAdd(storage, attributes.JOINTS_0, b, VertexBuffer.JointKey);
            CreateBufferAccessorAndAdd(storage, attributes.WEIGHTS_0, b, VertexBuffer.WeightKey);
            return(b);
        }
Beispiel #6
0
        public static VertexBuffer FromGltf(this glTFAttributes attributes,
                                            Vrm10Storage storage)
        {
            var b = new VertexBuffer();

            if (storage.TryCreateAccessor(attributes.POSITION, out BufferAccessor position))
            {
                b.Add(VertexBuffer.PositionKey, position);
            }
            else
            {
                // position required
                throw new Exception();
            }

            if (storage.TryCreateAccessor(attributes.NORMAL, out BufferAccessor normal))
            {
                b.Add(VertexBuffer.NormalKey, normal);
            }
            if (storage.TryCreateAccessor(attributes.COLOR_0, out BufferAccessor color))
            {
                b.Add(VertexBuffer.ColorKey, color);
            }
            if (storage.TryCreateAccessor(attributes.TEXCOORD_0, out BufferAccessor tex0))
            {
                b.Add(VertexBuffer.TexCoordKey, tex0);
            }
            if (storage.TryCreateAccessor(attributes.TEXCOORD_1, out BufferAccessor tex1))
            {
                b.Add(VertexBuffer.TexCoordKey2, tex1);
            }
            // if(storage.TryCreateAccessor(attributes.TANGENT, out BufferAccessor tangent))b.Add(VertexBuffer.TangentKey, tangent);
            if (storage.TryCreateAccessor(attributes.WEIGHTS_0, out BufferAccessor weights))
            {
                b.Add(VertexBuffer.WeightKey, weights);
            }
            if (storage.TryCreateAccessor(attributes.JOINTS_0, out BufferAccessor joints))
            {
                b.Add(VertexBuffer.JointKey, joints);
            }

            return(b);
        }
Beispiel #7
0
    public void MakeTesselatedPlane(int xRes, int yRes, int size, Material material)
    {
        var vb = new VertexBuffer();

        vb.Init(true);

        for (int x = 0; x <= xRes; x++)
        {
            for (int y = 0; y <= yRes; y++)
            {
                var uv  = new Vector2(x / (float)xRes, y / (float)yRes);
                var pos = uv - new Vector2(0.5f, 0.5f);
                vb.Add(new Vertex(new Vector3(pos.x * size, pos.y * size, 0), Vector3.Down, Vector3.Right, uv));
            }
        }

        for (int y = 0; y < yRes; y++)
        {
            for (int x = 0; x < xRes; x++)
            {
                var i = y + (x * yRes);

                vb.AddRawIndex(i + yRes + 1);
                vb.AddRawIndex(i + 1);
                vb.AddRawIndex(i);

                vb.AddRawIndex(i + 1);
                vb.AddRawIndex(i + yRes + 1);
                vb.AddRawIndex(i + yRes + 2);
            }
        }

        var model = vb.CreateModel($"TesselatedPlane-{NetworkIdent}.vmdl", material);

        SetModel(model);
    }
Beispiel #8
0
        public void BuildFromMesh(Mesh mesh)
        {
            Clear();
            if (mesh != null)
            {
                Vector3        minVec       = Vector3.zero;
                Vector3        maxVec       = Vector3.zero;
                bool           isInitMinMax = false;
                List <Vector3> vertexs      = new List <Vector3>();
                mesh.GetVertices(vertexs);
                if (vertexs.Count > 0)
                {
                    m_VertexBuffer          = new VertexBuffer();
                    m_VertexBuffer.Capacity = vertexs.Count;
                    for (int i = 0; i < vertexs.Count; ++i)
                    {
                        Vector3 v = vertexs[i];
                        m_VertexBuffer.Add(v);
                        if (!isInitMinMax)
                        {
                            minVec       = v;
                            maxVec       = v;
                            isInitMinMax = true;
                        }
                        else
                        {
                            if (minVec.x > v.x)
                            {
                                minVec.x = v.x;
                            }
                            if (minVec.y > v.y)
                            {
                                minVec.y = v.y;
                            }
                            if (minVec.z > v.z)
                            {
                                minVec.z = v.z;
                            }
                            if (maxVec.x < v.x)
                            {
                                maxVec.x = v.x;
                            }
                            if (maxVec.y < v.y)
                            {
                                maxVec.y = v.y;
                            }
                            if (maxVec.z < v.z)
                            {
                                maxVec.z = v.z;
                            }
                        }
                    }
                }

                if (isInitMinMax)
                {
                    m_BoundSpere.position = (maxVec + minVec) / 2.0f;
                    m_BoundSpere.radius   = (maxVec - minVec).magnitude / 2.0f;
                }
                else
                {
                    m_BoundSpere.position = Vector3.zero;
                    m_BoundSpere.radius   = 0f;
                }

                List <Color> colors = new List <Color>();
                mesh.GetColors(colors);
                if (colors.Count > 0)
                {
                    m_ColorBuffer          = new VertexColorBuffer();
                    m_ColorBuffer.Capacity = colors.Count;
                    for (int i = 0; i < colors.Count; ++i)
                    {
                        m_ColorBuffer.Add(colors[i]);
                    }
                }

                // UV 1坐标
                List <Vector4> uvs = new List <Vector4>();
                mesh.GetUVs(0, uvs);
                if (uvs.Count > 0)
                {
                    if (m_UV1Buffer == null)
                    {
                        m_UV1Buffer = new UVBuffer();
                    }
                    m_UV1Buffer.Capacity = uvs.Count;
                    for (int i = 0; i < uvs.Count; ++i)
                    {
                        m_UV1Buffer.Add(uvs[i]);
                    }
                }

                for (int i = 0; i < mesh.subMeshCount; ++i)
                {
                    if (m_SubList == null)
                    {
                        m_SubList = new List <SoftSubMesh>();
                    }
                    var triangles = mesh.GetTriangles(i);
                    if (triangles != null && triangles.Length > 0)
                    {
                        SoftSubMesh subMesh = new SoftSubMesh(mesh, triangles);
                        m_SubList.Add(subMesh);
                    }
                }
            }
        }