예제 #1
0
파일: MyGame.cs 프로젝트: tzsage/Balder
        public override void LoadContent()
        {
            var mesh = ContentManager.Load <Mesh>("audi.ASE");

            //mesh.Position.X = -30;
            mesh.World = Matrix.CreateScale(new Vector(10f, 10f, 10f));
            Scene.AddNode(mesh);

            _lightSprite = ContentManager.Load <Sprite>("sun.png");
            Scene.AddNode(_lightSprite);


            var sprite = ContentManager.Load <Sprite>("recycle.png");

            sprite.Position = new Vector(-10, 0, 0);
            //Scene.AddNode(sprite);

            Display.BackgroundColor = Color.FromArgb(0xff, 0, 0, 0);

            var cylinder = ContentManager.CreateCylinder(10f, 20f, 8, 1);

            light               = new OmniLight();
            light.Range         = 3.0f;
            light.Position.X    = 0;
            light.Position.Y    = 0;
            light.Position.Z    = -30;
            light.ColorDiffuse  = Color.FromArgb(0xff, 0x1f, 0x1f, 0x6f);
            light.ColorSpecular = Color.FromArgb(0xff, 0xff, 0xff, 0xff);
            light.ColorAmbient  = Color.FromArgb(0xff, 0, 0x5f, 0);
            Scene.AddNode(light);
        }
예제 #2
0
        void AddOmniLight()
        {
            light = new OmniLight(15);

            light.Attenuation = Attenuation.None;

            scene.Root.AddChildren(light);

            light.Position = new AIOEngine.MathSpace.Vector3(0, 1, 6);

            light.Color = new AIOEngine.MathSpace.Vector4(1, 1, 1, 1);

            scene.Lights.Add(light);
        }
예제 #3
0
        public override void SpawnNode(GameWorld world)
        {
            if (!world.IsPresentationEnabled)
            {
                return;
            }

            light = new OmniLight();

            light.Intensity   = LightPresetColor.GetColor(LightPreset, Intensity);;
            light.Position    = WorldMatrix.TranslationVector;
            light.RadiusOuter = Radius;
            light.RadiusInner = 0;

            world.Game.RenderSystem.RenderWorld.LightSet.OmniLights.Add(light);
        }
예제 #4
0
        private void DisplayScene()
        {
            // Create the 3D AR scene, and display the point cloud
            mScene = new ARScene();
            mScene.DisplayPointCloud(true);

            // Create a TrackedPlanesController to visually display identified planes.
            var controller = new TrackedPlanesController(this, mViroView);

            // Spawn a 3D Droid on the position where the user has clicked on a tracked plane.
            controller.AddOnPlaneClickListener(new ClickListener2(this));

            mScene.SetListener(controller);

            // Add some lights to the scene; this will give the Android's some nice illumination.
            var rootNode       = mScene.RootNode;
            var lightPositions = new List <Vector>
            {
                new Vector(-10, 10, 1), new Vector(10, 10, 1)
            };

            const float intensity   = 300;
            var         lightColors = new List <Color> {
                Color.White, Color.White
            };

            for (var i = 0; i < lightPositions.Count; i++)
            {
                var light = new OmniLight
                {
                    Color    = lightColors[i],
                    Position = lightPositions[i],
                    AttenuationStartDistance = 20,
                    AttenuationEndDistance   = 30,
                    Intensity = intensity
                };
                rootNode.AddLight(light);
            }

            //Add an HDR environment map to give the Android's more interesting ambient lighting.
            var environment =
                Texture.LoadRadianceHDRTexture(Android.Net.Uri.Parse("file:///android_asset/ibl_newport_loft.hdr"));

            mScene.LightingEnvironment = environment;

            mViroView.Scene = mScene;
        }
