Exemple #1
0
 protected void parseModel()
 {
     components = model.Children.First().Components;
     foreach (var component in components)
     {
         if (component.GetType() == typeof(MaterialComponent)) { materialComponent = (MaterialComponent)component; }
         if (component.GetType() == typeof(TransformComponent)) { transformComponent = (TransformComponent)component; }
         if (component.GetType() == typeof(MeshComponent)) { meshComponent = (MeshComponent)component; }
     }
 }
Exemple #2
0
        public MaterialComponentNameAndFractionControl(ComponentsControl dmSubstancesCtrl, MaterialComponent matComponent, INumericFormat iNumericFormat)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            this.dmComponentsControl = dmSubstancesCtrl;
            this.materialComponent   = matComponent;
            this.IsSelected          = false;
            this.InitializeTheUI(this.materialComponent, iNumericFormat);
        }
Exemple #3
0
        public override void ComponentsFractionsChanged()
        {
            Phase             gasPhase = this.phases[0] as Phase;
            MaterialComponent sc       = gasPhase[0];

            sc.SetMassFractionValue(this.DryMedium.GetMassFractionValue());
            sc = gasPhase[1];
            sc.SetMassFractionValue(this.Moisture.GetMassFractionValue());
            gasPhase.Normalize();
            //gasPhase.CalculateThermalProperties(temperature, pressure);
        }
Exemple #4
0
        private ShaderEffect LookupMaterial(MaterialComponent mc)
        {
            if (_matMap.TryGetValue(mc, out var mat))
            {
                return(mat);
            }

            mat = ShaderCodeBuilder.MakeShaderEffectFromMatComp(mc, _currentNode.GetWeights()); // <- broken
            _matMap.Add(mc, mat);
            return(mat);
        }
Exemple #5
0
 protected override void Start()
 {
     if (!Application.Current.IsEditor)
     {
         MaterialComponent materialComponent = Owner.FindComponent <MaterialComponent>();
         if (materialComponent != null && materialComponent.Material != null)
         {
             materialComponent.Material = materialComponent.Material.Clone();
         }
     }
 }
Exemple #6
0
        void OnMaterial(MaterialComponent material)
        {
            // LightDir in ModelKoordinate angeben, im Moment sind es ViewKoordinaten
            // falls Richtungsvektor, dann Mult. mit RC.InvTransModelView.
            // falls Punktvektor, dann mit RC.ModelView



            //RC.SetShaderParam(LightDirParam, new float3(0, 0, -1) * RC.InvModelView);
            RC.SetShaderParamTexture(TextureParam, _maleModelTexture);
            RC.SetShaderParam(TexMixParam, 1.0f);
        }
        private ShaderEffect LookupMaterial(MaterialComponent mc)
        {
            ShaderEffect mat;

            if (!_matMap.TryGetValue(mc, out mat))
            {
                mat = MakeMaterial(mc);
                mat.AttachToContext(_rc);
                _matMap.Add(mc, mat);
            }
            return(mat);
        }
 private void AnalyzeMaterial(MaterialComponent mc)
 {
     _hasDiffuse = mc.HasDiffuse;
     if (_hasDiffuse)
         _hasDiffuseTexture = (mc.Diffuse.Texture != null);
     _hasSpecular = mc.HasSpecular;
     if (_hasSpecular)
         _hasSpecularTexture = (mc.Specular.Texture != null);
     _hasEmissive = mc.HasEmissive;
     if (_hasEmissive)
         _hasEmissiveTexture = (mc.Emissive.Texture != null);
     _hasBump = mc.HasBump; // always has a texture...
 }
