Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="position"></param>
        /// <param name="normal"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static NormalNode Create(IBufferSource model, string position, string normal, vec3 size)
        {
            var builders = new RenderMethodBuilder[2];
            {
                // render model
                var vs       = new VertexShader(vertexShader, vPosition, vNormal);
                var fs       = new FragmentShader(fragmentShader);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                map.Add(vNormal, normal);
                builders[0] = new RenderMethodBuilder(provider, map);
            }
            {
                // render normal
                var vs       = new VertexShader(normalVertex, vPosition, vNormal);
                var gs       = new GeometryShader(normalGeometry);
                var fs       = new FragmentShader(normalFragment);
                var provider = new ShaderArray(vs, gs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                map.Add(vNormal, normal);
                builders[1] = new RenderMethodBuilder(provider, map);
            }

            var node = new NormalNode(model, position, builders);

            node.ModelSize = size;

            node.Initialize();

            return(node);
        }
Ejemplo n.º 2
0
        private void btnOpenObjFile_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string filename = this.openFileDialog1.FileName;
                //
                var          parser = new ObjVNFParser(true);
                ObjVNFResult result = parser.Parse(filename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    var   model = new ObjVNF(result.Mesh);
                    var   node  = NormalNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                    float max   = node.ModelSize.max();
                    node.Scale        *= 16.0f / max;
                    node.WorldPosition = new vec3(0, 0, 0);

                    var rootElement = this.scene.RootElement;
                    this.scene.RootElement = node;
                    if (rootElement != null)
                    {
                        rootElement.Dispose();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            string       folder      = System.Windows.Forms.Application.StartupPath;
            string       objFilename = System.IO.Path.Combine(folder, "nanosuit.obj_");
            var          parser      = new ObjVNFParser(true);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var   model = new ObjVNF(result.Mesh);
                var   node  = NormalNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale            *= 16.0f / max;
                this.scene.RootElement = node;
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="position"></param>
        /// <param name="normal"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static NormalNode Create(IBufferSource model, string position, string texCoord, string normal, vec3 size)
        {
            var builders = new RenderMethodBuilder[2];
            {
                // render model
                var vs       = new VertexShader(vertexShader);
                var fs       = new FragmentShader(fragmentShader);
                var provider = new ShaderArray(vs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                map.Add(vTexCoord, texCoord);
                map.Add(vNormal, normal);
                builders[0] = new RenderMethodBuilder(provider, map);
            }
            {
                // render normal
                var vs       = new VertexShader(normalVertex);
                var gs       = new GeometryShader(normalGeometry);
                var fs       = new FragmentShader(normalFragment);
                var provider = new ShaderArray(vs, gs, fs);
                var map      = new AttributeMap();
                map.Add(vPosition, position);
                map.Add(vNormal, normal);
                builders[1] = new RenderMethodBuilder(provider, map);
            }

            var    node   = new NormalNode(model, position, texCoord, builders);
            string folder = System.Windows.Forms.Application.StartupPath;

            node.TextureSource = new TextureSource(System.IO.Path.Combine(folder, @"superficie.png"));
            node.ModelSize     = size;

            node.Initialize();

            return(node);
        }