private void InitializeModels()
        {
            // create Main Model group - light and transforms for all sub model groups go here
            _MainGroup = new Model3DGroup();

            // Create default Transform collection
            // Add transform collection to the _MainGroup
            _GroupScaleTransform   = new ScaleTransform3D(new Vector3D(1, 1, 1));
            _GroupRotateTransformY = new RotateTransform3D(
                new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0),
                new Point3D(0, 0, 0));
            _GroupTranslateTransform = new TranslateTransform3D(new Vector3D(0, 1, 0));
            Transform3DCollection tcollection = new Transform3DCollection();

            tcollection.Add(_GroupScaleTransform);
            tcollection.Add(_GroupRotateTransformY);
            tcollection.Add(_GroupTranslateTransform);

            // setup group transform
            Transform3DGroup tGroupDefault = new Transform3DGroup();

            tGroupDefault.Children = tcollection;
            _MainGroup.Transform   = tGroupDefault;

            // Create sub model group [0] for the light
            //
            _ModelLights = new Model3DGroup();
            AmbientLight light1 = new AmbientLight(Colors.White);

            _ModelLights.Transform = tGroupDefault.Clone();
            _ModelLights.Children.Add(light1);
            _MainGroup.Children.Add(_ModelLights);
            _ModelItems = new Model3DGroup();
            _MainGroup.Children.Add(_ModelItems);
        }
