Ejemplo n.º 1
0
        public GeometryMesh(MeshData meshData, Transform meshTransform, Matrix4x4 worldToVesselMatrix, GeometryPartModule module)
        {
            this.meshLocalVerts = meshData.vertices;
            this.triangles      = meshData.triangles;
            this.isSkinned      = meshData.isSkinned;
            Bounds meshBounds = meshData.bounds;

            vertices           = new Vector3[meshLocalVerts.Length];
            this.meshTransform = meshTransform;
            UpdateLocalToWorldMatrix();
            this.thisToVesselMatrix = worldToVesselMatrix * meshLocalToWorld;

            for (int i = 0; i < vertices.Length; i++)
            {
                //vertices[i] = thisToVesselMatrix.MultiplyPoint3x4(untransformedVerts[i]);
                Vector3 v    = meshLocalVerts[i];
                Vector3 vert = Vector3.zero;
                vert.x = thisToVesselMatrix.m00 * v.x + thisToVesselMatrix.m01 * v.y + thisToVesselMatrix.m02 * v.z + thisToVesselMatrix.m03;
                vert.y = thisToVesselMatrix.m10 * v.x + thisToVesselMatrix.m11 * v.y + thisToVesselMatrix.m12 * v.z + thisToVesselMatrix.m13;
                vert.z = thisToVesselMatrix.m20 * v.x + thisToVesselMatrix.m21 * v.y + thisToVesselMatrix.m22 * v.z + thisToVesselMatrix.m23;

                float tmpTestVert = vert.x + vert.y + vert.z;
                if (float.IsNaN(tmpTestVert) || float.IsInfinity(tmpTestVert))
                {
                    ThreadSafeDebugLogger.Instance.RegisterMessage("Mesh error in " + module.part.partInfo.title);
                }
                vertices[i] = vert;
            }

            this.gameObjectActiveInHierarchy = meshTransform.gameObject.activeInHierarchy;

            bounds = TransformBounds(meshBounds, thisToVesselMatrix);

            float tmpTestBounds = bounds.center.x + bounds.center.y + bounds.center.z
                                  + bounds.extents.x + bounds.extents.y + bounds.extents.z;

            if (float.IsNaN(tmpTestBounds) || float.IsInfinity(tmpTestBounds))
            {
                ThreadSafeDebugLogger.Instance.RegisterMessage("Bounds error in " + module.part.partInfo.title);
                valid = false;
            }
            else
            {
                valid = true;
            }

            this.module = module;
            this.part   = module.part;

            if (!module.part.isMirrored)
            {
                invertXYZ = 1;
            }
            else
            {
                invertXYZ = -1;
            }
        }
        public GeometryMesh(MeshData meshData, Transform meshTransform, Matrix4x4 worldToVesselMatrix, GeometryPartModule module)
        {
            Vector3[] untransformedVerts = meshData.vertices;
            int[]     triangles          = meshData.triangles;
            Bounds    meshBounds         = meshData.bounds;

            vertices = new Vector3[untransformedVerts.Length];
            this.thisToVesselMatrix = worldToVesselMatrix * meshTransform.localToWorldMatrix;

            for (int i = 0; i < vertices.Length; i++)
            {
                //vertices[i] = thisToVesselMatrix.MultiplyPoint3x4(untransformedVerts[i]);
                Vector3 v    = untransformedVerts[i];
                Vector3 vert = Vector3.zero;
                vert.x = thisToVesselMatrix.m00 * v.x + thisToVesselMatrix.m01 * v.y + thisToVesselMatrix.m02 * v.z + thisToVesselMatrix.m03;
                vert.y = thisToVesselMatrix.m10 * v.x + thisToVesselMatrix.m11 * v.y + thisToVesselMatrix.m12 * v.z + thisToVesselMatrix.m13;
                vert.z = thisToVesselMatrix.m20 * v.x + thisToVesselMatrix.m21 * v.y + thisToVesselMatrix.m22 * v.z + thisToVesselMatrix.m23;

                vertices[i] = vert;
            }

            this.triangles     = triangles;
            this.meshTransform = meshTransform;

            Vector3 size = thisToVesselMatrix.MultiplyVector(meshBounds.size);

            size.x = Math.Abs(size.x);
            size.y = Math.Abs(size.y);
            size.z = Math.Abs(size.z);

            bounds = TransformBounds(meshBounds, thisToVesselMatrix);

            this.module = module;

            if (!module.part.isMirrored)
            {
                invertXYZ = 1;
            }
            else
            {
                invertXYZ = -1;
            }
        }