示例#1
0
        // Derive transform information from a placeholder
        public static void ImportPlaceholder(MeshFilter meshFilter, bool rhinoBasis)
        {
            var sharedMesh = meshFilter.sharedMesh;
            var vertices   = sharedMesh?.vertices;

            if (vertices == null || vertices.Length != 4)
            {
                Debug.LogWarning($"Inconsistent placeholder mesh: {meshFilter.Path()}.{sharedMesh.name}");
                return;
            }
            var placeholder = meshFilter.transform;
            // OBSERVATION: At this stage of the import the layer parent transform is present
            // but on completion the layer may be absent, although the transform will persist.
            // NOTE: This also applies to the default import path.

            // Derive Rhino transform block basis in world coordinates
            var origin = placeholder.TransformPoint(vertices[0]);
            var basisX = placeholder.TransformPoint(vertices[1]) - origin;
            var basisY = placeholder.TransformPoint(vertices[2]) - origin;
            var basisZ = placeholder.TransformPoint(vertices[3]) - origin;

            if (rhinoBasis)
            {
                // Mesh basis describes transformation of Rhino basis
                var unityX = new Vector3(-basisX.x, basisX.y, -basisX.z);
                var unityY = new Vector3(-basisZ.x, basisZ.y, -basisZ.z);
                var unityZ = new Vector3(-basisY.x, basisY.y, -basisY.z);
                basisX = unityX;
                basisY = unityY;
                basisZ = unityZ;
            }

            // TODO: Use SVD to construct transform, which can include shear
            // TEMP: Assume transform is axial scaling followed by rotation only
            // NOTE: The origin and bases are simply the columns of an affine (3x4) transform matrix
            placeholder.localScale = new Vector3(basisX.magnitude, basisY.magnitude, basisZ.magnitude);
            placeholder.rotation   = Quaternion.LookRotation(basisZ, basisY);
            placeholder.position   = origin;

            // Remove meshes from placeholders
            // IMPORTANT: MeshRenderers must also be removed, in order to avoid
            // the application of renderer configations that could modify or remove the placeholder.
            var meshRenderer = meshFilter.GetComponent <MeshRenderer>();

            if (meshRenderer)
            {
                EP.Destroy(meshRenderer);
            }
            EP.Destroy(meshFilter);
        }
示例#2
0
            public void SwapMeshes(MeshFilter meshFilter)
            {
                var oldMesh = meshFilter.sharedMesh;

                reduceMeshName(oldMesh);
                if (!(
                        meshAssets.ContainsKey(oldMesh.name) &&
                        meshAssets[oldMesh.name].ContainsKey(oldMesh.vertexCount)
                        ))
                {
                    Debug.LogWarning($"Missing Mesh {oldMesh.name} with vertexCount = {oldMesh.vertexCount} on {meshFilter.Path()} from {meshPath}");
                    return;
                }
                var newMesh = meshAssets[oldMesh.name][oldMesh.vertexCount];

                if (!oldMesh)
                {
                    Debug.LogWarning($"Created mesh {oldMesh.name} with vertexCount = {oldMesh.vertexCount} on {meshFilter.Path()} could not be loaded from {meshPath} -> stop editing assets, then reconstruct MeshGatherer");
                    return;
                }
                meshFilter.sharedMesh = newMesh;
            }