Exemple #9
0
        void OnMaterial(MaterialComponent material)
        {
            String shaderName;

            if (shaderEffects.ContainsKey(CurrentNode.Name))
            {
                shaderName = CurrentNode.Name;
            }
            else
            {
                shaderName = "standard";
            }

            if (material.HasDiffuse)
            {
                shaderEffects[shaderName].SetEffectParam("albedo", material.Diffuse.Color);
                if (material.Diffuse.Texture != null)
                {
                    shaderEffects[shaderName].SetEffectParam("texture", textures[material.Diffuse.Texture]);
                    shaderEffects[shaderName].SetEffectParam("texmix", 1.0f);
                }
                else
                {
                    shaderEffects[shaderName].SetEffectParam("texmix", 0.0f);
                }
            }
            else
            {
                shaderEffects[shaderName].SetEffectParam("albedo", float3.Zero);
            }
            if (material.HasSpecular)
            {
                shaderEffects[shaderName].SetEffectParam("shininess", material.Specular.Shininess);
                shaderEffects[shaderName].SetEffectParam("specfactor", material.Specular.Intensity);
                shaderEffects[shaderName].SetEffectParam("speccolor", material.Specular.Color);
            }
            else
            {
                shaderEffects[shaderName].SetEffectParam("shininess", 0);
                shaderEffects[shaderName].SetEffectParam("specfactor", 0);
                shaderEffects[shaderName].SetEffectParam("speccolor", float3.Zero);
            }
            if (material.HasEmissive)
            {
                shaderEffects[shaderName].SetEffectParam("ambientcolor", material.Emissive.Color);
            }
            else
            {
                shaderEffects[shaderName].SetEffectParam("ambientcolor", float3.Zero);
            }
        }
Exemple #10
0
        internal void PostBalanceCalculation()
        {
            DryingGasStream gasInlet           = owner.GasInlet as DryingGasStream;
            DryingGasStream gasOutlet          = owner.GasOutlet as DryingGasStream;
            double          gasOutMassFlow     = gasOutlet.MassFlowRate.Value;
            double          gasMoistureContent = gasOutlet.Humidity.Value;
            double          wg = gasOutlet.MassFlowRateDryBase.Value;

            if (gasOutMassFlow == Constants.NO_VALUE && gasMoistureContent != Constants.NO_VALUE && wg != Constants.NO_VALUE)
            {
                gasOutMassFlow = wg * (1.0 + gasMoistureContent);
            }

            if (gasOutMassFlow != Constants.NO_VALUE)
            {
                SolidPhase          sp        = null;
                DryingGasComponents inletDgc  = gasInlet.GasComponents;
                DryingGasComponents outletDgc = gasOutlet.GasComponents;
                double massFlowRateOfEntrainedMaterial;
                sp = outletDgc.SolidPhase;
                if (sp == null)
                {
                    if (inletDgc.NumberOfPhases <= 1)
                    {
                        ArrayList         solidCompList = new ArrayList();
                        MaterialComponent mc            = new MaterialComponent(inletDgc.AbsoluteDryMaterial.Substance);
                        solidCompList.Add(mc);
                        mc = new MaterialComponent(inletDgc.Moisture.Substance);
                        solidCompList.Add(mc);
                        sp = new SolidPhase("Cyclone Outlet Solid Phase", solidCompList);
                    }
                    else
                    {
                        sp = (SolidPhase)inletDgc.SolidPhase.Clone();
                    }

                    outletDgc.AddPhase(sp);
                }

                double volumeFlow   = gasInlet.VolumeFlowRate.Value;
                double inletLoading = inletParticleLoading.Value;
                double efficiency   = collectionEfficiency.Value;
                if (volumeFlow != Constants.NO_VALUE && inletLoading != Constants.NO_VALUE && efficiency != Constants.NO_VALUE)
                {
                    massFlowRateOfEntrainedMaterial = volumeFlow * inletLoading * (1.0 - efficiency);
                    Calculate(massFlowRateOfParticleLostToGasOutlet, massFlowRateOfEntrainedMaterial);
                    sp.MassFraction = massFlowRateOfEntrainedMaterial / gasOutMassFlow;
                }
            }
        }
Exemple #11
0
        public void UpdateTheUI(ArrayList materialComponentList, INumericFormat iNumericFormat)
        {
            this.panel.Controls.Clear();
            IEnumerator e = materialComponentList.GetEnumerator();
            int         i = 0;

            while (e.MoveNext())
            {
                MaterialComponent mc = (MaterialComponent)e.Current;
                MaterialComponentNameAndFractionControl ctrl = new MaterialComponentNameAndFractionControl(this, mc, iNumericFormat);
                ctrl.Location = new Point(0, ctrl.Height * i++);
                this.panel.Controls.Add(ctrl);
            }
        }
