private bool GenerateMesh()
    {
        Debug.Log(gParams.xSize);
        Mesh mesh = new CubeMeshFactory(gParams, name).result;

        DeformableBase.generatedVerticesLength = mesh.vertexCount;
        if (mesh == null)
        {
            Debug.LogError("Mesh Generation failed! (name: " + name + ").");
            return(false);
        }

        if (mFilter)
        {
            Debug.LogWarning("No mesh filter attached to CubeMeshGenerator (" + gameObject.name + ").");
            mFilter.sharedMesh = mesh;
        }

        if (mCollider)
        {
            Debug.LogWarning("No mesh collider attached to CubeMeshGenerator (" + gameObject.name + ").");
            mCollider.sharedMesh = mesh;
        }

        return(true);
    }
Пример #2
0
        public override void Do(IDemoChartControl chartControl)
        {
            // Create mesh for rendering. We need a cube.
            Mesh cubeMesh = CubeMeshFactory.GenerateCube();

            // Generates cube transformation matrixes and it's colors.
            Matrix4F[] transformations = new Matrix4F[TotalBarCount];
            Color4[]   colors          = new Color4[TotalBarCount];
            int        index           = 0;

            for (int x = 0; x < GridSize; x++)
            {
                for (int y = 0; y < GridSize; y++)
                {
                    // Randomize block height.
                    float height = (float)random.NextDouble() * MaxHeight;
                    // Compute current bar transformation matrix.
                    // Scaling matrix is used for size scaling. Translation matrix is used for positioning.
                    transformations[index] = Matrix4F.Scaling(BlockSize, BlockSize, height) *
                                             Matrix4F.Translation(GridStep * x, GridStep * y, height / 2);
                    // Randomize color.
                    colors[index] = DemoHelper.RandomizeColor();
                    index++;
                }
            }

            // Create presentation object.
            var primitiveCollection = new MultiColorPrimitiveCollection
            {
                // Set mesh.
                Mesh = cubeMesh,
                // Set name.
                Name = "Bars",
                // Set custom material.
                Material = new RenderMaterial(0.35f, 0.5f, 0.6f, 0.0f, 0.0f)
            };

            // Set transforms.
            primitiveCollection.SetTransformsAndColor(transformations, colors);

            // Set chart options.
            chartControl.Axes.IsAxes3DVisible = true;

            // Set data source.
            chartControl.DataSource = primitiveCollection;
        }