Пример #2
0
        private void AddHouseWithTreesModel()
        {
            // Use assimp importer to load house with trees.3DS
            AssimpLoader.LoadAssimpNativeLibrary();

            var assimpWpfImporter   = new AssimpWpfImporter();
            var houseWithTreesModel = (Model3DGroup)assimpWpfImporter.ReadModel3D(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Resources\Models\house with trees.3DS"));

            // Add AmbientLight
            var ambientLight = new AmbientLight(Color.FromRgb(80, 80, 80));

            houseWithTreesModel.Children.Add(ambientLight);

            // Show the loaded 3d scene
            var modelVisual3D = houseWithTreesModel.CreateModelVisual3D();

            _masterDXViewportView.Viewport3D.Children.Add(modelVisual3D);

            // Save the man01 model for animation (when clicked on "Change scene" button)
            _animatedPersonModel = assimpWpfImporter.NamedObjects["man01"] as Model3DGroup;


            // Add base green plate and the house models to a CustomRenderingQueue.
            // This is done with setting value of CustomRenderingQueue (custom DXAttribute) on some parts of the 3D scene.
            // This will add the specified models to the custom rendering queue (created in the OnMasterDXSceneCreated method).
            var modelNames = new string[] { "Box01", "Box02", "roof01" };

            foreach (var modelName in modelNames)
            {
                var model3D = assimpWpfImporter.NamedObjects[modelName] as Model3D;

                // Note that CustomRenderingQueue can be set to an instance of RenderingQueue or to a name (as string) of the RenderingQueue
                model3D.SetDXAttribute(DXAttributeType.CustomRenderingQueue, "CustomRenderingQueue");
            }
        }
Пример #3
0
        private CompositionScopedBatch RemoveLighting()
        {
            CompositionScopedBatch returnBatch = null;

            if (this._compositor != null)
            {
                returnBatch = this._compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                var animation2 = this._compositor.CreateColorKeyFrameAnimation();
                animation2.Duration = TimeSpan.FromSeconds(2);
                animation2.InsertKeyFrame(1, Colors.White);
                this._ambientLight.StartAnimation("Color", animation2);

                var animation = this._compositor.CreateScalarKeyFrameAnimation();
                animation.Duration = TimeSpan.FromSeconds(2);
                animation.InsertKeyFrame(1, 40.0f);
                this._pointLight.StartAnimation("LinearAttenuation", animation);

                returnBatch.Completed += (o, e) =>
                {
                    if (this._pointLight != null)
                    {
                        this._pointLight.Dispose();
                        this._pointLight = null;
                    }

                    if (this._ambientLight != null)
                    {
                        this._ambientLight.Dispose();
                        this._ambientLight = null;
                    }
                };
            }

            return(returnBatch);
        }
Пример #4
0
        private void AddLighting()
        {
            this.ambientLight = this.compositor.CreateAmbientLight();
            //if (this.supportIntensety)
            //    this.ambientLight.Intensity = 0.2f;
            //this.ambientLight.Color = Colors.Black;//Colors.Gray;
            const int ambientLightIntensety = 25;

            this.ambientLight.Color = Color.FromArgb(255, ambientLightIntensety, ambientLightIntensety, ambientLightIntensety);//Colors.Gray;
            this.ambientLight.Targets.Add(this.backgroundVisual);

            this.pointLight1       = this.compositor.CreatePointLight();
            this.pointLight1.Color = splotlightColors[0, 0];
            //if (this.supportIntensety)
            //    this.pointLight1.Intensity = 0.5f;
            this.pointLight1.CoordinateSpace = this.containerVisual;
            this.pointLight1.Targets.Add(this.backgroundVisual);
            this.pointLight1.Offset = new Vector3((float)this.rootElement.ActualWidth, (float)this.rootElement.ActualHeight * 0.25f,
                                                  PointLightDistance);

            this.pointLight2       = this.compositor.CreatePointLight();
            this.pointLight2.Color = splotlightColors[0, 1];
            //if (this.supportIntensety)
            //    this.pointLight2.Intensity = 0.5f;
            this.pointLight2.CoordinateSpace = this.containerVisual;
            this.pointLight2.Targets.Add(this.backgroundVisual);
            this.pointLight2.Offset = new Vector3(0, (float)this.rootElement.ActualHeight * 0.75f, PointLightDistance);

            this.pointLight1.Offset = new Vector3(0, (float)this.rootElement.ActualHeight * 0.25f, PointLightDistance);
            this.pointLight2.Offset = new Vector3((float)this.rootElement.ActualWidth, (float)this.rootElement.ActualHeight * 0.75f,
                                                  PointLightDistance);
        }
Пример #5
0
        /// <summary>
        /// Loads the content.
        /// </summary>
        protected override void LoadContent()
        {
            // Load content for the game or screen
            this.webUIComponent = new WebUIScreenDrawableComponent(this.GameWorld, 1280, 720, Vector2.Zero);
            this.webUIComponent.RegisterEventCallback("game:spawnLight", this.SpawnLight);

            this.backgroundSprite = new TiledSprite(this.GameWorld, "Content/stone", null, Vector2.Zero, new Vector2(this.GraphicsDeviceManager.PreferredBackBufferWidth, this.GraphicsDeviceManager.PreferredBackBufferHeight) * this.GameWorld.WorldPerPixelRatio)
            {
                LayerDepth    = 1,
                RenderOptions = SpriteRenderOptions.IsLit
            };

            var newLight = new BouncyPointLight(this.GameWorld)
            {
                Position         = new Vector3(Vector2.Zero, 0.15f),
                Velocity         = this.GetRandomVelocity(),
                Color            = this.GetRandomColor(),
                Power            = 0.25f,
                Range            = this.prng.Next(300, 500) / 100.0f,
                SpecularStrength = 2.75f,
                CastsShadows     = true,
                LayerDepth       = 2
            };

            var amLight = new AmbientLight(Color.White, 0.2f, true, 1);

            this.RenderSystem.AddPostProcessEffect(newLight);
            this.RenderSystem.AddPostProcessEffect(amLight);

            this.GameCamera.Position = new Vector2(this.GraphicsDeviceManager.PreferredBackBufferWidth, this.GraphicsDeviceManager.PreferredBackBufferHeight) * this.GameWorld.WorldPerPixelRatio * 0.5f;

            base.LoadContent();
        }
Пример #6
0
        private void InitializeLight()
        {
            _hoverLight = new PointLight(Colors.White, new Point3D(0, 0, 0));
            UtilityWPF.SetAttenuation(_hoverLight, _camera.Position.ToVector().Length * 2d, .95d);

            _selectedLight = new AmbientLight(UtilityWPF.ColorFromHex("808080"));
        }
        private void LoadModel(string fileName)
        {
            MainViewport.Children.Clear();

            // Create an instance of AssimpWpfImporter
            var assimpWpfImporter = new AssimpWpfImporter();
            var readModel3D       = assimpWpfImporter.ReadModel3D(fileName, texturesPath: null); // we can also define a textures path if the textures are located in some other directory (this is parameter can be skipped, but is defined here so you will know that you can use it)


            if (readModel3D == null)
            {
                MessageBox.Show("Cannot read file");
                return;
            }

            MainViewport.Children.Add(readModel3D.CreateModelVisual3D());


            if (_fileName != fileName) // Reset camera only when the file is loaded for the first time
            {
                _fileName = fileName;

                Camera1.TargetPosition = readModel3D.Bounds.GetCenterPosition();
                Camera1.Distance       = readModel3D.Bounds.GetDiagonalLength() * 1.2;
            }

            // Add ambient light
            var ambientLight = new AmbientLight(Color.FromRgb(100, 100, 100));

            MainViewport.Children.Add(ambientLight.CreateModelVisual3D());
        }
Пример #8
0
        private void btnOpenSandbox_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog();

            if ((bool)ofd.ShowDialog())
            {
                var h3 = new Halo3(ofd.FileName);
                lblSandboxPath.Text = ofd.FileName;

                var container = new Model3DCollection();
                foreach (var placedObject in h3.SandboxObjects.Where(placedObject => placedObject.TagIndex != -1))
                {
                    // Try to load Model
                    if (placedObject.TagEntry.Tag.TagPath.Contains("spawning"))
                    {
                    }

                    string gameAssetPath;
                    try
                    {
                        gameAssetPath = VariousFunctions.GetGameAsset(Halo3.GameId, placedObject.TagEntry.Tag.TagPath);
                    }
                    catch (FileNotFoundException)
                    {
                        ActionLog.AddEntry("Missing Game Asset");
                        continue;
                    }

                    var model = (Model3D)ModelImporter.Load(gameAssetPath);
                    model.Transform = CreateTransformGroup(placedObject);
                    container.Add(model);
                }

                ModelViewport.Children.Clear();
                ModelViewport.Children.Add(new GridLines());
                foreach (var model in container)
                {
                    ModelViewport.Children.Add(new ModelVisual3D
                    {
                        Content = model
                    });
                }
                var light        = new LightVisual3D();
                var ambientLight = new AmbientLight(Colors.WhiteSmoke)
                {
                    Transform = new MatrixTransform3D(new Matrix3D
                    {
                        OffsetX = 0,
                        OffsetY = 0,
                        OffsetZ = 100
                    })
                };
                light.Content = ambientLight;
                ModelViewport.Children.Add(light);

                ModelViewport.ShowCameraInfo = true;
                ModelViewport.ZoomExtents();
                ModelViewport.IsHeadLightEnabled = true;
            }
        }
