示例#1
0
        public void OBJ_file_is_correctly_parsed_whatever_the_current_culture(string culture)
        {
            using (TestHelper.SetCurrentCulture(culture))
            {
                var path          = TestHelper.ResolvePath(@"data\ducky.obj");
                var objFileFormat = new ObjFileFormat();
                var scene         = objFileFormat.LoadData(path);
                var polygon       = (Polygon)scene.SceneContainer.Children.First();

                // The first texture coordinate line with a floating-point value is: vt 0.219297 1 0
                var uv = polygon.UVs.First(x => (int)x.U != x.U);
                Assert.That(uv, Is.EqualTo(new UV(0.219297f, 0f)));

                // We cannot test normals for now as there are none in our test file

                // The first vertex line is: v 29.564405 140.987503 67.743927
                var vertex = polygon.Vertices.First();
                Assert.That(vertex, Is.EqualTo(new Vertex(29.564405f, 140.987503f, 67.743927f)));

                // Materials should have been read too
                // First material is DBody; its ambient light is defined as: Ka 1.0000 0.6667 0.0000
                // This shoudl give us (in ARGB): FFFFAA00

                var material = (Material)scene.Assets.First();
                Assert.AreEqual("DBody", material.Name);
                Assert.That(material.Ambient, Is.EqualTo(Color.FromArgb(0xFF, 0xFF, 0xAA, 0x00)));
            }
        }
示例#2
0
        private void openGLControl1_Load(object sender, EventArgs e)
        {
            var obj      = new ObjFileFormat();
            var objScene = obj.LoadData("Assets/cansat_gotowy.obj");

            foreach (var asset in objScene.Assets)
            {
                openGLControl1.Scene.Assets.Add(asset);
            }

            openGLControl1.Scene.RenderBoundingVolumes = false;

            var polygons = objScene.SceneContainer.Traverse <Polygon>().ToList();


            foreach (Polygon polygon in polygons)
            {
                polygon.Transformation.RotateX = 90f; // rotate to right direction

                polygon.Parent.RemoveChild(polygon);
                polygon.Transformation.ScaleX = 8f;
                polygon.Transformation.ScaleY = 8f;
                polygon.Transformation.ScaleZ = 8f;

                polygon.Freeze(openGLControl1.OpenGL);

                openGLControl1.Scene.SceneContainer.AddChild(polygon);

                // Add effects.
                polygon.AddEffect(new OpenGLAttributesEffect());
                //polygon.AddEffect(arcBallEffect); //DEBUG Mouse 3d object
            }
        }
示例#3
0
        private void InitializeScene()
        {
            sceneControl.MouseDown += new MouseEventHandler(sceneControl_MouseDown);
            sceneControl.MouseMove += new MouseEventHandler(sceneControl_MouseMove);
            sceneControl.MouseUp   += new MouseEventHandler(sceneControl_MouseUp);

            //  Add some design-time primitives.
            sceneControl.Scene.SceneContainer.AddChild(new Grid());
            sceneControl.Scene.SceneContainer.AddChild(new Axies());

            // Let's load ducky
            var obj      = new ObjFileFormat();
            var objScene = obj.LoadData(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data", "ducky.obj"));

            // Add the materials to the scene
            foreach (var asset in objScene.Assets)
            {
                sceneControl.Scene.Assets.Add(asset);
            }

            // Get the polygons
            var polygons = objScene.SceneContainer.Traverse <Polygon>().ToList();

            // Add each polygon (There is only one in ducky.obj)
            foreach (var polygon in polygons)
            {
                polygon.Name = "Ducky";
                polygon.Transformation.RotateX = 90f; // So that Ducky appears in the right orientation

                //  Get the bounds of the polygon.
                var boundingVolume = polygon.BoundingVolume;
                var extent         = new float[3];
                polygon.BoundingVolume.GetBoundDimensions(out extent[0], out extent[1], out extent[2]);

                // Get the max extent.
                var maxExtent = extent.Max();

                // Scale so that we are at most 10 units in size.
                var scaleFactor = maxExtent > 10 ? 10.0f / maxExtent : 1;

                polygon.Parent.RemoveChild(polygon);
                polygon.Transformation.ScaleX = scaleFactor;
                polygon.Transformation.ScaleY = scaleFactor;
                polygon.Transformation.ScaleZ = scaleFactor;
                polygon.Freeze(sceneControl.OpenGL);
                sceneControl.Scene.SceneContainer.AddChild(polygon);

                // Add effects.
                polygon.AddEffect(new OpenGLAttributesEffect());
                polygon.AddEffect(arcBallEffect);
            }
        }
        public FigureFromOBJSharpGL(OpenGL gl, Point3D position, string fileName, float scale = 1,
                                    float rotX = 0)
            : base(position)
        {
            ObjFileFormat objFile = new ObjFileFormat();
            var           res     = objFile.LoadData(fileName);

            ListInd = gl.GenLists(1);
            gl.NewList(ListInd, OpenGL.GL_COMPILE);
            {
                gl.Translate(position.x, position.y, position.z);
                if (rotX != 0)
                {
                    gl.Rotate(rotX, 0, 0);
                }
                gl.Scale(scale, scale, scale);
                DrawFigure(gl, res.SceneContainer.Traverse <Polygon>().ElementAt(0));
            }
            gl.EndList();
        }