Exemple #12
0
        public static double GetDensity(ArrayList materialComponents, double t)
        {
            t = t - 273.15;
            double             total = 0.0;
            double             den   = 0;
            double             massFrac;
            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    den = GetCarbohydrateDensity(t);
                }
                else if (s.Name == "Ash")
                {
                    den = GetAshDensity(t);
                }
                else if (s.Name == "Fiber")
                {
                    den = GetFiberDensity(t);
                }
                else if (s.Name == "Fat")
                {
                    den = GetFatDensity(t);
                }
                else if (s.Name == "Protein")
                {
                    den = GetProteinDensity(t);
                }

                total += dryTotalFraction * massFrac / den;
            }

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();
            double            moistureDensity   = GetWaterDensity(t);

            total += moistureFraction / moistureDensity;

            double density = 1.0 / total;

            return(density);
        }
Exemple #13
0
        public static double GetCp(ArrayList materialComponents, double t)
        {
            t = t - 273.15;
            double heatCapacity = 0.0;
            double cp           = 0;
            double massFrac;

            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();

            ArrayList components = drySubstance.Components;

            foreach (MaterialComponent mc in components)
            {
                Substance s = mc.Substance;
                massFrac = mc.GetMassFractionValue();
                if (s.Name == "Carbohydrate")
                {
                    cp = GetCarbohydrateCp(t);
                }
                else if (s.Name == "Ash")
                {
                    cp = GetAshCp(t);
                }
                else if (s.Name == "Fiber")
                {
                    cp = GetFiberCp(t);
                }
                else if (s.Name == "Fat")
                {
                    cp = GetFatCp(t);
                }
                else if (s.Name == "Protein")
                {
                    cp = GetProteinCp(t);
                }

                heatCapacity += cp * massFrac * dryTotalFraction;
            }

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();

            cp = GetWaterCp(t);

            heatCapacity += cp * moistureFraction;

            return(1000 * heatCapacity);
        }
Exemple #14
0
        public void GetComponentFromEntity()
        {
            var somePlayerComponent   = new PlayerComponent(_entity);
            var someMaterialComponent = new MaterialComponent(_entity);

            _entity.AddComponent(somePlayerComponent)
            .AddComponent(someMaterialComponent);

            var samePlayerComponent   = _entity.GetComponent <PlayerComponent>();
            var sameMaterialComponent = _entity.GetComponent <MaterialComponent>();

            Assert.That(Has.ReferenceEquals(somePlayerComponent,
                                            samePlayerComponent));
            Assert.That(Has.ReferenceEquals(someMaterialComponent,
                                            sameMaterialComponent));
        }
Exemple #15
0
        public void Remove(string name)
        {
            MaterialComponent scToBeDeleted = null;

            foreach (MaterialComponent sc in components)
            {
                if (sc.Name.Equals(name))
                {
                    scToBeDeleted = sc;
                    break;
                }
            }
            if (scToBeDeleted != null)
            {
                components.Remove(scToBeDeleted);
            }
        }
        public static ShaderEffect MakeShaderEffect(float3 diffuseColor, float3 specularColor, float shininess)
        {
            MaterialComponent temp = new MaterialComponent
            {
                Diffuse = new MatChannelContainer
                {
                    Color = diffuseColor
                },
                Specular = new SpecularChannelContainer
                {
                    Color     = specularColor,
                    Shininess = shininess
                }
            };

            return(ShaderCodeBuilder.MakeShaderEffectFromMatComp(temp));
        }
Exemple #17
0
        private void SetMaterialComponents(DryingMaterialCache cache, INumericFormat iNumericFormat)
        {
            IEnumerator en = cache.MaterialComponentList.GetEnumerator();

            while (en.MoveNext())
            {
                MaterialComponent mc  = (MaterialComponent)en.Current;
                ListViewItem      lvi = new ListViewItem();

                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(lvi, mc.Name);
                lvi.SubItems.Insert(0, lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, mc.MassFraction.Value.ToString(iNumericFormat.NumericFormatString));
                lvi.SubItems.Insert(1, lvsi);

                this.listViewMaterialComponents.Items.Add(lvi);
            }
        }