Пример #9
0
        public LightSphere()
        {
            this.InitializeComponent();

            _sphereList = new List <SpriteVisual>(16);
            _brushList  = new List <CompositionEffectBrush>(16);

            // Get the current compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            // Setup the basic scene
            _rootContainer       = _compositor.CreateContainerVisual();
            _sceneContainer      = _compositor.CreateContainerVisual();
            _worldSpaceContainer = _compositor.CreateContainerVisual();

            _rootContainer.Children.InsertAtTop(_worldSpaceContainer);
            _worldSpaceContainer.Children.InsertAtTop(_sceneContainer);

            // Create the ambient light for the scene
            _ambientLight       = _compositor.CreateAmbientLight();
            _ambientLight.Color = Color.FromArgb(255, 255, 255, 255);
            _ambientLight.Targets.Add(_sceneContainer);

            ElementCompositionPreview.SetElementChildVisual(EnvironmentPanel, _rootContainer);
        }
Пример #10
0
        /// <summary>
        /// Sets up the lighting
        /// </summary>
        public static void setupLighting(Model3DGroup my3DGroup)
        {
            AmbientLight myAmbLight = new AmbientLight();

            myAmbLight.Color = Colors.White;
            my3DGroup.Children.Add(myAmbLight);
        }
Пример #11
0
 public Scene(string name = "default")
 {
     Root         = new Frame("_root_");
     Name         = name;
     AmbientLight = new AmbientLight();
     Id           = Guid.NewGuid();
 }
Пример #12
0
        private void ConfigureLighting(FrameworkElement element)
        {
            if (this._compositor != null)
            {
                // get interop visual for element
                var text = element.GetVisual();

                this._ambientLight       = this._compositor.CreateAmbientLight();
                this._ambientLight.Color = Colors.White;
                this._ambientLight.Targets.Add(text);

                this._pointLight                 = this._compositor.CreatePointLight();
                this._pointLight.Color           = Colors.White;
                this._pointLight.CoordinateSpace = text;
                this._pointLight.Targets.Add(text);

                // starts out to the left; vertically centered; light's z-offset is related to fontsize
                this._pointLight.Offset = new Vector3(0, (float)element.ActualHeight / 2, 480);

                // simple offset.X animation that runs forever
                var animation = this._compositor.CreateScalarKeyFrameAnimation();
                animation.InsertKeyFrame(1, (float)element.ActualWidth);
                animation.Duration          = TimeSpan.FromMilliseconds(800);
                animation.IterationBehavior = AnimationIterationBehavior.Forever;
                animation.Direction         = AnimationDirection.Alternate;

                var animation2 = this._compositor.CreateColorKeyFrameAnimation();
                animation2.Duration = TimeSpan.FromSeconds(2);
                animation2.InsertKeyFrame(1, Color.FromArgb(0xFF, 0x50, 0x50, 0x50));
                this._ambientLight.StartAnimation(nameof(AmbientLight.Color), animation2);

                this._pointLight.StartAnimation("Offset.X", animation);
            }
        }
Пример #13
0
        private void DrawScene()
        {
            Viewport3D        Viewport = new Viewport3D();        //Viewport3D class provides a rendering surface for 3-D visual content
            PerspectiveCamera Camera   = new PerspectiveCamera(); //PerspectiveCamera class object represents a perspective projection camera
            DirectionalLight  myDLight = new DirectionalLight();  //DirectionalLight class object provides effect along a direction
            AmbientLight      AmLight  = new AmbientLight();      //AmbientLight class objects provides Lights every surface uniformly a bright AmbientLight creates  because of lack of shading, but a low-intensity AmbientLight approximatesthe effect of light that has been scattered by reflecting between diffuse surfaces in the scene.

            Camera.Position      = new Point3D(-5, 2, 3);         //setting the camera position in world coordinates
            Camera.LookDirection = new Vector3D(5, -2, -3);       //defininig the direction in which the camera looking in world coordinates
            AmLight.Color        = Colors.White;                  //setting the color of light

            Vector3D          vecD        = new Vector3D(-50, -90, 0);
            Rotation3D        RD          = new AxisAngleRotation3D(vecD, 1);
            RotateTransform3D RotateTrans = new RotateTransform3D(RD);//RotateTransform3D class specify rotation transformation that is parameterized

            //Define an animation for the rotation

            DoubleAnimation myAnimation = new DoubleAnimation();

            myAnimation.From           = 1;
            myAnimation.To             = 361;
            myAnimation.Duration       = new Duration(TimeSpan.FromMilliseconds(3000));//Defining time in second for cube that will be rotate
            myAnimation.RepeatBehavior = RepeatBehavior.Forever;

            RotateTrans.Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, myAnimation);

            //Add transformation to the model
            Transform3DGroup Transgroup = new Transform3DGroup(); //Transform3DGroup class contains a collection of Transform3Ds.
            Model3DGroup     Modelgroup = new Model3DGroup();     //The Model3DGroup class is itself a Model3D and is often used to group multiple GeometryModel3Ds

            Transgroup.Children.Add(RotateTrans);

            Modelgroup.Transform = Transgroup;

            Modelgroup.Children.Add(AmLight);
            Viewport.Camera = Camera;

            ModelVisual3D ModelVisualD = new ModelVisual3D();//ModelVisual3D class contains 3-D models

            ModelVisualD.Content = Modelgroup;

            Viewport.Children.Add(ModelVisualD);

            var mb = new ModelBuilder();

            var cubes = new List <Model3DGroup>();

            cubes.Add(mb.MakeCube(0.5, 0.5, 0.1, 0));
            cubes.Add(mb.MakeCube(0.5, 0.5, 0.1, 1.5));
            cubes.Add(mb.MakeCube(0.5, 1.5, 0.1, 1.5));


            foreach (var c in cubes)
            {
                Modelgroup.Children.Add(c);
            }

            this.Content = Viewport;
        }
