Exemplo n.º 1
0
        private static Mesh <V> GetBackMesh(int slices, int stacks)
        {
            var upperMesh = MyManifold <V> .Surface(slices, stacks, (u, v) =>
            {
                var left  = topLeftCurve.GetPoint(u);
                var right = topRightCurve.GetPoint(u);
                return(lerp(right, left, v) + float3.back);
            });

            var bottomMesh = MyManifold <V> .Surface(slices, stacks,
                                                     (u, v) =>
            {
                var left  = bottomLeftCurve.GetPoint(u);
                var right = bottomRightCurve.GetPoint(u);
                return(lerp(right, left, v) + float3.back);
            }
                                                     );

            return(bottomMesh.Concat(upperMesh).Weld());
        }
Exemplo n.º 2
0
        private static Mesh <V> GetBorderMeshes(int slices, int stacks)
        {
            var meshes = new[]
            {
                MyManifold <V> .Lofted(slices, stacks,
                                       t => bottomLeftCurve.GetPoint(1 - t),
                                       t => bottomLeftCurve.GetPoint(1 - t) + float3.back),
                MyManifold <V> .Lofted(slices, stacks,
                                       t => bottomRightCurve.GetPoint(t),
                                       t => bottomRightCurve.GetPoint(t) + float3.back),
                MyManifold <V> .Lofted(slices, stacks,
                                       t => topLeftCurve.GetPoint(1 - t),
                                       t => topLeftCurve.GetPoint(1 - t) + float3.back),
                MyManifold <V> .Lofted(slices, stacks,
                                       t => topRightCurve.GetPoint(t),
                                       t => topRightCurve.GetPoint(t) + float3.back)
            };

            return(MeshTools.Join(meshes).Weld());
        }
Exemplo n.º 3
0
        public Cube(Transform transform, int xSize, int ySize, int zSize, int roundness = 0) : base(transform)
        {
            this.xSize     = xSize;
            this.ySize     = ySize;
            this.zSize     = zSize;
            this.roundness = roundness;

            var meshes = new[]
            {
                // front
                MyManifold <V> .SurfaceDiscrete(xSize, ySize,
                                                (u, v) => float3(u, v, 0)),
                // right
                MyManifold <V> .SurfaceDiscrete(zSize, ySize,
                                                (u, v) => float3(xSize, v, u)),
                // back
                MyManifold <V> .SurfaceDiscrete(xSize, ySize,
                                                (u, v) => float3(xSize - u, v, zSize)),
                // left
                MyManifold <V> .SurfaceDiscrete(zSize, ySize,
                                                (u, v) => float3(0, v, zSize - u)),
                // top
                MyManifold <V> .SurfaceDiscrete(xSize, zSize,
                                                (u, v) => float3(u, ySize, v)),
                // bottom
                MyManifold <V> .SurfaceDiscrete(xSize, zSize,
                                                (u, v) => float3(xSize - u, 0, v)),
            };

            Mesh = meshes.Aggregate((t, x) => t.Concat(x)).Weld();

            for (var i = 0; i < Mesh.Vertices.Length; i++)
            {
                var vertex = Mesh.Vertices[i];
                var inner  = vertex.Position;

                var(x, y, z) = vertex.Position;

                if (x < roundness)
                {
                    inner.x = roundness;
                }
                else if (x > xSize - roundness)
                {
                    inner.x = xSize - roundness;
                }

                if (y < roundness)
                {
                    inner.y = roundness;
                }
                else if (y > ySize - roundness)
                {
                    inner.y = ySize - roundness;
                }

                if (z < roundness)
                {
                    inner.z = roundness;
                }
                else if (z > zSize - roundness)
                {
                    inner.z = zSize - roundness;
                }

                var normal = normalize(vertex.Position - inner);
                Mesh.Vertices[i].Position = inner + normal * roundness;
            }

            // Mesh.ComputeNormals();
            UpdateTranslation();
        }
Exemplo n.º 4
0
 public static Mesh <V> GetMesh(int slices, int stacks)
 {
     return(MyManifold <V> .Revolution(slices, stacks, t => potentiometerOutline.GetPoint(t), float3.up));
 }