예제 #5
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="instance"></param>
            /// <param name="position"></param>
            /// <param name="color"></param>
            /// <param name="radius"></param>
            /// <param name="fadeInRate"></param>
            /// <param name="fadeOutRate"></param>
            public LightStage(FXInstance instance, FXLightStage stageDesc, FXEvent fxEvent, bool looped) : base(instance)
            {
                light          = new OmniLight();
                this.stageDesc = stageDesc;

                light.Position = FXFactory.GetPosition(stageDesc.OffsetDirection, stageDesc.OffsetFactor, fxEvent);

                light.RadiusInner = stageDesc.InnerRadius;
                light.RadiusOuter = stageDesc.OuterRadius;
                light.Intensity   = stageDesc.Intensity;

                this.period = stageDesc.Period;
                this.looped = looped;

                instance.rw.LightSet.OmniLights.Add(light);

                UpdatePeriodIntensity();
                UpdateLightStyle();
            }
예제 #6
0
파일: MyGame.cs 프로젝트: tzsage/Balder
        public override void LoadContent()
        {
            var mesh = ContentManager.Load <Mesh>("teapot.ase");

            Scene.AddNode(mesh);

            var cylinder = ContentManager.CreateCylinder(10f, 20f, 8, 1);

            light               = new OmniLight();
            light.Range         = 2.0f;
            light.Position.X    = 0;
            light.Position.Y    = 0;
            light.Position.Z    = -30;
            light.ColorDiffuse  = Color.FromArgb(0xff, 0x7f, 0x7f, 0x1f);
            light.ColorSpecular = Color.FromArgb(0xff, 0x7f, 0x7f, 0x1f);
            light.ColorAmbient  = Color.FromArgb(0x1f, 0x1f, 0x1f, 0x1f);

            this.Scene.AddNode(light);
        }
예제 #7
0
        private Node initLightingNode()
        {
            Vector[] omniLightPositions = { new Vector(-3,  3, 0.3),
                                            new Vector(3,   3,   1),
                                            new Vector(-3, -3,   1),
                                            new Vector(3,  -3, 1) };

            Node lightingNode = new Node();

            foreach (Vector pos in omniLightPositions)
            {
                OmniLight light = new OmniLight
                {
                    Position  = pos,
                    Color     = Color.ParseColor("#FFFFFF"),
                    Intensity = 20,
                    AttenuationStartDistance = 6,
                    AttenuationEndDistance   = 9
                };

                lightingNode.AddLight(light);
            }

            // The spotlight will cast the shadows
            Spotlight spotLight = new Spotlight();

            spotLight.Position      = new Vector(0, 5, -0.5);
            spotLight.Color         = (Color.ParseColor("#FFFFFF"));
            spotLight.Direction     = (new Vector(0, -1, 0));
            spotLight.Intensity     = (50);
            spotLight.ShadowOpacity = (0.4f);
            spotLight.ShadowMapSize = (2048);
            spotLight.ShadowNearZ   = (2f);
            spotLight.ShadowFarZ    = (7f);
            spotLight.InnerAngle    = (5);
            spotLight.OuterAngle    = (20);
            spotLight.CastsShadow   = (true);

            lightingNode.AddLight(spotLight);

            // Add a lighting environment for realistic PBR rendering
            Texture environment = Texture.LoadRadianceHDRTexture(Uri.Parse("file:///android_asset/wakanda_360.hdr"));

            mScene.LightingEnvironment = (environment);

            // Add shadow planes: these are "invisible" surfaces on which virtual shadows will be cast,
            // simulating real-world shadows
            Material material = new Material();

            material.SetShadowMode(Material.ShadowMode.Transparent);

            Surface surface = new Surface(3, 3);

            surface.Materials = new List <Material>()
            {
                material
            };

            Node surfaceShadowNode = new Node();

            surfaceShadowNode.SetRotation(new Vector(Math.ToRadians(-90), 0, 0));
            surfaceShadowNode.Geometry = surface;
            surfaceShadowNode.SetPosition(new Vector(0, 0, 0.0));
            lightingNode.AddChildNode(surfaceShadowNode);

            lightingNode.SetRotation(new Vector(Math.ToRadians(-90), 0, 0));
            return(lightingNode);
        }
