Beispiel #1
0
        private IDAESceneNode CreateLightNode(DAELoaderNode loader, light l)
        {
            IDAESceneNode result = null;

            if (l.technique_common.Item is lightTechnique_commonAmbient)
            {
                var ambLight = l.technique_common.Item as lightTechnique_commonAmbient;

                if (ambLight.color != null)
                {
                    result = loader.Context.CreateAmbientLightNode(l.name, GetColor(ambLight.color));
                }
            }
            else if (l.technique_common.Item is lightTechnique_commonDirectional)
            {
                var dirLight = l.technique_common.Item as lightTechnique_commonDirectional;

                if (dirLight.color != null)
                {
                    result = loader.Context.CreateDirectionalLightNode(l.name, GetColor(dirLight.color));
                }
            }
            else if (l.technique_common.Item is lightTechnique_commonPoint)
            {
                var pointLight = l.technique_common.Item as lightTechnique_commonPoint;

                DAEVector4 color;
                if (pointLight.color != null)
                {
                    color = GetColor(pointLight.color);
                }
                else
                {
                    color = new DAEVector4(1, 1, 1, 1);
                }

                double constantAttenuation = 1;
                if (pointLight.constant_attenuation != null)
                {
                    constantAttenuation = pointLight.constant_attenuation.Value;
                }

                double linearAttenuation = 0;
                if (pointLight.linear_attenuation != null)
                {
                    linearAttenuation = pointLight.linear_attenuation.Value;
                }

                double quadraticAttenuation = 0;
                if (pointLight.quadratic_attenuation != null)
                {
                    quadraticAttenuation = pointLight.quadratic_attenuation.Value;
                }

                result = loader.Context.CreatePointLightNode(l.name, color, constantAttenuation, linearAttenuation, quadraticAttenuation);
            }
            else if (l.technique_common.Item is lightTechnique_commonSpot)
            {
                var spotLight = l.technique_common.Item as lightTechnique_commonSpot;

                DAEVector4 color;
                if (spotLight.color != null)
                {
                    color = GetColor(spotLight.color);
                }
                else
                {
                    color = new DAEVector4(1, 1, 1, 1);
                }

                double constantAttenuation = 1;
                if (spotLight.constant_attenuation != null)
                {
                    constantAttenuation = spotLight.constant_attenuation.Value;
                }

                double linearAttenuation = 0;
                if (spotLight.linear_attenuation != null)
                {
                    linearAttenuation = spotLight.linear_attenuation.Value;
                }

                double quadraticAttenuation = 0;
                if (spotLight.quadratic_attenuation != null)
                {
                    quadraticAttenuation = spotLight.quadratic_attenuation.Value;
                }

                double spotExponent = 0;
                if (spotLight.falloff_exponent != null)
                {
                    spotExponent = spotLight.falloff_exponent.Value;
                }

                double spotCutOff = System.Math.PI; // default is 180°
                if (spotLight.falloff_angle != null)
                {
                    spotCutOff = spotLight.falloff_angle.Value / 2;
                }
                else if (l.extra != null && l.extra.Length > 0)
                {
                    foreach (var extra in l.extra)
                    {
                        if (extra.technique != null && extra.technique.Length > 0)
                        {
                            foreach (var extraTech in extra.technique)
                            {
                                if (extraTech.Any != null && extraTech.Any.Length > 0)
                                {
                                    foreach (var ele in extraTech.Any)
                                    {
                                        if (ele.ChildNodes != null)
                                        {
                                            for (int i = 0; i < ele.ChildNodes.Count; i++)
                                            {
                                                var n = ele.ChildNodes[i];
                                                if (n.Name == "falloff")
                                                {
                                                    float angle = 0;
                                                    if (float.TryParse(n.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out angle))
                                                    {
                                                        spotCutOff = ((double)angle * System.Math.PI / 180) / 2;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                result = loader.Context.CreateSpotLightNode(l.name, color, constantAttenuation, linearAttenuation, quadraticAttenuation, spotExponent, spotCutOff);
            }

            return(result);
        }
Beispiel #2
0
 abstract public IDAESpotLightNode CreateSpotLightNode(string name, DAEVector4 color, double constantAttenuation, double linearAttenuation, double quadraticAttenuation, double spotExponent, double spotCutOff);
Beispiel #3
0
        internal DAEEffect(effect efx)
        {
            foreach (effectFx_profile_abstractProfile_COMMON profile in efx.Items)
            {
                if (profile.Items != null)
                {
                    foreach (var item in profile.Items)
                    {
                        if (item is common_newparam_type)
                        {
                            common_newparam_type newparam = item as common_newparam_type;
                            if (newparam.Item is fx_surface_common)
                            {
                                foreach (fx_surface_init_from_common initFrom in (newparam.Item as fx_surface_common).init_from)
                                {
                                    _imageId = initFrom.Value;
                                    break;
                                }
                            }
                        }
                    }
                }

                effectFx_profile_abstractProfile_COMMONTechnique technique = profile.technique;

                DAEVector4     transpColor  = new DAEVector4(1, 1, 1, 1);
                double         transparency = 1;
                fx_opaque_enum opaqueMode   = fx_opaque_enum.RGB_ZERO;

                if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniquePhong) // phong
                {
                    effectFx_profile_abstractProfile_COMMONTechniquePhong p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniquePhong;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    if (p.specular != null)
                    {
                        _specular = GetColor(opaqueMode, GetRgbaColor(p.specular.Item), transpColor, transparency);
                    }

                    if (p.shininess != null && p.shininess.Item is common_float_or_param_typeFloat)
                    {
                        _shininess = (float)(p.shininess.Item as common_float_or_param_typeFloat).Value;
                    }
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueBlinn) // blinn
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueBlinn p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueBlinn;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    if (p.specular != null)
                    {
                        _specular = GetColor(opaqueMode, GetRgbaColor(p.specular.Item), transpColor, transparency);
                    }

                    if (p.shininess != null && p.shininess.Item is common_float_or_param_typeFloat)
                    {
                        _shininess = (float)(p.shininess.Item as common_float_or_param_typeFloat).Value;
                    }
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueLambert) // lambert
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueLambert p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueLambert;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.ambient != null)
                    {
                        _ambient = GetColor(opaqueMode, GetRgbaColor(p.ambient.Item), transpColor, transparency);
                    }

                    if (p.diffuse != null)
                    {
                        _diffuse = GetColor(opaqueMode, GetRgbaColor(p.diffuse.Item), transpColor, transparency);
                    }

                    _specular = new DAEVector4(0.0f, 0.0f, 0.0f, 0.0f);
                }
                else if (technique.Item is effectFx_profile_abstractProfile_COMMONTechniqueConstant) // constant
                {
                    effectFx_profile_abstractProfile_COMMONTechniqueConstant p = technique.Item as effectFx_profile_abstractProfile_COMMONTechniqueConstant;
                    if (p.transparent != null)
                    {
                        if (p.transparency != null)
                        {
                            if (p.transparency.Item is common_float_or_param_typeFloat)
                            {
                                opaqueMode   = p.transparent.opaque;
                                transpColor  = GetRgbaColor(p.transparent.Item);
                                transparency = (p.transparency.Item as common_float_or_param_typeFloat).Value;
                            }
                        }
                    }

                    if (p.emission != null)
                    {
                        _ambient   = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _diffuse   = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _specular  = GetColor(opaqueMode, GetRgbaColor(p.emission.Item), transpColor, transparency);
                        _shininess = 0;
                    }
                }

                _isTransparent = _diffuse.W < 1.0;
            }
        }
Beispiel #4
0
 abstract public IDAEPointLightNode CreatePointLightNode(string name, DAEVector4 color, double constantAttenuation, double linearAttenuation, double quadraticAttenuation);
Beispiel #5
0
 abstract public IDAEDirectionalLightNode CreateDirectionalLightNode(string name, DAEVector4 color);
Beispiel #6
0
 abstract public IDAEAmbientLightNode CreateAmbientLightNode(string name, DAEVector4 color);
Beispiel #7
0
 abstract public IDAEMaterial CreateMaterial(DAEVector4 ambient, DAEVector4 diffuse, DAEVector4 specular, double shininess, bool isTransparent, string texturePath);
Beispiel #8
0
 public double Dot(DAEVector4 v)
 {
     return(X * v.X + Y * v.Y + Z * v.Z + W * v.W);
 }