コード例 #1
0
ファイル: Geometry.cs プロジェクト: tksuoran/renderstack_net
        public void Transform(Matrix4 transform)
        {
            Matrix4 inverseTransposeTransform = Matrix4.Transpose(Matrix4.Invert(transform));

            //  Check.. Did I forget something?
            //  \todo Mark each attributemap how they should be transformed
            var polygonCentroids = PolygonAttributes.FindOrNull <Vector3>("polygon_centroids");
            var polygonNormals   = PolygonAttributes.FindOrNull <Vector3>("polygon_normals");
            var pointLocations   = PointAttributes.FindOrNull <Vector3>("point_locations");
            var pointNormals     = PointAttributes.FindOrNull <Vector3>("point_normals");
            var cornerNormals    = CornerAttributes.FindOrNull <Vector3>("corner_normals");

            //  Make copies of old points
            foreach (Point point in Points)
            {
                if (pointLocations != null && pointLocations.ContainsKey(point))
                {
                    pointLocations[point] = transform.TransformPoint(pointLocations[point]);
                }
                if (pointNormals != null && pointNormals.ContainsKey(point))
                {
                    pointNormals[point] = inverseTransposeTransform.TransformDirection(pointNormals[point]);
                }
            }
            foreach (Polygon polygon in Polygons)
            {
                if (polygonCentroids != null && polygonCentroids.ContainsKey(polygon))
                {
                    polygonCentroids[polygon] = transform.TransformPoint(polygonCentroids[polygon]);
                }
                if (polygonNormals != null && polygonNormals.ContainsKey(polygon))
                {
                    polygonNormals[polygon] = inverseTransposeTransform.TransformDirection(polygonNormals[polygon]);
                }
                if (cornerNormals != null)
                {
                    foreach (Corner corner in polygon.Corners)
                    {
                        if (cornerNormals.ContainsKey(corner))
                        {
                            cornerNormals[corner] = inverseTransposeTransform.TransformDirection(cornerNormals[corner]);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Geometry.cs プロジェクト: tksuoran/renderstack_net
        public void Geodesate(float radius)
        {
            float rInv             = 1.0f / radius;
            var   polygonCentroids = PolygonAttributes.FindOrNull <Vector3>("polygon_centroids");
            var   polygonNormals   = PolygonAttributes.FindOrNull <Vector3>("polygon_normals");
            var   pointLocations   = PointAttributes.FindOrNull <Vector3>("point_locations");
            var   pointNormals     = PointAttributes.FindOrNull <Vector3>("point_normals");
            var   cornerNormals    = CornerAttributes.FindOrNull <Vector3>("corner_normals");

            //  Make copies of old points
            foreach (Point point in Points)
            {
                if (
                    (pointLocations != null) &&
                    pointLocations.ContainsKey(point)
                    )
                {
                    Vector3 newNormal = Vector3.Normalize(pointLocations[point]);
                    pointLocations[point] = radius * newNormal;
                    if (
                        (pointNormals != null) &&
                        pointNormals.ContainsKey(point)
                        )
                    {
                        pointNormals[point] = newNormal;
                    }
                }
            }
            foreach (Polygon polygon in Polygons)
            {
                if (
                    (polygonCentroids != null) &&
                    polygonCentroids.ContainsKey(polygon)
                    )
                {
                    Vector3 newNormalizedCentroid = Vector3.Normalize(polygonCentroids[polygon]);
                    polygonCentroids[polygon] = radius * newNormalizedCentroid;
                    if (
                        (polygonNormals != null) &&
                        polygonNormals.ContainsKey(polygon)
                        )
                    {
                        polygonNormals[polygon] = newNormalizedCentroid;
                    }
                }
                if (cornerNormals != null)
                {
                    foreach (Corner corner in polygon.Corners)
                    {
                        if (
                            cornerNormals.ContainsKey(corner)
                            )
                        {
                            if (pointNormals.ContainsKey(corner.Point))
                            {
                                cornerNormals[corner] = pointNormals[corner.Point];
                            }
                            else if (pointLocations.ContainsKey(corner.Point))
                            {
                                cornerNormals[corner] = pointLocations[corner.Point] * rInv;
                            }
                        }
                    }
                }
            }
        }