private List<Object3D> ConvertGroupingNode(GroupingNode node, float[,] transformation)
 {
     if (node is TransformNode) {
         float[,] matrix = ((TransformNode)node).GenerateTransformMatrix();
         VrmlMath.ConcatenateMatrixes(transformation, matrix, matrix);
         transformation = matrix;
     }
     Shape3DComposite shapes = new Shape3DComposite();
     List<Object3D> objects = new List<Object3D>();
     objects.Add(shapes);
     foreach (Node child in node.children) {
         List<Object3D> t = ConvertNode(child, transformation);
         foreach (Object3D obj in t) {
             if (obj != null) {
                 if (obj is Shape3D) {
                     shapes.Add((Shape3D)obj);
                 } else {
                     objects.Add(obj);
                 }
             }
         }
     }
     return objects;
 }
Esempio n. 2
0
        public void Visit(Box3D box)
        {
            Shape3DComposite composite = new Shape3DComposite();
            composite.CoordinateSystem = box.CoordinateSystem;

            float dx = box.Width / 2;
            float dy = box.Height / 2;
            float dz = box.Depth / 2;

            var top = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, -dy, +dz),
                C = new Vector3D(+dx, -dy, -dz),
                Material = box.Material
            };

            var bottom = new Rectangle3D {
                A = new Vector3D(-dx, +dy, -dz),
                B = new Vector3D(-dx, +dy, +dz),
                C = new Vector3D(+dx, +dy, -dz),
                Material = box.Material
            };

            var left = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, +dy, -dz),
                C = new Vector3D(-dx, -dy, +dz),
                Material = box.Material
            };

            var right = new Rectangle3D {
                A = new Vector3D(+dx, -dy, -dz),
                B = new Vector3D(+dx, +dy, -dz),
                C = new Vector3D(+dx, -dy, +dz),
                Material = box.Material
            };

            var front = new Rectangle3D {
                A = new Vector3D(-dx, -dy, -dz),
                B = new Vector3D(-dx, +dy, -dz),
                C = new Vector3D(+dx, -dy, -dz),
                Material = box.Material
            };

            var back = new Rectangle3D {
                A = new Vector3D(-dx, -dy, +dz),
                B = new Vector3D(-dx, +dy, +dz),
                C = new Vector3D(+dx, -dy, +dz),
                Material = box.Material
            };

            composite.Add(top);
            composite.Add(bottom);
            composite.Add(left);
            composite.Add(right);
            composite.Add(front);
            composite.Add(back);

            Visit(composite);
        }
 private Shape3D ConvertShapeNode(ShapeNode node, float[,] transformation)
 {
     AppearanceNode appearance = (AppearanceNode)node.appearance.Node;
     MaterialNode material = appearance.material.Node as MaterialNode;
     if (node.geometry.Node is SphereNode) {
         SphereNode sphereNode = (SphereNode)node.geometry.Node;
         Sphere3D sphere = new Sphere3D();
         //sphere.Position = new Graph3D.Framework.Math.Vector3D(0, 0, 0);
         sphere.Radius = sphereNode.radius.Value;
         SetAppearance(sphere, appearance);
         return sphere;
     }
     if (node.geometry.Node is BoxNode) {
         return null;
     }
     if (node.geometry.Node is IndexedFaceSetNode) {
         IndexedFaceSetNode faceSetNode = (IndexedFaceSetNode)node.geometry.Node;
         Shape3DComposite composite = new Shape3DComposite();
         int facesCount = 0;
         for (int i = 0; i < faceSetNode.coordIndex.length; i++)
             if (faceSetNode.coordIndex[i] == -1) facesCount++;
         MFVec3f coords = ((CoordinateNode)faceSetNode.coord.Node).point;
         for (int faceOffsetIndex = 0; faceOffsetIndex < faceSetNode.coordIndex.length; faceOffsetIndex++) {
             Triangle3D triangle;
             triangle = new Triangle3D();
             SFVec3f a = coords[faceSetNode.coordIndex[faceOffsetIndex]];
             SFVec3f b = coords[faceSetNode.coordIndex[faceOffsetIndex + 1]];
             SFVec3f c = coords[faceSetNode.coordIndex[faceOffsetIndex + 2]];
             triangle.A = ConvertVector3D(a, transformation);
             triangle.B = ConvertVector3D(b, transformation);
             triangle.C = ConvertVector3D(c, transformation);
             SetAppearance(triangle, appearance);
             composite.Add(triangle);
             faceOffsetIndex += 3;
             while (faceSetNode.coordIndex[faceOffsetIndex] != -1) {
                 faceOffsetIndex++;
             }
         }
         triangles += facesCount;
         return composite;
     }
     return null;
 }
Esempio n. 4
0
 private List<Object3D> WrapTransform(TransformNode node, float[,] transformation)
 {
     float[,] matrix = node.GenerateTransformMatrix();
     Shape3DComposite shapes = new Shape3DComposite();
     List<Object3D> objects = new List<Object3D>();
     objects.Add(shapes);
     foreach (BaseNode child in node) {
         List<Object3D> t = TestConvNode(child);
         foreach (Object3D obj in t) {
             if (obj != null) {
                 if (obj is Shape3D) {
                     shapes.Add((Shape3D)obj);
                 } else {
                     objects.Add(obj);
                 }
             }
         }
     }
     return objects;
 }