Exemplo n.º 1
0
        public void AdjustModelScaleOffset()
        {
            AABBf?box = null;


            if (_scene == null || (box = box = new AABBCalculator(_scene).GetBox()) == null)
            {
                _modelScaleOffset = float4x4.Identity;
            }
            var   bbox  = ((AABBf)box);
            float scale = Math.Max(Math.Max(bbox.Size.x, bbox.Size.y), bbox.Size.z);

            _modelScaleOffset = float4x4.CreateScale(200.0f / scale) * float4x4.CreateTranslation(-bbox.Center);
        }
Exemplo n.º 2
0
        // Init is called on startup.
        public override void Init()
        {
            // VERSION 1 - SYNCHRONER DOWNLOAD

            /*
             * ButtonDown += delegate (object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  string fileContents = client.DownloadString(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             *  Ticker.CompleteText = fileContents;
             * };
             * /* */


            // VERSION 2 - Asynchronous Programming Model (APM) - wird von WebClient nicht unterstützt, daher kein Beispiel

            // VERSION 3 - Event Based Asynchronous Pattern (EAP)

            /*
             * ButtonDown += delegate (object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  client.DownloadStringCompleted += delegate(object o, DownloadStringCompletedEventArgs eventArgs)
             *  {
             *      Ticker.CompleteText = eventArgs.Result;
             *  };
             *  client.DownloadStringAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             * };
             * /*  */


            // VERSION 4 - Task-based Asynchronous Pattern (TAP)

            /*
             * ButtonDown += async delegate (object sender, EventArgs args)
             * {
             *  WebClient client = new WebClient();
             *
             *  String fileContents = await client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
             *  // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen
             *  Ticker.CompleteText = fileContents;
             *
             * };
             * /*  */


            /* */
            // VERSION 5 - Task-based Asynchronous Pattern (TAP) mit getrenntem await
            ButtonDown += async delegate(object sender, EventArgs args)
            {
                WebClient client = new WebClient();

                Task <string> task = client.DownloadStringTaskAsync(new Uri("http://www.fusee3d.org/Examples/Async/SomeText.txt"));
                // Dinge, die direkt nach dem Starten des Task passieren sollen

                Ticker.CompleteText = "- - - D O W N L O A D I N G - - - T H E   C O M P L E T E   W O R K S   O F   W I L L I A M   S H A K E S P E A R E ";


                // Vor dem await - hier passiert alles direkt nach dem Starten des Task
                String fileContents = await task;
                // Nach dem await - Code der hier steht, wird erst nach dem ENDE des Task aufgerufen
                Ticker.CompleteText = fileContents;
            };
            /*  */



            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            _guiFuseeLink                   = new GUIButton(6, 6, 253, 221);
            _guiFuseeLink.ButtonColor       = new float4(0, 0, 0, 0);
            _guiFuseeLink.BorderColor       = new float4(0.6f, 0.2f, 0.2f, 1);
            _guiFuseeLink.BorderWidth       = 0;
            _guiFuseeLink.OnGUIButtonDown  += _guiFuseeLink_OnGUIButtonDown;
            _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter;
            _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave;
            _guiHandler.Add(_guiFuseeLink);
            _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("ClickMe.png"), 10, 10, -5, 253, 221);
            _guiHandler.Add(_guiFuseeLogo);
            var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf");

            fontLato.UseKerning   = true;
            _guiLatoBlack         = new FontMap(fontLato, 64);
            _guiSubText           = new GUIText(Ticker.CurrentText, _guiLatoBlack, 100, 100);
            _guiSubText.TextColor = new float4(0, 0, 0.15f, 0.8f);
            _guiHandler.Add(_guiSubText);
            _subtextWidth  = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack);
            _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack);

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>("Model.fus");
            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotating around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }
            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRenderer(_scene);
        }