Пример #14
0
        // OnLoad() is called when the GameObject is added to the IGameObjectService.
        protected override void OnLoad()
        {
            var ambientLight = new AmbientLight
            {
                //Color = new Vector3F(0.05333332f, 0.09882354f, 0.1819608f),  // XNA BasicEffect Values
                Color     = new Vector3F(0.5f),                        // Make ambient light brighter.
                Intensity = 1,
                HemisphericAttenuation = 1,
            };

            _ambientLightNode = new LightNode(ambientLight);

            var keyLight = new DirectionalLight
            {
                Color             = new Vector3F(1, 0.9607844f, 0.8078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };

            _keyLightNode = new LightNode(keyLight)
            {
                Name      = "KeyLight",
                Priority  = 10, // This is the most important light.
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(-0.5265408f, -0.5735765f, -0.6275069f))),
            };

            var fillLight = new DirectionalLight
            {
                Color             = new Vector3F(0.9647059f, 0.7607844f, 0.4078432f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 0,
            };

            _fillLightNode = new LightNode(fillLight)
            {
                Name      = "FillLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.7198464f, 0.3420201f, 0.6040227f))),
            };

            var backLight = new DirectionalLight
            {
                Color             = new Vector3F(0.3231373f, 0.3607844f, 0.3937255f),
                DiffuseIntensity  = 1,
                SpecularIntensity = 1,
            };

            _backLightNode = new LightNode(backLight)
            {
                Name      = "BackLight",
                PoseWorld = new Pose(QuaternionF.CreateRotation(Vector3F.Forward, new Vector3F(0.4545195f, -0.7660444f, 0.4545195f))),
            };

            var scene = _services.GetInstance <IScene>();

            scene.Children.Add(_ambientLightNode);
            scene.Children.Add(_keyLightNode);
            scene.Children.Add(_fillLightNode);
            scene.Children.Add(_backLightNode);
        }
Пример #15
0
        /// <summary>
        /// Adds ambientlight and directionallight to the scene
        /// </summary>
        protected void AddDefaultLight()
        {
            var dir = new DirectionalLight(Color.FromRgb(255, 255, 255), new Vector3D(1, -5, 1));
            var amb = new AmbientLight(Color.FromRgb(170, 170, 170));

            _collection.Add(dir);
            _collection.Add(amb);
        }
Пример #16
0
        private void CreateLight()
        {
            AmbientLight  light = new AmbientLight(Colors.White);
            ModelVisual3D model = new ModelVisual3D();

            model.Content = light;
            view3d.Children.Add(model);
        }
Пример #17
0
        // Define the lights.
        private void DefineLights()
        {
            var ambientLight     = new AmbientLight(Colors.Gray);
            var directionalLight = new DirectionalLight(Colors.Gray, new Vector3D(-1.0, -3.0, -2.0));

            MainModel3Dgroup.Children.Add(ambientLight);
            MainModel3Dgroup.Children.Add(directionalLight);
        }
Пример #18
0
 public void Init()
 {
     hitInfo           = new HitInfo();
     hitInfo.hasHit    = true;
     hitInfo.hitObject = new Sphere(new Point3D(-50, 0, 60), 30, new Metal(new ColorRGB(1, 0, 0)));
     testPhong         = new Phong();
     ambLight          = new AmbientLight(new ColorRGB(0, 1, 0));
 }
        // Define the lights.
        public void DefineLights()
        {
            AmbientLight     ambient_light     = new AmbientLight(Colors.Gray);
            DirectionalLight directional_light =
                new DirectionalLight(Colors.Gray, new Vector3D(-1.0, -3.0, -2.0));

            MainModel3Dgroup.Children.Add(ambient_light);
            MainModel3Dgroup.Children.Add(directional_light);
        }
Пример #20
0
        private void FestlegungBeleuchtung()
        {
            var ambientLight     = new AmbientLight(Colors.Gray);
            var directionalLight =
                new DirectionalLight(Colors.Gray, new Vector3D(-1.0, -3.0, -2.0));

            model3DGroup.Children.Add(ambientLight);
            model3DGroup.Children.Add(directionalLight);
        }
