Ejemplo n.º 1
0
    // ガイド用メッシュを出力
    public void WriteToGuideMesh(ModelMeshMerger meshMerger)
    {
        var     meshFilter = this.gameObject.GetComponent <MeshFilter>();
        var     mesh       = meshFilter.sharedMesh;
        Vector3 localScale =
            Vector3.Scale(mesh.bounds.size, new Vector3(1.0f, 2.0f, 1.0f)) *
            (this.shape.scale * this.scale);
        Vector3    localPosition = mesh.bounds.center * (this.shape.scale * this.scale);
        Quaternion localRotation = Quaternion.AngleAxis(this.rotation, Vector3.up);

        Matrix4x4 matrix = Matrix4x4.TRS(this.position + this.offset + localPosition, localRotation, localScale);

        // 頂点を書き出す
        for (int j = 0; j < EditUtil.cubeVertices.Length; j++)
        {
            meshMerger.vertexPos.Add(matrix.MultiplyPoint3x4(EditUtil.cubeVertices[j]));
        }
        // インデックスを書き出す
        for (int i = 0; i < 6; i++)
        {
            int offset = meshMerger.vertexPos.Count - EditUtil.cubeVertices.Length;
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 1]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 3]);
        }
    }
Ejemplo n.º 2
0
    // ガイド用メッシュを出力
    public void WriteToGuideMesh(ModelMeshMerger meshMerger)
    {
        Bounds bounds     = new Bounds();
        float  totalScale = this.shape.scale * this.scale;

        foreach (var meshFilter in this.gameObject.GetComponentsInChildren <MeshFilter>())
        {
            Mesh mesh = meshFilter.sharedMesh;
            bounds.SetMinMax(
                Vector3.Min(mesh.bounds.min, bounds.min),
                Vector3.Max(mesh.bounds.max, bounds.max));
        }

        Vector3    localScale    = Vector3.Scale(bounds.size, new Vector3(1.0f, 2.0f, 1.0f)) * totalScale;
        Quaternion localRotation = Quaternion.AngleAxis(180.0f - this.rotation, Vector3.up);
        Vector3    localPosition = this.shape.offset + this.offset +
                                   Matrix4x4.Rotate(localRotation).MultiplyVector(bounds.center * totalScale);

        Matrix4x4 matrix = Matrix4x4.TRS(this.position + localPosition, localRotation, localScale);

        // 頂点を書き出す
        for (int j = 0; j < EditUtil.cubeVertices.Length; j++)
        {
            meshMerger.vertexPos.Add(matrix.MultiplyPoint3x4(EditUtil.cubeVertices[j]));
        }
        // インデックスを書き出す
        for (int i = 0; i < 6; i++)
        {
            int offset = meshMerger.vertexPos.Count - EditUtil.cubeVertices.Length;
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 1]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 0]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 2]);
            meshMerger.triangles.Add(offset + EditUtil.cubeQuadIndices[i * 4 + 3]);
        }
    }