Exemplo n.º 3
0
        // Init is called on startup.
        public override void Init()
        {
            _initCanvasWidth  = Width / 100f;
            _initCanvasHeight = Height / 100f;

            _canvasHeight = _initCanvasHeight;
            _canvasWidth  = _initCanvasWidth;

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>(ModelFile);

            _gui = CreateGui();
            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            // Register the input devices that are not already given.
            _gamePad = GetDevice <GamePadDevice>(0);

            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
Exemplo n.º 4
0
        // Init is called on startup.
        public override void Init()
        {
            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>(ModelFile);


            //TODO: export the correct material - with bump channel - from blender exporter
            //Problem: because of the initial scene convert in main.cs we do not have a material component but a shader effect here

            //_scene.Children[0].GetComponent<MaterialComponent>().Bump = new BumpChannelContainer
            //{
            //    Intensity = 0.5f,
            //    Texture = "bump.png"
            //};

            //_scene.Children[0].Children[1].GetComponent<MaterialComponent>().Bump = new BumpChannelContainer
            //{
            //    Intensity = 1.0f,
            //    Texture = "bump.png"
            //};

            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            var projComp = _scene.Children[0].GetComponent <ProjectionComponent>();

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRenderer(_scene);
        }
Exemplo n.º 5
0
        // Init is called on startup.
        public override void Init()
        {
            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = new SceneContainer
            {
                Children = new List <SceneNodeContainer>
                {
                    new SceneNodeContainer
                    {
                        Components = new List <SceneComponentContainer>
                        {
                            new TransformComponent
                            {
                                Rotation    = float3.Zero,
                                Translation = new float3(0, 0, 0),
                                Scale       = float3.One
                            },
                            new BoneComponent()
                        },
                        Children = new ChildList()
                        {
                            new SceneNodeContainer
                            {
                                Components = new List <SceneComponentContainer>
                                {
                                    new TransformComponent
                                    {
                                        Rotation    = float3.Zero,
                                        Translation = new float3(0, 0.5f, 0),
                                        Scale       = float3.One
                                    },
                                    new BoneComponent(),
                                    new WeightComponent(),
                                    new MaterialComponent
                                    {
                                        Diffuse = new MatChannelContainer
                                        {
                                            Color = new float4(1.0f, 0.4f, 0.2f, 1.0f)
                                        }
                                    },
                                    CreateCuboid(float3.One)
                                }
                            }
                        }
                    }
                }
            };
            _scene = AssetStorage.Get <SceneContainer>("BoneAnim.fus");
            // convert scene graph is not called in this project, so we can add a bone animation

            // then add a weightcomponent with weight matrices etc:
            // binding matrices is the start point of every transformation
            // as many entries as vertices are present in current model
            //var cube = _scene.Children[0].GetComponent<Mesh>();
            //var vertexCount = cube.Vertices.Length;

            //var bindingMatrices = new List<float4x4>();
            //for (var i = 0; i < vertexCount; i++)
            //{
            //    bindingMatrices.Add(float4x4.Identity);
            //}
            var mesh      = _scene.Children[1].Children[2].GetComponent <Mesh>();
            var wm        = _scene.Children[1].Children[2].GetComponent <WeightComponent>();
            var WeightMap = new List <VertexWeightList>();

            for (var i = 0; i < mesh.Vertices.Length; i++)
            {
                WeightMap.Add(new VertexWeightList
                {
                    VertexWeights = new List <VertexWeight>
                    {
                        new VertexWeight
                        {
                            JointIndex = 0,
                            Weight     = (mesh.Vertices[i].y > 0 ? 1: 0f)
                        },
                        new VertexWeight()
                        {
                            JointIndex = 1,
                            Weight     = (mesh.Vertices[i].y <= 0 ? 1f: 0f)
                        }
                    }
                });
            }
            wm.WeightMap = WeightMap;
            var weightMapFromScene = _scene.Children[1].Children[2].Components[1];

            //_scene.Children.Insert(0, new SceneNodeContainer()
            //{
            //    Name = "BoneContainer1",
            //    Components = new List<SceneComponentContainer>()
            //    {
            //        new TransformComponent()
            //        {
            //            Translation = new float3(0, 2, 0),
            //            Scale = new float3(1, 1, 1)
            //        },


            //    },
            //    Children = new ChildList
            //    {
            //        new SceneNodeContainer()
            //        {
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -1f, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },
            //                new BoneComponent(),
            //                new Cube()
            //            }
            //        },


            //        new SceneNodeContainer()
            //        {
            //            Name = "BoneContainer2",
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -2, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },

            //            },

            //            Children = new ChildList
            //            {

            //                new SceneNodeContainer
            //                {

            //                Components = new List<SceneComponentContainer>()
            //                {
            //                    new TransformComponent()
            //                    {
            //                        Translation = new float3(0, -0.5f, 0),
            //                        Scale = new float3(1,1,1)
            //                    },
            //                    new BoneComponent(),
            //                    new Cube()
            //                }
            //                }
            //            }

            //        }
            //    }

            //});

            //_scene.Children[1].Components.Insert(1, new WeightComponent
            //{
            //    BindingMatrices = bindingMatrices,
            //    WeightMap = WeightMap
            //    // Joints are added automatically during scene conversion (ConvertSceneGraph)
            //});

            ////_scene = AssetStorage.Get<SceneContainer>("BoneAnim.fus");
            //// now we can convert the scene
            //_scene = new ConvertSceneGraph().Convert(_scene);

            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            var projComp = _scene.Children[0].GetComponent <ProjectionComponent>();

            AddResizeDelegate(delegate { projComp.Resize(Width, Height); });

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRenderer(_scene);
        }