Пример #21
0
        public void Execute(ref WooState state)
        {
            Vector3 colourVec = _ColourExpr.EvaluateVector(ref state);
            Colour  colour    = new Colour(colourVec.x, colourVec.y, colourVec.z);

            AmbientLight ambientLight = new AmbientLight(colour);

            ambientLight.CreateElement(state._Parent, new Vector3(0, 0, 0));
        }
Пример #22
0
        private void DefineLights(Model3DGroup model_group)
        {
            AmbientLight     ambient_light     = new AmbientLight(Colors.Gray);
            DirectionalLight directional_light =
                new DirectionalLight(Colors.Gray, new Vector3D(-1.0, -3.0, -2.0));

            model_group.Children.Add(ambient_light);
            model_group.Children.Add(directional_light);
        }
Пример #23
0
 /// <summary>
 /// Invalidates the lights.
 /// </summary>
 public void InvalidateLights()
 {
     if (DefaultLighting && (AmbientLight == null))
     {
         AmbientLight = new AmbientLight();
     }
     if (AmbientLight != null)
     {
         _ambientLightVector = new Vector4(0.0f, 0.0f, 0.0f, AmbientLight.Intensity); // X (unused), Y (unused), Z (unused), W (intensity)
     }
     if (DefaultLighting && (DirectionalLight1 == null))
     {
         DirectionalLight1           = new DirectionalLight();
         DirectionalLight1.Direction = new Vector3(0.0f, -0.25f, 1.0f);
     }
     if (DirectionalLight1 != null)
     {
         Vector3 v = DirectionalLight1.Direction;
         v.Normalize();
         _directionalLightVector1 = new Vector4(v, DirectionalLight1.Intensity);
     }
     if (DefaultLighting && (DirectionalLight2 == null))
     {
         DirectionalLight2           = new DirectionalLight();
         DirectionalLight2.Direction = new Vector3(-0.75f, -0.5f, -1.0f);
     }
     if (DirectionalLight2 != null)
     {
         Vector3 v = DirectionalLight2.Direction;
         v.Normalize();
         _directionalLightVector2 = new Vector4(v, DirectionalLight2.Intensity);
     }
     if (DefaultLighting && (DirectionalLight3 == null))
     {
         DirectionalLight3           = new DirectionalLight();
         DirectionalLight3.Direction = new Vector3(1.0f, 0.0f, -1.0f);
         DirectionalLight3.Intensity = 0.5f;
     }
     if (DirectionalLight3 != null)
     {
         Vector3 v = DirectionalLight3.Direction;
         v.Normalize();
         _directionalLightVector3 = new Vector4(v, DirectionalLight3.Intensity);
     }
     if (DefaultLighting && (DirectionalLight4 == null))
     {
         DirectionalLight4           = new DirectionalLight();
         DirectionalLight4.Direction = new Vector3(0.0f, 1.0f, 0.0f);
         DirectionalLight4.Intensity = 0.5f;
     }
     if (DirectionalLight4 != null)
     {
         Vector3 v = DirectionalLight4.Direction;
         v.Normalize();
         _directionalLightVector4 = new Vector4(v, DirectionalLight4.Intensity);
     }
 }
Пример #24
0
        /// <summary>
        /// Imports a light referenced by a light instance.
        /// Inputs are assumed to be supported (CanImport must return true for them).
        /// </summary>
        /// <param name="xmlInstanceLight">instance_light XML node</param>
        /// <returns>The imported light</returns>
        Light ImportLight(XmlNode xmlInstanceLight)
        {
            string  lightId      = xmlInstanceLight.Attributes["url"].Value.Substring(1);
            XmlNode xmlRoot      = xmlInstanceLight.OwnerDocument.DocumentElement;
            XmlNode xmlTechnique = xmlRoot.SelectSingleNode(".//light[@id='" + lightId + "']/technique_common");
            XmlNode xmlNode      = xmlTechnique.SelectSingleNode("directional|ambient|point|spot");

            Light light;
            int   countDirectional = 0;

            switch (xmlNode.Name)
            {
            case "directional":
                DirectionalLight dirLight = new DirectionalLight();
                dirLight.Name = "DirLight" + (++countDirectional);

                // Color
                XmlNode xmlColor = xmlNode.SelectSingleNode("color");
                Vector3 values   = XmlUtil.ParseVector3(xmlColor.InnerText);
                dirLight.Color = new Color(values);

                // Direction
                Matrix  transform = XmlUtil.CreateNodeTransform(xmlInstanceLight);
                Vector3 dir       = Vector3.Transform(new Vector3(0, 0, -1), transform);
                dirLight.Direction = dir;

                light = dirLight;

                break;

            case "ambient":
                AmbientLight ambientLight = new AmbientLight();
                ambientLight.Name = "AmbientLight";

                // Color
                xmlColor           = xmlNode.SelectSingleNode("color");
                values             = XmlUtil.ParseVector3(xmlColor.InnerText);
                ambientLight.Color = new Color(values);

                light = ambientLight;

                break;

            default:
                throw new NotSupportedException("Lights of type '" +
                                                xmlNode.Name + "' are not supported");
            }

            // Name: Bad Idea (if unique names are used a new shader has to be generated
            // for each name variant)
            //XmlNode xmlName = xmlRoot.SelectSingleNode(".//light[@id='" + lightId +
            //    "']/@name");
            //if (xmlName != null) light.Name = xmlName.Value;

            return(light);
        }