예제 #8
0
 public override void _Ready()
 {
     _material = GetMaterialOverride() as SpatialMaterial;
     _light    = GetNode <OmniLight>("OmniLight");
     _curTime  = IsGlowing ? 1 : 0;
 }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        internal void Parse()
        {
            var configDoc = new XmlDocument();

            configDoc.LoadXml(configXmlEditBox.Text);

            #region Log

            var logNode = configDoc.SelectSingleNode("/AthenaConfig/Log");
            if (logNode != null)
            {
                Log.Instance.MinLogLevel = logNode.Attributes["minLogLevel"] != null ? (LogLevel)Enum.Parse(typeof(LogLevel), logNode.Attributes["minLogLevel"].Value) : LogLevel.Anything;

                if (logNode.SelectSingleNode("Filename") != null && !string.IsNullOrEmpty(logNode.SelectSingleNode("Filename").InnerText))
                {
                    Log.Instance.Filename = logNode.SelectSingleNode("Filename").InnerText;
                }
            }

            #endregion

            #region Output

            var vsyncNode = configDoc.SelectSingleNode("/AthenaConfig/Output").Attributes["vSync"];
            if (vsyncNode != null)
            {
                VSync = (VSyncMode)Enum.Parse(typeof(VSyncMode), vsyncNode.Value);
            }

            var saveAfterRenderingNode = configDoc.SelectSingleNode("/AthenaConfig/Output").Attributes["saveAfterRendering"];
            if (saveAfterRenderingNode != null)
            {
                SaveOutputAfterRendering = bool.Parse(saveAfterRenderingNode.Value);
            }

            Fullscreen = false;
            var fullscreenNode = configDoc.SelectSingleNode("/AthenaConfig/Output").Attributes["fullscreen"];
            if (fullscreenNode != null)
            {
                Fullscreen = bool.Parse(fullscreenNode.Value);
            }

            OutputSize = new Vector2i(Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Output/Resolution").Attributes["width"].Value), Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Output/Resolution").Attributes["height"].Value));

            OutputImageFilename = null;
            var outputImageFilenameNode = configDoc.SelectSingleNode("/AthenaConfig/Output/Filename");
            if (outputImageFilenameNode != null)
            {
                OutputImageFilename = outputImageFilenameNode.Value;
            }

            #endregion

            #region Rendering

            NumberOfThreads = null;
            if (configDoc.SelectSingleNode("/AthenaConfig/Rendering").Attributes["threads"] != null)
            {
                NumberOfThreads = Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Rendering").Attributes["threads"].Value);
            }

            NumberOfJobs = new Vector2i(Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Rendering/JobCount").Attributes["width"].Value), Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Rendering/JobCount").Attributes["height"].Value));
            //JobSize = new Vector2i(Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Rendering/JobSize").Attributes["width"].Value), Int32.Parse(configDoc.SelectSingleNode("/AthenaConfig/Rendering/JobSize").Attributes["height"].Value));

            FramesToRender = null;
            var framesToRenderNode = configDoc.SelectSingleNode("/AthenaConfig/Rendering").Attributes["framesToRender"];
            if (framesToRenderNode != null)
            {
                FramesToRender = Int32.Parse(framesToRenderNode.Value);
            }

            if (FramesToRender == 0)
            {
                FramesToRender = null;
            }

            WaitForOutputRedraw = false;
            var waitForOutputRedrawNode = configDoc.SelectSingleNode("/AthenaConfig/Rendering").Attributes["waitForOutputRedraw"];
            if (waitForOutputRedrawNode != null)
            {
                WaitForOutputRedraw = bool.Parse(waitForOutputRedrawNode.Value);
            }

            RayTracer.BackgroundColor = null;

            var backgroundNode = configDoc.SelectSingleNode("/AthenaConfig/Output/Background");
            if (backgroundNode != null)
            {
                if (backgroundNode.Attributes["useRayDirectionVector"] != null && bool.Parse(backgroundNode.Attributes["useRayDirectionVector"].Value))
                {
                    RayTracer.BackgroundColor = null;
                }
                else if (backgroundNode.SelectSingleNode("Color") != null)
                {
                    RayTracer.BackgroundColor = ParseColorRGBNode(backgroundNode.SelectSingleNode("Color"));
                }
                else
                {
                    RayTracer.BackgroundColor = ColorRGB.Black;
                }
            }

            #region RayTracer

            RayTracer.MaxOctreeDepth = 8;

            var rayTracerNode = configDoc.SelectSingleNode("/AthenaConfig/Rendering/RayTracer");
            if (rayTracerNode != null)
            {
                if (rayTracerNode.Attributes["maxOctreeDepth"] != null)
                {
                    RayTracer.MaxOctreeDepth = Int32.Parse(rayTracerNode.Attributes["maxOctreeDepth"].Value);
                }
            }

            #endregion

            #endregion

            #region Scene

            Scene.Current = null;

            var sceneNode = configDoc.SelectSingleNode("/AthenaConfig/Scene");
            if (sceneNode == null)
            {
                throw new Exception("No scene found in configuration");
            }

            Scene.Current = new Scene(ParseName(sceneNode));

            var sceneMaxDepth           = 8;
            var sceneVoxelSizeThreshold = 1f;
            ParseVoxelOctreeNode(sceneNode.SelectSingleNode("VoxelOctree"), ref sceneMaxDepth, ref sceneVoxelSizeThreshold);

            VoxelOctree.GenerateOnMultipleThreads = false;
            var voxelOctreeNode = sceneNode.SelectSingleNode("VoxelOctree");
            if (voxelOctreeNode != null && voxelOctreeNode.Attributes["generateOnMultipleThreads"] != null)
            {
                VoxelOctree.GenerateOnMultipleThreads = bool.Parse(voxelOctreeNode.Attributes["generateOnMultipleThreads"].Value);
            }

            #region Camera

            var cameraNode = configDoc.SelectSingleNode("/AthenaConfig/Scene/Camera");
            if (cameraNode != null)
            {
                Scene.Current.Camera = new Camera(ParseVector3Node(cameraNode.SelectSingleNode("Position")), ParseVector3Node(cameraNode.SelectSingleNode("Target")));

                if (cameraNode.Attributes["fov"] != null)
                {
                    Scene.Current.Camera.FieldOfVision = float.Parse(cameraNode.Attributes["fov"].Value);
                }

                Scene.Current.Camera.MovementSpeed = cameraNode.SelectSingleNode("MovementSpeed") != null?ParseVector3Node(cameraNode.SelectSingleNode("MovementSpeed")) : new Athena.Core.DataTypes.Vector3(1);

                Scene.Current.Camera.RotationSpeed = cameraNode.SelectSingleNode("RotationSpeed") != null?ParseVector3Node(cameraNode.SelectSingleNode("RotationSpeed")) : new Athena.Core.DataTypes.Vector3(1);
            }

            #endregion

            #region Objects

            foreach (XmlNode objNode in sceneNode.SelectSingleNode("Objects").ChildNodes)
            {
                if (objNode is XmlComment)
                {
                    continue;
                }

                var position = ParseVector3Node(objNode.SelectSingleNode("Position"));
                var name     = ParseName(objNode);

                if (objNode.Name == "WavefrontObjMesh")
                {
                    #region Mesh

                    var mesh = new WavefrontObjMesh(objNode.SelectSingleNode("Filename").InnerText)
                    {
                        Position = position, Name = name
                    };

                    if (objNode.Attributes["voxelize"] == null || bool.Parse(objNode.Attributes["voxelize"].Value))
                    {
                        var maxDepth           = sceneMaxDepth;
                        var voxelSizeThreshold = sceneVoxelSizeThreshold;
                        ParseVoxelOctreeNode(objNode.SelectSingleNode("VoxelOctree"), ref maxDepth, ref voxelSizeThreshold);

                        mesh.GenerateOctree(maxDepth, voxelSizeThreshold);
                    }

                    #endregion

                    Scene.Current.AddObject(mesh);
                }

                if (objNode.Name == "Terrain")
                {
                    #region Terrain

                    var heightMap = null as float[];
                    if (objNode.Attributes["generationMethod"].Value == "MidPointDisplacement")
                    {
                        var midPointDisplacementNode = objNode.SelectSingleNode("MidPointDisplacement");
                        var heightMapSize            = int.Parse(midPointDisplacementNode.Attributes["size"].Value);
                        var roughness = float.Parse(midPointDisplacementNode.Attributes["roughness"].Value);

                        int?seed = null;
                        if (midPointDisplacementNode.Attributes["seed"] != null)
                        {
                            seed = int.Parse(midPointDisplacementNode.Attributes["seed"].Value);
                        }

                        heightMap = HeightMapGenerator.GenerateWithMidPointDisplacement(heightMapSize, roughness, seed);
                    }

                    var size      = float.Parse(objNode.Attributes["size"].Value);
                    var maxHeight = float.Parse(objNode.Attributes["maxHeight"].Value);

                    var terrain = new Terrain(size, maxHeight, heightMap)
                    {
                        Position = position, Name = name
                    };

                    if (objNode.Attributes["voxelize"] == null || bool.Parse(objNode.Attributes["voxelize"].Value))
                    {
                        var maxDepth           = sceneMaxDepth;
                        var voxelSizeThreshold = sceneVoxelSizeThreshold;
                        ParseVoxelOctreeNode(objNode.SelectSingleNode("VoxelOctree"), ref maxDepth, ref voxelSizeThreshold);

                        terrain.GenerateOctree(maxDepth, voxelSizeThreshold);
                    }

                    #endregion

                    Scene.Current.AddObject(terrain);
                }

                else if (objNode.Name == "Sphere")
                {
                    #region Sphere

                    var sphere = new Sphere()
                    {
                        Position = position, Name = name
                    };

                    sphere.Radius = float.Parse(objNode.Attributes["radius"].Value);

                    if (objNode.Attributes["voxelize"] == null || bool.Parse(objNode.Attributes["voxelize"].Value))
                    {
                        var maxDepth           = sceneMaxDepth;
                        var voxelSizeThreshold = sceneVoxelSizeThreshold;
                        ParseVoxelOctreeNode(objNode.SelectSingleNode("VoxelOctree"), ref maxDepth, ref voxelSizeThreshold);

                        sphere.Octree = VoxelOctree.Create(sphere, maxDepth, voxelSizeThreshold);
                    }

                    #endregion

                    Scene.Current.AddObject(sphere);
                }

                else if (objNode.Name == "OmniLight")
                {
                    #region OmniLight

                    var omniLight = new OmniLight(float.Parse(objNode.Attributes["radius"].Value))
                    {
                        Position = position, Name = name
                    };

                    omniLight.Color = ParseColorRGBNode(objNode.SelectSingleNode("Color"));

                    if (objNode.Attributes["intensity"] != null)
                    {
                        omniLight.Intensity = float.Parse(objNode.Attributes["intensity"].Value);
                    }

                    #endregion

                    Scene.Current.AddObject(omniLight);
                }
            }

            #endregion

            #endregion
        }
예제 #10
0
 public override void _Ready()
 {
     base._Ready();
     _ap = GetNode <AnimationPlayer>("AnimationPlayer");
     _ol = GetNode <OmniLight>("OmniLight");
 }