Exemplo n.º 6
0
        // Init is called on startup.
        public override void Init()
        {
            _guiHandler = new GUIHandler();
            _guiHandler.AttachToContext(RC);

            _guiFuseeLink                   = new GUIButton(6, 6, 253, 221);
            _guiFuseeLink.ButtonColor       = new float4(0, 0, 0, 0);
            _guiFuseeLink.BorderColor       = new float4(0.6f, 0.2f, 0.2f, 1);
            _guiFuseeLink.BorderWidth       = 0;
            _guiFuseeLink.OnGUIButtonDown  += _guiFuseeLink_OnGUIButtonDown;
            _guiFuseeLink.OnGUIButtonEnter += _guiFuseeLink_OnGUIButtonEnter;
            _guiFuseeLink.OnGUIButtonLeave += _guiFuseeLink_OnGUIButtonLeave;
            _guiHandler.Add(_guiFuseeLink);
            _guiFuseeLogo = new GUIImage(AssetStorage.Get <ImageData>("ClickMe.png"), 10, 10, -5, 253, 221);
            _guiHandler.Add(_guiFuseeLogo);
            var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf");

            fontLato.UseKerning   = true;
            _guiLatoBlack         = new FontMap(fontLato, 64);
            _guiSubText           = new GUIText(Ticker.CurrentText, _guiLatoBlack, 100, 100);
            _guiSubText.TextColor = new float4(0, 0, 0.15f, 0.8f);
            _guiHandler.Add(_guiSubText);
            _subtextWidth  = GUIText.GetTextWidth(_guiSubText.Text, _guiLatoBlack);
            _subtextHeight = GUIText.GetTextHeight(_guiSubText.Text, _guiLatoBlack);

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the backbuffer to white (100% intentsity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            // Load the standard model
            _scene = AssetStorage.Get <SceneContainer>("Model.fus");
            AABBCalculator aabbc = new AABBCalculator(_scene);
            var            bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotating around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }
            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRenderer(_scene);
        }