Пример #25
0
        /// <summary>
        /// 初始化光源
        /// </summary>
        private void DefineLights()
        {
            //光适用 light 于对象统一,而不考虑其形状的对象。
            AmbientLight ambient_light = new AmbientLight(Colors.Gray);
            //沿 Vector3D 指定的方向投射其效果的光对象。
            DirectionalLight directional_light = new DirectionalLight(Colors.Gray, new Vector3D(-1.0, -3.0, -2.0));

            MainModel3Dgroup.Children.Add(ambient_light);
            MainModel3Dgroup.Children.Add(directional_light);
        }
        /// <summary>
        /// Creates the configuration controls of this asset.
        /// </summary>
        public static void AddControls(AmbientLight asset, Window owner, ComboBox comboBoxResource)
        {
            GroupBox groupGeneral = CommonControls.Group("General", owner);
            var intensity = CommonControls.SliderNumericFloat("Intensity", groupGeneral, asset.Intensity, true, true, 0, 10,
                                                         asset, "Intensity");
            var color = CommonControls.SliderColor("Color", groupGeneral, asset.Color, asset, "Color");
            var ambientOcclusion = CommonControls.AssetSelector<AmbientOcclusion>("Ambient Occlusion", owner, asset, "AmbientOcclusion");
            groupGeneral.AdjustHeightFromChildren();

        } // AddControls       
Пример #27
0
 public SensorManager(Grid grid)
 {
     _accelerometer = new Accelerometer();
     _gyrometer     = new Gyrometer();
     _inclinometer  = new Inclinometer();
     _light         = new AmbientLight();
     _compass       = new Compass();
     _updaters      = new List <Action>();
     _grid          = grid;
 }
Пример #28
0
        private static Model3DGroup GetUnitLitText(string text)
        {
            GeometryModel3D textModel  = GetUnitText(text);
            var             lightModel = new AmbientLight(Colors.White);

            return(new Model3DGroup
            {
                Children = new Model3DCollection(new Model3D[] { textModel, lightModel })
            });
        }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        public void Initialise(ILayer baseLayer)
        {
            #region Construct View Port , Add Transforms, Scale

            Viewport3D viewport = ViewPort;
            _transform = new Transform3DGroup();
            _transform.Children.Add(_scale);
            _rotationTranform = new RotateTransform3D(_rotation);
            _transform.Children.Add(_rotationTranform);

            AmbientLight _ambLight = new AmbientLight(System.Windows.Media.Brushes.White.Color);
            var          visuald   = new ModelVisual3D();
            Model3DGroup M3dG      = new Model3DGroup();
            M3dG.Children.Add(_ambLight);
            visuald.Content = M3dG;
            viewport.Children.Add(visuald);

            #endregion

            BaseLayer     = baseLayer;
            this.RootTile = new GlobeTile(0, 0, 0, visuald);

            var root = this.RootTile;
            this.RootTile.zoomIn();

            //Map Viewport as Event Source to Map Event Handlers.
            EventSource = viewport;

            //Add All Necessary Transforms to view port Camera.
            viewport.Camera.Transform = _transform;

            #region Populate Initial Layer [Based on MS Bing Map]


            var initialKey = "032010110132012031";//initial key
            for (var i = 0; i < initialKey.Length; i++)
            {
                root.Children[int.Parse(initialKey.Substring(i, 1))].zoomIn();
            }


            #endregion

            #region Map Events to Handelers

            viewport.MouseDown   += viewport_MouseDown;
            viewport.MouseUp     += viewport_MouseUp;
            viewport.MouseMove   += viewport_MouseMove;
            viewport.MouseWheel  += viewport_MouseWheel;
            viewport.SizeChanged += viewport_SizeChanged;

            #endregion

            RedrawSphere();
        }