Exemple #18
0
        public void Remove(string name)
        {
            MaterialComponent sc = null;
            IEnumerator       e  = components.GetEnumerator();

            while (e.MoveNext())
            {
                sc = (e.Current) as MaterialComponent;
                if (sc.Name.Equals(name))
                {
                    break;
                }
            }
            if (sc != null)
            {
                components.Remove(sc);
            }
        }
Exemple #19
0
        private void Populate(IList list)
        {
            IEnumerator en = list.GetEnumerator();

            while (en.MoveNext())
            {
                MaterialComponent mc  = (MaterialComponent)en.Current;
                ListViewItem      lvi = new ListViewItem();

                ListViewItem.ListViewSubItem lvsi = new ListViewItem.ListViewSubItem(lvi, mc.Name);
                lvi.SubItems.Insert(0, lvsi);

                lvsi = new ListViewItem.ListViewSubItem(lvi, mc.MassFraction.Value.ToString("0.000"));
                lvi.SubItems.Insert(1, lvsi);

                this.listViewComponents.Items.Add(lvi);
            }
        }
Exemple #20
0
        // Init is called on startup.
        public override void Init()
        {
            // 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);

            // Create five cubes
            _cubes = new SceneNodeContainer[5];

            for (int i = 0; i < 5; i++)
            {
                var cubeTransform = new TransformComponent {
                    Scale = new float3(1, 1, 1), Translation = new float3((i - 2) * 15, 0, 0)
                };
                var cubeMaterial = new MaterialComponent
                {
                    Diffuse = new MatChannelContainer {
                        Color = new float3(1 - (i / 4.0f), 0.5f, i / 4.0f)
                    },
                    Specular = new SpecularChannelContainer {
                        Color = float3.One, Shininess = 4
                    }
                };
                var cubeMesh = SimpleMeshes.CreateCuboid(new float3(10, 10, 10));

                var cubeNode = new SceneNodeContainer();
                cubeNode.Components = new List <SceneComponentContainer>();
                cubeNode.Components.Add(cubeTransform);
                cubeNode.Components.Add(cubeMaterial);
                cubeNode.Components.Add(cubeMesh);

                _cubes[i] = cubeNode;
            }

            // Create the scene containing the cubes
            _scene          = new SceneContainer();
            _scene.Children = new List <SceneNodeContainer>();
            foreach (SceneNodeContainer cube in _cubes)
            {
                _scene.Children.Add(cube);
            }

            // Create a scene renderer holding the scene above
            _sceneRenderer = new SceneRenderer(_scene);
        }
Exemple #21
0
        public static double GetCp(ArrayList materialComponents, double t)
        {
            //t = t - 273.15;
            double heatCapacity = 0.0;
            //double cp = 0;
            //double massFrac;

            MaterialComponent  dryMatComponent  = materialComponents[0] as MaterialComponent;
            CompositeSubstance drySubstance     = dryMatComponent.Substance as CompositeSubstance;
            double             dryTotalFraction = dryMatComponent.GetMassFractionValue();
            double             boneDryCp        = GetAbsoluteDryCp(drySubstance, t); //Cp unit is J/kg.k

            //ArrayList components = drySubstance.Components;
            //foreach (MaterialComponent mc in components) {
            //   Substance s = mc.Substance;
            //   massFrac = mc.GetMassFractionValue();
            //   if (s.Name == "Carbohydrate") {
            //      cp = GetCarbohydrateCp(t);
            //   }
            //   else if (s.Name == "Ash") {
            //      cp = GetAshCp(t);
            //   }
            //   else if (s.Name == "Fiber") {
            //      cp = GetFiberCp(t);
            //   }
            //   else if (s.Name == "Fat") {
            //      cp = GetFatCp(t);
            //   }
            //   else if (s.Name == "Protein") {
            //      cp = GetProteinCp(t);
            //   }

            //   heatCapacity += cp * massFrac * dryTotalFraction;
            //}

            MaterialComponent moistureComponent = materialComponents[1] as MaterialComponent;
            double            moistureFraction  = moistureComponent.GetMassFractionValue();
            double            moistureCp        = 1000 * GetWaterCp(t - 273.15);//convert from kJ/kg.k to J/kg.k, we have to multiply 1000

            heatCapacity = boneDryCp * dryTotalFraction + moistureCp * moistureFraction;

            return(heatCapacity);
        }
