Exemplo n.º 1
0
        private void CreateNodes(TreeNode node, Node sceneNode)
        {
            foreach (Node childNode in sceneNode.ChildNodes)
            {
                if (ABUtils.IsHidden(childNode))
                {
                    continue;
                }
                TreeNode childTree = new SceneNodeWrapper(childNode, Img_Node);
                CreateNodes(childTree, childNode);
                node.Nodes.Add(childTree);
            }

            //create entity nodes
            foreach (Entity entity in sceneNode.Entities)
            {
                if (ABUtils.IsHidden(entity))
                {
                    continue;
                }
                int img = Img_Geometry;
                if (entity is Camera)
                {
                    img = Img_Camera;
                }
                else if (entity is Light)
                {
                    img = Img_Light;
                }
                node.Nodes.Add(new SceneNodeWrapper(entity, img));
            }
            //create material nodes
            foreach (Material mat in sceneNode.Materials)
            {
                if (mat == null)
                {
                    continue;
                }
                var matNode = new SceneNodeWrapper(mat, Img_Material);
                CreateTextureNode(matNode, mat, Material.MapDiffuse);
                CreateTextureNode(matNode, mat, Material.MapAmbient);
                CreateTextureNode(matNode, mat, Material.MapEmissive);
                CreateTextureNode(matNode, mat, Material.MapNormal);
                CreateTextureNode(matNode, mat, "Occlusion");
                CreateTextureNode(matNode, mat, "MetallicRoughness");
                node.Nodes.Add(matNode);
            }
        }
    private void OnGUI()
    {
        GUILayout.BeginVertical();
        GUILayout.Space(10);
        GUILayout.Space(15);
        if (isSelecteChanged)
        {
            isSelecteChanged = false;
            resPaths.Clear();
        }
        if (GUILayout.Button("依赖打包"))
        {
            ABUtils.BuildAllAbAboutDependency(ResourceSystemFacade.AbOutPath);
        }

        if (GUILayout.Button("非依赖快速打包"))
        {
        }



        GUILayout.EndVertical();
    }
Exemplo n.º 3
0
        private void CreateNodes(TreeNode node, Node sceneNode)
        {
            foreach (Node childNode in sceneNode.ChildNodes)
            {
                if (ABUtils.IsHidden(childNode))
                {
                    continue;
                }
                TreeNode childTree = new SceneNodeWrapper(childNode, Img_Node);
                CreateNodes(childTree, childNode);
                node.Nodes.Add(childTree);
            }

            //create entity nodes
            foreach (Entity entity in sceneNode.Entities)
            {
                if (ABUtils.IsHidden(entity))
                {
                    continue;
                }
                int img = Img_Geometry;
                if (entity is Camera)
                {
                    img = Img_Camera;
                }
                else if (entity is Light)
                {
                    img = Img_Light;
                }
                node.Nodes.Add(new SceneNodeWrapper(entity, img));
            }
            //create material nodes
            foreach (Material mat in sceneNode.Materials)
            {
                node.Nodes.Add(new SceneNodeWrapper(mat, Img_Material));
            }
        }