Пример #30
0
    public void Draw(AD2SpriteBatch sb)
    {
        Renderer.GraphicsDevice.Clear(Color.White);

        //figure out camera stuff
        int cameraX = 0;
        int cameraY = 0;

        foreach (PC p in allPlayers())
        {
            cameraX += p.X - (CastleSpire.BaseWidth / 2);
            cameraY += p.Y - (CastleSpire.BaseHeight / 2);
        }

        cameraX /= allPlayers().Count;
        cameraY /= allPlayers().Count;

        //no soul lighitng
        // l.center_x = p.x + player.size/2;
        //l.center_y = player.y + player.size/2;

        DrawWorldNoLighting(sb, cameraX, cameraY);
        Lightmap.RenderLightMap(sb, AmbientLight.AmbientColor(Clock), cameraX, cameraY, CastleSpire.BaseWidth, CastleSpire.BaseHeight);


        /*** LIGHTING STUFF
         * /**
         * //Before dawn, draw a lightsource at the player spot. That way he/she can see a little bit.
         * if (clock.hours() < AmbientLight.hourDawn || clock.hours() >= AmbientLight.hourDusk)
         * {
         *    soul = new Light(soulcol, player.x + (player.size / 2), player.y + (player.size / 2), 7, 40);
         *    lights.AddFirst(soul);
         * }
         * if (clock.hours() == AmbientLight.hourDawn && (clock.minutes() < 20))
         * {
         *    soul = new Light(Utils.mix(20 * 60,(60 * clock.minutes()) + clock.seconds(),soulcol, AmbientLight.ambientColor(clock)), player.x + (player.size / 2), player.y + (player.size / 2), 7,40);
         *    lights.AddFirst(soul);
         * }
         * if (clock.hours() == AmbientLight.hourSunset && (clock.minutes() > 40))
         * {
         *   soul = new Light(Utils.mix(20 * 60, (60 * (clock.minutes() - 40 ) ) + clock.seconds(), AmbientLight.ambientColor(clock), soulcol) , player.x + (player.size / 2), player.y + (player.size / 2), 7, 40);
         *   lights.AddFirst(soul);
         * }
         * //Nancies();
         */
        for (int i = 0; i != 4; i++)
        {
            if (HUDs[i] != null)
            {
                HUDs[i].Draw(sb);
            }
        }

        ClockHUD.Draw(sb, Clock);
    }
 public void Execute()
 {
     if (light == null)
     {
         light = new AmbientLight(app, parent, color);
     }
     parent.Add(light);
     for (int i = app.SelectedObject.Count - 1; i >= 0; i--)
     {
         app.SelectedObject[i].Node.UnSelect();
     }
     if (light.Node != null)
     {
         light.Node.Select();
     }
 }
        public ThumbnailLighting()
        {
            Model = new LocalDataSource();
            this.InitializeComponent();

            // Get the current compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;


            //
            // Create the lights
            //

            _ambientLight = _compositor.CreateAmbientLight();
            _pointLight = _compositor.CreatePointLight();
            _distantLight = _compositor.CreateDistantLight();
            _spotLight = _compositor.CreateSpotLight();
        }
Пример #33
0
        /// <summary>
        /// Logic running into controller
        /// </summary>
        public void Run()
        {
            StringBuilder dataLogging = new StringBuilder();
            #if EMULATOR
            Random rand = new Random();
            #endif

            while (true)
            {
            #if !EMULATOR
                // get humidity/temp
                this.temperature = System.Math.Round(this.sht1x.ReadTemperature(SHT1X.TempUnit.Celsius));
                this.humidity = System.Math.Round(this.sht1x.ReadRelativeHumidity());
                // get LDR data
                this.ldrResistance = this.ldr.GetStatus().Resistance;
                this.ambientLight = AmbientLightConverter.FromResistance(this.ldrResistance);
                // get anenometer data
                this.windSpeed = System.Math.Round(this.anemometer.WindSpeed);
            #else
                // get humidity/temp
                this.temperature = rand.Next(30);
                this.humidity = rand.Next(100);
                // get LDR data
                this.ldrResistance = rand.Next(50);
                this.ambientLight = AmbientLightConverter.FromResistance(this.ldrResistance);
                // get anenometer data
                this.windSpeed = rand.Next(100);
            #endif

                if (this.config.IsDataLogEnabled)
                {
                    if (!this.dataLogger.IsOpen)
                        this.dataLogger.Open();

                    dataLogging.Append(this.rtc.GetDateTime().ToString("HH:mm:ss"));
                    dataLogging.Append(",");
                    dataLogging.Append(humidity);
                    dataLogging.Append(",");
                    dataLogging.Append(temperature);
                    dataLogging.Append(",");
                    dataLogging.Append(ldrResistance);
                    dataLogging.Append(",");
                    dataLogging.Append(windSpeed);

                    this.dataLogger.Log(dataLogging.ToString());
                    dataLogging.Clear();
                }

                Thread.Sleep(CONTROLLER_DELAY);
            }
        }
Пример #34
0
 internal void addLight(AmbientLight ambient)
 {
     throw new NotImplementedException();
 }
Пример #35
0
        public void Execute(ref WooState state)
        {
            Vector3 colourVec = _ColourExpr.EvaluateVector(ref state);
            Colour colour = new Colour(colourVec.x, colourVec.y, colourVec.z);

            AmbientLight ambientLight = new AmbientLight(colour);
            ambientLight.CreateElement(state._Parent, new Vector3(0,0,0));
        }