Exemple #22
0
 protected void parseModel()
 {
     components = model.Children.First().Components;
     foreach (var component in components)
     {
         if (component.GetType() == typeof(MaterialComponent))
         {
             materialComponent = (MaterialComponent)component;
         }
         if (component.GetType() == typeof(TransformComponent))
         {
             transformComponent = (TransformComponent)component;
         }
         if (component.GetType() == typeof(MeshComponent))
         {
             meshComponent = (MeshComponent)component;
         }
     }
 }
Exemple #23
0
        public void Remove(string name)
        {
            MaterialComponent theSC = null;

            //IEnumerator e = components.GetEnumerator();
            //while (e.MoveNext()) {
            //   sc = (e.Current) as MaterialComponent;
            foreach (MaterialComponent sc in this.components)
            {
                if (sc.Name.Equals(name))
                {
                    theSC = sc;
                    break;
                }
            }

            if (theSC != null)
            {
                components.Remove(theSC);
            }
        }
Exemple #24
0
        // public SceneObject Camera { get { return _camera; } }
        public virtual void OnLoad()
        {
            //    _camera = new PlayerCamera();
            //    if (_skybox == null)
            //       _skybox = new Skybox();
            // _camera.AddComponent(new Camera());
            //    _sceneObjects.Add(_camera);
            //   _sceneObjects.Add(_skybox);
            Context.Assetmanager.Register(new Triangle().TriangleDefaultModel);
            ModelComponent    modelSceneObject = new ModelComponent("Triangle");
            MaterialComponent materiaComponent = new MaterialComponent();
            SceneObject       sceneObject      = new SceneObject();

            sceneObject.AddComponent(modelSceneObject);
            sceneObject.AddComponent(materiaComponent);
            _sceneObjects.Add(sceneObject);
            foreach (SceneObject _sceneObject in _sceneObjects)
            {
                _sceneObject.OnLoad();
            }
        }
        public static ShaderEffect MakeShaderEffect(float3 diffuseColor, float3 specularColor, float shininess)
        {
            MaterialComponent temp = new MaterialComponent
            {
                Diffuse = new MatChannelContainer
                {
                    Color = diffuseColor
                },
                Specular = new SpecularChannelContainer
                {
                    Color     = specularColor,
                    Shininess = shininess
                }
            };

            var ret = ShaderCodeBuilder.MakeShaderEffectFromMatComp(temp);

            ret.SetEffectParam("allLights[0].intensities", new float3(1, 1, 1));

            return(ret);
        }
Exemple #26
0
        private static DryingGasComponents CreateDryingGasComponents(double flueGasMoistureContentDryBase, CompositeSubstance flueGas)
        {
            ArrayList compList = new ArrayList();

            compList.Add(new MaterialComponent(flueGas, 1 / (1 + flueGasMoistureContentDryBase)));
            compList.Add(new MaterialComponent(water, flueGasMoistureContentDryBase / (1 + flueGasMoistureContentDryBase)));

            DryingGasComponents flueGasComponents = new DryingGasComponents(compList);

            ArrayList         gasCompList = new ArrayList();
            MaterialComponent pc          = new MaterialComponent(flueGas);

            gasCompList.Add(pc);
            pc = new MaterialComponent(water);
            gasCompList.Add(pc);
            GasPhase gp = new GasPhase("Drying Gas Gas Phase", gasCompList);

            flueGasComponents.AddPhase(gp);

            return(flueGasComponents);
        }