Exemplo n.º 7
0
        // Init is called on startup.
        public override void Init()
        {
            Diagnostics.Warn("[05/2020] Bone animation is disabled for now due to the Blender exporter not be able to export bones!");

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = float4.One;

            // Load the standard model

            _scene = AssetStorage.Get <SceneContainer>("BoneAnim.fus");
            _gui   = CreateGui();

            #region LEGACY CODE - REFERENCE ONLY!

            /*
             * =====================================================================================
             * // then add a weightcomponent with weight matrices etc:
             * // binding matrices is the start point of every transformation
             * // as many entries as vertices are present in current model
             * var cube = _scene.Children[0].GetComponent<Mesh>();
             * var vertexCount = cube.Vertices.Length;
             *
             * var bindingMatrices = new List<float4x4>();
             * for (var i = 0; i < vertexCount; i++)
             * {
             *  bindingMatrices.Add(float4x4.Identity);
             * }
             * Mesh mesh = _scene.Children[1].Children[2].GetComponent<Mesh>();
             * Weight wm = _scene.Children[1].Children[2].GetComponent<Weight>();
             * List<VertexWeightList> WeightMap = new List<VertexWeightList>();
             * for (int i = 0; i < mesh.Vertices.Length; i++)
             * {
             *  WeightMap.Add(new VertexWeightList
             *  {
             *      VertexWeights = new List<VertexWeight>
             *      {
             *          new VertexWeight
             *          {
             *              JointIndex = 0,
             *              Weight = (mesh.Vertices[i].y > 0 ? 1: 0f)
             *          },
             *          new VertexWeight()
             *          {
             *              JointIndex = 1,
             *              Weight = (mesh.Vertices[i].y <= 0 ? 1f: 0f)
             *          }
             *      }
             *  });
             * }
             * wm.WeightMap = WeightMap;
             * SceneComponent weightMapFromScene = _scene.Children[1].Children[2].Components[1];
             *
             * _scene.Children.Insert(0, new SceneNode()
             * {
             *  Name = "BoneContainer1",
             *  Components = new List<SceneComponentContainer>()
             *  {
             *      new TransformComponent()
             *      {
             *          Translation = new float3(0, 2, 0),
             *          Scale = new float3(1, 1, 1)
             *      },
             *
             *  },
             *  Children = new ChildList
             *  {
             *      new SceneNode()
             *      {
             *          Components = new List<SceneComponentContainer>
             *          {
             *              new TransformComponent
             *              {
             *                  Translation = new float3(0, -1f, 0),
             *                  Scale = new float3(1, 2, 1)
             *              },
             *              new BoneComponent(),
             *              new Cube()
             *          }
             *      },
             *
             *      new SceneNode()
             *      {
             *          Name = "BoneContainer2",
             *          Components = new List<SceneComponentContainer>
             *          {
             *              new TransformComponent
             *              {
             *                  Translation = new float3(0, -2, 0),
             *                  Scale = new float3(1, 2, 1)
             *              },
             *
             *          },
             *
             *          Children = new ChildList
             *          {
             *              new SceneNode
             *              {
             *              Components = new List<SceneComponentContainer>()
             *              {
             *                  new TransformComponent()
             *                  {
             *                      Translation = new float3(0, -0.5f, 0),
             *                      Scale = new float3(1,1,1)
             *                  },
             *                  new BoneComponent(),
             *                  new Cube()
             *              }
             *              }
             *          }
             *
             *      }
             *  }
             *
             * });
             *
             * _scene.Children[1].Components.Insert(1, new WeightComponent
             * {
             *  BindingMatrices = bindingMatrices,
             *  WeightMap = WeightMap
             *  // Joints are added automatically during scene conversion (ConvertSceneGraph)
             * });
             *
             */
            #endregion

            AABBCalculator aabbc = new AABBCalculator(_scene);
            AABBf?         bbox  = aabbc.GetBox();
            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                var bbCenter = bbox.Value.Center;
                var bbSize   = bbox.Value.Size;
                var center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                var maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }
Exemplo n.º 8
0
        // Init is called on startup.
        public override void Init()
        {
            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 2;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the backbuffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            _meshTransform = new Transform();

            _scene = new SceneContainer()
            {
                Children = new List <SceneNode>()
                {
                    new SceneNode()
                    {
                        Components = new List <SceneComponent>()
                        {
                            _meshTransform,
                            new Plane()
                        }
                    }
                }
            };

            var albedoTex = new Texture(AssetStorage.Get <ImageData>("Bricks_1K_Color.png"));
            var normalTex = new Texture(AssetStorage.Get <ImageData>("Bricks_1K_Normal.png"));

            var normalMappingEffect = MakeEffect.FromDiffuseSpecularTexture(float4.One, float4.Zero, albedoTex, normalTex, 1.0f, new float2(2, 2), 85, 0.2f, 0.3f);

            normalMappingEffect.RendererStates.AlphaBlendEnable = true;
            normalMappingEffect.RendererStates.SourceBlend      = Blend.SourceAlpha;
            normalMappingEffect.RendererStates.DestinationBlend = Blend.InverseSourceAlpha;
            normalMappingEffect.RendererStates.BlendOperation   = BlendOperation.Add;

            _mesh            = _scene.Children[0].GetComponent <Plane>();
            _mesh.Tangents   = _mesh.CalculateTangents();
            _mesh.BiTangents = _mesh.CalculateBiTangents();
            _scene.Children[0].Components.Insert(1, normalMappingEffect);

            AABBCalculator aabbc = new AABBCalculator(_scene);
            AABBf?         bbox  = aabbc.GetBox();

            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                float3 bbCenter = bbox.Value.Center;
                float3 bbSize   = bbox.Value.Size;
                float3 center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }

                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }

                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }

                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                float maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
        }