Пример #36
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here

            // Add objects and lights to the ObjectManager and LightManager
            // respectively. The ObjectManager accepts objects in several forms:
            //
            //   -As SceneObjects, which can be dynamic (movable) or static and are
            //    created from XNA Models or custom vertex / index buffer.
            //
            //   -As XNA Models, which can only be static.
            //

            voxelManager.AddVoxelType("Models/cobblestone", 10000);
            voxelManager.FinishInit(Content, GraphicsDevice, sceneInterface);

            //Window.Title = Window.Title + " - Instanced Object Count: " + (instancesPerContainerObject * containerObjects.Length);

            // LightRigs contain many lights and light groups.
            LightRig rig = new LightRig();

            // Ambient lights uniformly illuminate the scene.
            AmbientLight ambientlight = new AmbientLight();
            ambientlight.Enabled = true;
            ambientlight.DiffuseColor = new Vector3(0.8f, 0.98f, 0.99f);
            ambientlight.Intensity = 0.5f;

            // Directional lights illuminate the scene from a specific direction, similar to sunlight.
            DirectionalLight sunlight = new DirectionalLight();
            sunlight.Enabled = true;
            sunlight.DiffuseColor = new Vector3(1.0f, 0.97f, 0.77f);
            sunlight.Intensity = 2.6f;
            sunlight.Direction = new Vector3(-0.60f, -0.73f, -0.32f);
            sunlight.ShadowType = ShadowType.AllObjects;
            sunlight.ShadowQuality = 1.0f;
            sunlight.ShadowPrimaryBias = 1.0f;
            sunlight.ShadowSecondaryBias = 0.04f;

            DirectionalLight sunlightB = new DirectionalLight();
            sunlightB.Enabled = true;
            sunlightB.DiffuseColor = new Vector3(0.0f, 0.97f, 0.77f);
            sunlightB.Intensity = 2.6f;
            sunlightB.Direction = new Vector3(0.60f, -0.73f, -0.32f);
            sunlightB.ShadowType = ShadowType.AllObjects;
            sunlightB.ShadowQuality = 1.0f;
            sunlightB.ShadowPrimaryBias = 1.0f;
            sunlightB.ShadowSecondaryBias = 0.04f;

            // Add the lights to a group.
            LightGroup group = new LightGroup();
            group.Add(ambientlight);
            group.Add(sunlight);
            group.Add(sunlightB);

            // Add the group to the light rig and commit the changes.
            rig.LightGroups.Add(group);
            rig.CommitChanges();

            // Submit the light rig to the light manager.
            sceneInterface.LightManager.Submit(rig);

            // Setup the scene settings.
            environment = new SceneEnvironment();
            environment.VisibleDistance = 250;
            environment.FogEnabled = true;
            environment.FogColor = new Vector3(0.5f, 0.5f, 0.5f);
            environment.FogStartDistance = 200;
            environment.FogEndDistance = 250;
            environment.ShadowFadeStartDistance = 200;
            environment.ShadowFadeEndDistance = 250;
            environment.ShadowCasterDistance = 250;

            // Apply the user preferences (example - not required).
            sceneInterface.ApplyPreferences(preferences);
        }
Пример #37
0
        protected void FromXml(XmlReader r)
        {
            // first parse the attributes
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                    case "Name":
                        this.name = r.Value;
                        break;
                    case "Priority":
                        this.priority = int.Parse(r.Value);
                        break;
                }
            }
            r.MoveToElement(); //Moves the reader back to the element node.

            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }
                if (r.NodeType == XmlNodeType.Element)
                {
                    switch (r.Name)
                    {
                        case "PointCollection":
                            if (!r.IsEmptyElement)
                            {
                                this.points = new PointCollection(this, app, true, app.Config.DisplayRegionPoints, this.app.Config.RegionPointMeshName, this.app.Config.RegionPointMaterial,MPPointType.Boundary, r);
                                Add(points);
                                points.PointsChanged += new PointsChangedEventHandler(PointsChangedHandler);
                            }
                            break;
                        case "NameValuePairs":
                            this.nameValuePairs = new NameValueObject(r);
                            break;
                        case "Forest":
                            Forest forest = new Forest(r, this, app);
                            Add(forest);
                            break;
                        case "Fog":
                            Fog fog = new Fog(r, this, app);
                            Add(fog);
                            break;
                        case "Water":
                            Water water = new Water(r, this, app);
                            Add(water);
                            break;
                        case "Sound":
                            Sound sound = new Sound(r, (IWorldContainer)this, app);
                            Add(sound);
                            break;
                        case "Grass":
                            Grass grass = new Grass(r, this, app);
                            Add(grass);
                            break;
                        case "SpawnGen":
                            SpawnGen mob = new SpawnGen(r, app, this);
                            Add(mob);
                            break;
                        case "AmbientLight":
                            AmbientLight ambientLight = new AmbientLight(app, this, r);
                            Add(ambientLight);
                            break;
                        case "DirectionalLight":
                            DirectionalLight directionalLight = new DirectionalLight(app, this, r);
                            Add(directionalLight);
                            break;
                    }
                }
            }
            if (points == null)
            {
                this.points = new PointCollection(this, app, true, app.Config.DisplayRegionPoints, this.app.Config.RegionPointMeshName, this.app.Config.RegionPointMaterial, MPPointType.Boundary);
                Add(points);
                points.PointsChanged += new PointsChangedEventHandler(PointsChangedHandler);
            }
        }
Пример #38
0
        public CompositionList()
        {
            this.InitializeComponent();

            this.Loaded += CompositionList_Loaded;
            this.Unloaded += CompositionList_Unloaded;

            // Get the current compositor
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            SurfaceLoader.Initialize(_compositor);
            
            //
            // Create the lights
            //
            _ambientLight = _compositor.CreateAmbientLight();
            _pointLight = _compositor.CreatePointLight();
            _distantLight = _compositor.CreateDistantLight();
            _spotLight = _compositor.CreateSpotLight();
        }