예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="color"></param>
        /// <param name="texture"></param>
        private bool ReadEffectColorType(Profile_COMMON prof, FX_Common_Color_Or_Texture_Type type, out Vector4 color, out IOTexture texture)
        {
            color   = Vector4.One;
            texture = null;

            if (type.Color != null)
            {
                var c = type.Color.GetValues();
                color = new Vector4(c[0], c[1], c[2], c[3]);
            }

            if (type.Texture != null)
            {
                // create diffuse texture
                texture = new IOTexture();

                var texid = type.Texture.Textures;


                // blender image lookup
                if (prof.New_Param != null)
                {
                    var samp = prof.New_Param.FirstOrDefault(e => e.sID == type.Texture.Textures);
                    if (samp != null && samp.Data != null)
                    {
                        var samp2d = samp.Data.FirstOrDefault(e => e.Name == "sampler2D");
                        if (samp2d != null)
                        {
                            var src = FindChild(samp2d, "source");
                            if (src != null)
                            {
                                var surf = prof.New_Param.FirstOrDefault(e => e.sID == src.InnerText);
                                if (surf != null && surf.Data != null)
                                {
                                    var sur2d = surf.Data.FirstOrDefault(e => e.Name == "surface");
                                    if (sur2d != null)
                                    {
                                        var init = FindChild(sur2d, "init_from");
                                        texid = init.InnerText;
                                    }
                                }
                            }
                        }
                    }
                }

                // lookup image from image library
                var image = _collada.Library_Images.Image.FirstOrDefault(e => e.ID == texid);
                if (image != null)
                {
                    texture.Name     = image.Name;
                    texture.FilePath = string.IsNullOrEmpty(image.Init_From.Ref) ? image.Init_From.Value : image.Init_From.Ref;
                }
            }

            return(type.Color != null);
        }
예제 #2
0
 public Effect(string id, string name, Profile_COMMON profileCommon)
 {
     _id = id;
     _name = name;
     _profileCommon = profileCommon;
 }
예제 #3
0
        public Effect(XPathNodeIterator iterator, string uri)
        {
            XPathNodeIterator attributeIterator;
            attributeIterator = iterator.Current.Select("@" + XmlCollada.Effect.id);
            if (attributeIterator.Count > 0)
            {
                attributeIterator.MoveNext();
                _id = attributeIterator.Current.Value;
            }
            attributeIterator = iterator.Current.Select("@" + XmlCollada.Effect.name);
            if (attributeIterator.Count > 0)
            {
                attributeIterator.MoveNext();
                _name = attributeIterator.Current.Value;
            }

            XPathNodeIterator profileCommonNodesIterator = iterator.Current.SelectChildren(XmlCollada.Profile_COMMON.root, uri);
            if (profileCommonNodesIterator.Count > 0)
            {
                profileCommonNodesIterator.MoveNext();
                _profileCommon = new Profile_COMMON(profileCommonNodesIterator, uri);
            }
        }
예제 #4
0
        private Effect GetEffect(ModelPart p, int i, string modelName)
        {
            var id     = $"{modelName}-Part-{i}";
            var effect = new Effect
            {
                Id   = $"{id}-effect",
                Name = $"{id}-effect"
            };

            var profile = new Profile_COMMON
            {
                Technique = new Profile_COMMONTechnique
                {
                    Sid     = "common",
                    Lambert = new Profile_COMMONTechniqueLambert
                    {
                        Emission = new Common_Color_Or_Texture_Type
                        {
                            Color = new Common_Color_Or_Texture_TypeColor
                            {
                                Value = "0 0 0 1"
                            }
                        },
                        Index_Of_Refraction = new Common_Float_Or_Param_Type
                        {
                            Float = new Common_Float_Or_Param_TypeFloat
                            {
                                Value = 1
                            }
                        },
                        Diffuse = new Common_Color_Or_Texture_Type
                        {
                            Texture = new Common_Color_Or_Texture_TypeTexture
                            {
                                Texcoord = "UVMap",
                                Texture  = $"{id}-sampler"
                            }
                        }
                    }
                }
            };

            var surface = new Fx_Surface_Common
            {
                Type = Fx_Surface_Type_Enum.Item2D,
            };

            surface.Init_From.Add(new Fx_Surface_Init_From_Common
            {
                Value = $"{id}-texture"
            });

            var sampler = new Fx_Sampler2D_Common
            {
                Source = $"{id}-surface"
            };

            profile.Newparam.Add(new Common_Newparam_Type
            {
                Sid     = $"{id}-surface",
                Surface = surface
            });

            profile.Newparam.Add(new Common_Newparam_Type
            {
                Sid       = $"{id}-sampler",
                Sampler2D = sampler
            });

            effect.Fx_Profile_Abstract.Add(profile);
            return(effect);
        }