Exemplo n.º 4
0
        public void SceneUpdated(string fileName)
        {
            //create the default camera, and update all viewports to use this camera
            //not all file formats support camera(e.g. STL/obj), and even they support, the file may not define a camera
            //so we need to manually define one
            camera     = new Camera();
            cameraNode = Scene.RootNode.CreateChildNode("aab-camera", camera);
            CalculateCamera(Scene, camera);


            //calculate the center of the whole scene
            foreach (Viewport vp in viewports)
            {
                vp.Frustum = camera;
            }

            movement = Movement.Create <StandardMovement>(this, camera, Scene);

            //update camera's position with new elevation
            UpdateCameraPosition();


            //if the scene loaded has no light, we should also add some lights, otherwise the renderer will disable lighting and only show diffuse color
            int lights = 0;

            Scene.RootNode.Accept(delegate(Node n)
            {
                if (n.GetEntity <Light>() != null)//found the light, increment the light counter
                {
                    lights++;
                }
                return(lights == 0);//continue to search if no lights found
            });
            if (lights == 0)
            {
                //no light found in the scene, manually add a direction light
                Node lightNode = Scene.RootNode.CreateChildNode("aab-light1", new Light()
                {
                    LightType    = LightType.Directional,
                    RotationMode = RotationMode.FixedDirection,
                    Direction    = new Vector3(1, 0.4, 0),
                    NearPlane    = 0.1,
                    Color        = new Vector3(Color.Lavender)
                });
                lightNode.Excluded = true; //generated by Asset browser, we don't want it to be exported
                lightNode          = Scene.RootNode.CreateChildNode("aab-light2", new Light()
                {
                    LightType    = LightType.Directional,
                    RotationMode = RotationMode.FixedDirection,
                    Direction    = new Vector3(-1, -0.4, 0),
                    NearPlane    = 0.1,
                    Color        = new Vector3(Color.Lavender)
                });
                lightNode.Excluded = true; //generated by Asset browser, we don't want it to be exported
            }
            //prepare the global ambient color, because a lot of file formats doesn't have this
            if (!Scene.AssetInfo.Ambient.HasValue)
            {
                Scene.AssetInfo.Ambient = new Vector4(Color.AliceBlue);
            }

            //make sure the renderer can find the texture in the same folder
            renderer.AssetDirectories.Clear();
            if (!string.IsNullOrEmpty(fileName))
            {
                var fileDir = Path.GetDirectoryName(fileName);
                renderer.AssetDirectories.Add(fileDir);
                renderer.AssetDirectories.Add("textures");
            }

            //when scene reloaded, should manually clear the internal cache(textures/models) used in previous scene
            //it's ok to not clear the cache but may make your application consume more system and video memories
            renderer.ClearCache();

            //now we attach a grid object to the scene
            ABUtils.CreateInternalNode(Scene.RootNode, "aab-grid", grid = new Grid());
            ABUtils.CreateInternalNode(Scene.RootNode, "aab-axises", new Axises());
            ABUtils.CreateInternalNode(Scene.RootNode, "aab-background", new Background());
            SetUpVector(up);

            Invalidate();
        }
Exemplo n.º 5
0
        public void SceneUpdated(string fileName)
        {
            //create the default camera, and update all viewports to use this camera
            //not all file formats support camera(e.g. STL/obj), and even they support, the file may not define a camera
            //so we need to manually define one
            camera              = new Camera();
            cameraNode          = Scene.RootNode.CreateChildNode("aab-camera", camera);
            cameraNode.Excluded = true;//generated by Asset browser, we don't want it to be exported
            camera.FarPlane     = 4000;
            camera.NearPlane    = 0.1;
            cameraNode.Transform.Translation = new Vector3(10, 10, 10);
            camera.LookAt = Vector3.Origin;
            foreach (Viewport vp in viewports)
            {
                vp.Frustum = camera;
            }

            movement = Movement.Create <StandardMovement>(this, camera, Scene);

            //update camera's position with new elevation
            UpdateCameraPosition();


            //if the scene loaded has no light, we should also add some lights, otherwise the renderer will disable lighting and only show diffuse color
            int lights = 0;

            Scene.RootNode.Accept(delegate(Node n)
            {
                if (n.GetEntity <Light>() != null)//found the light, increment the light counter
                {
                    lights++;
                }
                return(lights == 0);//continue to search if no lights found
            });
            if (lights == 0)
            {
                //no light found in the scene, manually add some lights in random positions
                Random r         = new Random();
                double elevation = Scene.RootNode.GetBoundingBox().Maximum.Length;
                for (int i = 0; i < 2; i++)
                {
                    Vector3 pos = new Vector3();
                    pos.x = (r.NextDouble() - 0.5) * 2 * elevation;
                    pos.y = (r.NextDouble() - 0.5) * 2 * elevation;
                    pos.z = (r.NextDouble() - 0.5) * 2 * elevation;

                    Node lightNode = Scene.RootNode.CreateChildNode("aab-light#" + i, new Light()
                    {
                        LightType = LightType.Point,
                        NearPlane = 0.1,
                        Color     = new Vector3(Color.Lavender)
                    });
                    lightNode.Transform.Translation = pos;
                    lightNode.Excluded = true;//generated by Asset browser, we don't want it to be exported
                }
            }
            //prepare the global ambient color, because a lot of file formats doesn't have this
            if (!Scene.AssetInfo.Ambient.HasValue)
            {
                Scene.AssetInfo.Ambient = new Vector4(Color.AliceBlue);
            }

            //make sure the renderer can find the texture in the same folder
            renderer.AssetDirectories.Clear();
            if (!string.IsNullOrEmpty(fileName))
            {
                renderer.AssetDirectories.Add(Path.GetDirectoryName(fileName));
            }

            //when scene reloaded, should manually clear the internal cache(textures/models) used in previous scene
            //it's ok to not clear the cache but may make your application consume more system and video memories
            renderer.ClearCache();

            //now we attach a grid object to the scene
            ABUtils.CreateInternalNode(Scene.RootNode, "aab-grid", new Grid(renderer, gridShader));

            Invalidate();
        }