Exemple #27
0
        public LegacyShaderCodeBuilder(MaterialComponent mc, Mesh mesh, WeightComponent wc = null)
        {
            if (wc != null)
            {
                _hasWeightMap = true;
                _nBones       = wc.Joints.Count;
            }
            else
            {
                _nBones = 0;
            }

            //float f1 = 1;
            //var type = f1.GetType();
            _normalizeNormals = true;
            if (mesh != null)
            {
                AnalyzeMesh(mesh);
            }
            else
            {
                _hasVertices = _hasNormals = _hasUVs = true;
            }
            AnalyzeMaterial(mc);

            //TODO: Use/switch lightning method to build PS & VS

            StringBuilder vs = new StringBuilder();

            MeshInputDeclarations(vs);
            MatrixDeclarations(vs);
            VSBody(vs);
            _vs = vs.ToString();

            StringBuilder ps = new StringBuilder();

            PixelInputDeclarations(ps);
            PSBody(ps);
            _ps = ps.ToString();
        }
Exemple #28
0
 void OnMaterial(MaterialComponent material)
 {
     if (material.HasDiffuse)
     {
         ShaderEffect.SetEffectParam("albedo", material.Diffuse.Color);
         if (material.Diffuse.Texture == "Leaves.jpg")
         {
             ShaderEffect.SetEffectParam("texture", _leafTexture);
             ShaderEffect.SetEffectParam("texmix", 1.0f);
         }
         else
         {
             ShaderEffect.SetEffectParam("texmix", 0.0f);
         }
     }
     else
     {
         ShaderEffect.SetEffectParam("albedo", float3.Zero);
     }
     if (material.HasSpecular)
     {
         ShaderEffect.SetEffectParam("shininess", material.Specular.Shininess);
         ShaderEffect.SetEffectParam("specfactor", material.Specular.Intensity);
         ShaderEffect.SetEffectParam("speccolor", material.Specular.Color);
     }
     else
     {
         ShaderEffect.SetEffectParam("shininess", 0);
         ShaderEffect.SetEffectParam("specfactor", 0);
         ShaderEffect.SetEffectParam("speccolor", float3.Zero);
     }
     if (material.HasEmissive)
     {
         ShaderEffect.SetEffectParam("ambientcolor", material.Emissive.Color);
     }
     else
     {
         ShaderEffect.SetEffectParam("ambientcolor", float3.Zero);
     }
 }
Exemple #29
0
        /*
         * struct SurfaceOutput {
         *  half3 Albedo;
         *  half3 Normal;
         *  half3 Emission;
         *  half Specular;
         *  half Gloss;
         *  half Alpha;
         * };
         */

        public ShaderCodeBuilder(MaterialComponent mc, MeshComponent mesh, WeightComponent wc = null)
        {
            if (wc != null)
            {
                _hasWeightMap = true;
                _nBones       = wc.Joints.Count;
            }
            else
            {
                _nBones = 0;
            }

            float f1 = 1;

            f1.GetType();
            _normalizeNormals = true;
            if (mesh != null)
            {
                AnalyzeMesh(mesh);
            }
            else
            {
                _hasVertices = _hasNormals = _hasUVs = true;
            }
            AnalyzeMaterial(mc);

            StringBuilder vs = new StringBuilder();

            MeshInputDeclarations(vs);
            MatrixDeclarations(vs);
            VSBody(vs);
            _vs = vs.ToString();

            StringBuilder ps = new StringBuilder();

            PixelInputDeclarations(ps);
            PSBody(ps);
            _ps = ps.ToString();
        }