Exemplo n.º 9
0
        // Init is called on startup.
        public override void Init()
        {
            _gui = CreateGui();

            // Create the interaction handler
            _sih = new SceneInteractionHandler(_gui);

            // Initial "Zoom" value (it's rather the distance in view direction, not the camera's focal distance/opening angle)
            _zoom = 400;

            _angleRoll        = 0;
            _angleRollInit    = 0;
            _twoTouchRepeated = false;
            _offset           = float2.Zero;
            _offsetInit       = float2.Zero;

            // Set the clear color for the back buffer to white (100% intensity in all color channels R, G, B, A).
            RC.ClearColor = new float4(1, 1, 1, 1);

            //----- DUMMY SCENE BELOW - use the fus file when the exporter is able to export bones again ---- //
            //_scene = AssetStorage.Get<SceneContainer>("BoneAnim.fus");

            _scene = new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    new SceneNode
                    {
                        Components = new List <SceneComponent>
                        {
                            new Transform
                            {
                                Rotation    = float3.Zero,
                                Translation = new float3(0, 0, 0),
                                Scale       = float3.One
                            },
                            new Engine.Core.Scene.Bone()
                        },
                        Children = new ChildList()
                        {
                            new SceneNode
                            {
                                Components = new List <SceneComponent>
                                {
                                    new Transform
                                    {
                                        Rotation    = float3.Zero,
                                        Translation = new float3(0, 0.5f, 0),
                                        Scale       = new float3(10, 100, 10)
                                    },
                                    new Engine.Core.Scene.Bone(),
                                    new Weight(),
                                    ShaderCodeBuilder.MakeShaderEffect(albedoColor: new float4(1.0f, 0.4f, 0.2f, 1.0f)),
                                    new Cube()
                                }
                            }
                        }
                    }
                }
            };

            var mesh      = _scene.Children[0].Children[0].GetComponent <Cube>();
            var wm        = _scene.Children[0].Children[0].GetComponent <Weight>();
            var WeightMap = new List <VertexWeightList>();

            for (var i = 0; i < mesh.Vertices.Length; i++)
            {
                WeightMap.Add(new VertexWeightList
                {
                    VertexWeights = new List <VertexWeight>
                    {
                        new VertexWeight
                        {
                            JointIndex = 0,
                            Weight     = (mesh.Vertices[i].y > 0 ? 1: 0f)
                        },
                        new VertexWeight()
                        {
                            JointIndex = 1,
                            Weight     = (mesh.Vertices[i].y <= 0 ? 1f: 0f)
                        }
                    }
                });
            }
            wm.WeightMap = WeightMap;
            var weightMapFromScene = _scene.Children[0].Children[0].Components[1];

            #region LEGACY / REFERENCE CODE
            // Add a weightcomponent with weight matrices etc:
            // binding matrices is the start point of every transformation
            // as many entries as vertices are present in current model
            //var cube = _scene.Children[0].GetComponent<Mesh>();
            //var vertexCount = cube.Vertices.Length;

            //var bindingMatrices = new List<float4x4>();
            //for (var i = 0; i < vertexCount; i++)
            //{
            //    bindingMatrices.Add(float4x4.Identity);
            //}

            //_scene.Children.Insert(0, new SceneNode()
            //{
            //    Name = "BoneContainer1",
            //    Components = new List<SceneComponentContainer>()
            //    {
            //        new TransformComponent()
            //        {
            //            Translation = new float3(0, 2, 0),
            //            Scale = new float3(1, 1, 1)
            //        },

            //    },
            //    Children = new ChildList
            //    {
            //        new SceneNode()
            //        {
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -1f, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },
            //                new BoneComponent(),
            //                new Cube()
            //            }
            //        },

            //        new SceneNode()
            //        {
            //            Name = "BoneContainer2",
            //            Components = new List<SceneComponentContainer>
            //            {
            //                new TransformComponent
            //                {
            //                    Translation = new float3(0, -2, 0),
            //                    Scale = new float3(1, 2, 1)
            //                },

            //            },

            //            Children = new ChildList
            //            {
            //                new SceneNode
            //                {
            //                Components = new List<SceneComponentContainer>()
            //                {
            //                    new TransformComponent()
            //                    {
            //                        Translation = new float3(0, -0.5f, 0),
            //                        Scale = new float3(1,1,1)
            //                    },
            //                    new BoneComponent(),
            //                    new Cube()
            //                }
            //                }
            //            }

            //        }
            //    }

            //});

            //_scene.Children[1].Components.Insert(1, new WeightComponent
            //{
            //    BindingMatrices = bindingMatrices,
            //    WeightMap = WeightMap
            //    // Joints are added automatically during scene conversion (ConvertSceneGraph)
            //});

            #endregion

            var aabbc = new AABBCalculator(_scene);
            var bbox  = aabbc.GetBox();
            if (bbox != null)
            {
                // If the model origin is more than one third away from its bounding box,
                // recenter it to the bounding box. Do this check individually per dimension.
                // This way, small deviations will keep the model's original center, while big deviations
                // will make the model rotate around its geometric center.
                var bbCenter = bbox.Value.Center;
                var bbSize   = bbox.Value.Size;
                var center   = float3.Zero;
                if (System.Math.Abs(bbCenter.x) > bbSize.x * 0.3)
                {
                    center.x = bbCenter.x;
                }
                if (System.Math.Abs(bbCenter.y) > bbSize.y * 0.3)
                {
                    center.y = bbCenter.y;
                }
                if (System.Math.Abs(bbCenter.z) > bbSize.z * 0.3)
                {
                    center.z = bbCenter.z;
                }
                _sceneCenter = float4x4.CreateTranslation(-center);

                // Adjust the model size
                var maxScale = System.Math.Max(bbSize.x, System.Math.Max(bbSize.y, bbSize.z));
                if (maxScale != 0)
                {
                    _sceneScale = float4x4.CreateScale(200.0f / maxScale);
                }
                else
                {
                    _sceneScale = float4x4.Identity;
                }
            }

            // Wrap a SceneRenderer around the model.
            _sceneRenderer = new SceneRendererForward(_scene);
            _guiRenderer   = new SceneRendererForward(_gui);
        }