Exemple #30
0
        private void Ray(Camera3D activeCamera, TouchLocation touchLocation)
        {
            // Creates Ray from Touch 2D position
            _nearPosition.X = touchLocation.Position.X;
            _nearPosition.Y = touchLocation.Position.Y;
            _nearPosition.Z = 0.0f;

            _farPosition.X = touchLocation.Position.X;
            _farPosition.Y = touchLocation.Position.Y;
            _farPosition.Z = 1.0f;

            // Unproject Mouse Position
            _nearPosition = activeCamera.Unproject(ref _nearPosition);
            _farPosition  = activeCamera.Unproject(ref _farPosition);

            // Update ray. Ray launched from nearPosition in rayDirection direction.
            _rayDirection = _farPosition - _nearPosition;
            _rayDirection.Normalize();
            _ray.Direction = _rayDirection;
            _ray.Position  = _nearPosition;

            foreach (Entity entity in this.Owner.Scene.EntityManager.FindAllByTag("touchable"))
            {
                _entityBoxCollider = entity.FindComponent <BoxCollider3D>();

                if (_entityBoxCollider != null)
                {
                    _materialComponent = entity.FindComponent <MaterialComponent>();

                    _collisionResult = _entityBoxCollider.Intersects(ref _ray);

                    if (_collisionResult.HasValue)
                    {
                        PushpinTapped?.Invoke(this, new PushpinTappedEventArgs(entity.Name));
                    }
                }
            }
        }
Exemple #31
0
        private void AddGeometryToSceneNode(Geometry geometry, float3 position)
        {
            Geometry newGeo = geometry.CloneGeometry();

            newGeo.Triangulate();
            var geometryMesh = new JometriMesh(newGeo);

            var sceneNodeContainer = new SceneNodeContainer {
                Components = new List <SceneComponentContainer>()
            };

            var meshComponent = new Mesh
            {
                Vertices  = geometryMesh.Vertices,
                Triangles = geometryMesh.Triangles,
                Normals   = geometryMesh.Normals,
            };
            var translationComponent = new TransformComponent
            {
                Rotation    = float3.Zero,
                Scale       = new float3(1, 1, 1),
                Translation = position
            };
            var materialComponent = new MaterialComponent
            {
                Diffuse  = new MatChannelContainer(),
                Specular = new SpecularChannelContainer(),
            };

            materialComponent.Diffuse.Color = _defaultColor;
            sceneNodeContainer.Components.Add(translationComponent);
            sceneNodeContainer.Components.Add(materialComponent);
            sceneNodeContainer.Components.Add(meshComponent);

            _parentNode.Children.Add(sceneNodeContainer);
            _activeGeometrys.Add(_parentNode.Children.IndexOf(sceneNodeContainer), geometry);
        }
Exemple #32
0
        void OnMaterial(MaterialComponent material)
        {
            if (material.HasDiffuse)
            {
                RC.SetShaderParam(AlbedoParam, material.Diffuse.Color);
            }
            else
            {
                RC.SetShaderParam(AlbedoParam, float3.Zero);
            }

            if (CurrentNode.Name.Contains("block"))
            {
                RC.SetShaderParamTexture(TextureParam, _textures["pflasterstein.jpg"]);
                RC.SetShaderParam(TexMixParam, 1.0f);
            }

            else if (CurrentNode.Name.Contains("Ebene"))
            {
                RC.SetShaderParamTexture(TextureParam, _textures["justBlack.jpg"]);
                RC.SetShaderParam(TexMixParam, 1.0f);
            }
            else if (CurrentNode.Name.Contains("himmel"))
            {
                RC.SetShaderParamTexture(TextureParam, _textures["blue_poly.jpg"]);
                RC.SetShaderParam(TexMixParam, 1.0f);
            }
            else
            {
                RC.SetShaderParam(TexMixParam, 0.0f);
            }

            if (material.HasSpecular)
            {
                RC.SetShaderParam(ShininessParam, material.Specular.Shininess);
                RC.SetShaderParam(SpecFactorParam, material.Specular.Intensity);
                RC.SetShaderParam(SpecColorParam, material.Specular.Color);
            }
            else
            {
                RC.SetShaderParam(ShininessParam, 0);
                RC.SetShaderParam(SpecFactorParam, 0);
                RC.SetShaderParam(SpecColorParam, float3.Zero);
            }
            if (material.HasEmissive)
            {
                RC.SetShaderParam(AmbientColorParam, material.Emissive.Color);
            }
            else
            {
                RC.SetShaderParam(AmbientColorParam, float3.Zero);
            }
        }