Exemplo n.º 1
0
        /// <summary>
        /// The main Process method converts an intermediate format content pipeline
        /// NodeContent tree to a ModelContent object with embedded animation data.
        /// </summary>
        public override ModelContent Process(NodeContent input,
                                             ContentProcessorContext context)
        {
            ValidateMesh(input, context, null);

            // Find the skeleton.
            BoneContent skeleton = MeshHelper.FindSkeleton(input);

            if (skeleton == null)
            {
                throw new InvalidContentException("Input skeleton not found.");
            }

            // We don't want to have to worry about different parts of the model being
            // in different local coordinate systems, so let's just bake everything.
            FlattenTransforms(input, skeleton);

            // Read the bind pose and skeleton hierarchy data.
            IList <BoneContent> bones = MeshHelper.FlattenSkeleton(skeleton);

            if (bones.Count > SkinnedEffect.MaxBones)
            {
                throw new InvalidContentException(string.Format(
                                                      "Skeleton has {0} bones, but the maximum supported is {1}.",
                                                      bones.Count, SkinnedEffect.MaxBones));
            }

            List <Matrix> bindPose          = new List <Matrix>();
            List <Matrix> inverseBindPose   = new List <Matrix>();
            List <int>    skeletonHierarchy = new List <int>();

            foreach (BoneContent bone in bones)
            {
                bindPose.Add(bone.Transform);
                inverseBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
                skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
            }

            // Convert animation data to our runtime format.
            Dictionary <string, AnimationClip> animationClips;

            animationClips = ProcessAnimations(skeleton.Animations, bones);

            // Chain to the base ModelProcessor class so it can convert the model data.
            ModelContent model = base.Process(input, context);

            // Store our custom animation data in the Tag property of the model.
            model.Tag = new SkinningData(animationClips, bindPose,
                                         inverseBindPose, skeletonHierarchy);

            return(model);
        }
        private void InitializeFloorAsphalt()
        {
            float l = spaceSize;
            float h = 0f;

            VertexData[] vertices = new VertexData[]
            {
                new VertexData {
                    Position = new Vector3(-l, h, -l), Normal = Vector3.Up, Texture = new Vector2(0.0f, 0.0f)
                },
                new VertexData {
                    Position = new Vector3(-l, h, +l), Normal = Vector3.Up, Texture = new Vector2(0.0f, 1.0f)
                },
                new VertexData {
                    Position = new Vector3(+l, h, -l), Normal = Vector3.Up, Texture = new Vector2(1.0f, 0.0f)
                },
                new VertexData {
                    Position = new Vector3(+l, h, +l), Normal = Vector3.Up, Texture = new Vector2(1.0f, 1.0f)
                },
            };

            uint[] indices = new uint[]
            {
                0, 1, 2,
                1, 3, 2,
            };

            MaterialContent mat = MaterialContent.Default;

            mat.DiffuseTexture   = "SceneLights/floors/asphalt/d_road_asphalt_stripes_diffuse.dds";
            mat.NormalMapTexture = "SceneLights/floors/asphalt/d_road_asphalt_stripes_normal.dds";
            mat.SpecularTexture  = "SceneLights/floors/asphalt/d_road_asphalt_stripes_specular.dds";

            var content = ModelContent.GenerateTriangleList(vertices, indices, mat);

            var desc = new ModelDescription()
            {
                Name                    = "Floor",
                Static                  = true,
                CastShadow              = true,
                DeferredEnabled         = true,
                DepthEnabled            = true,
                AlphaEnabled            = false,
                UseAnisotropicFiltering = true,
                Content                 = new ContentDescription()
                {
                    ModelContent = content
                }
            };

            this.AddComponent <Model>(desc);
        }
        private AnimationClips ProcessAnimations(ModelContent model, NodeContent input, ContentProcessorContext context)
        {
            //first build a lookup table so we can determine the index into the list of bones from a bone name
            for (int i = 0; i < model.Bones.Count; i++)
            {
                bones[model.Bones[i].Name] = i;
            }

            AnimationClips animationClips = new AnimationClips();

            ProcessAnimationRecursive(input, animationClips);
            return(animationClips);
        }
Exemplo n.º 4
0
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
            // play with this later
            //foreach (MD5Submesh submesh in input.Submeshes)
            //{
            //    TextureContent l = context.BuildAndLoadAsset<TextureContent, TextureContent>(new ExternalReference<TextureContent>(submesh.Shader), "TextureProcessor");
            //    submesh.TextureContent = l;
            //}
            ModelContent model = MD5CapsuleContent.CreateCapsule(Vector3.Forward * 30f + Vector3.Up * 30f, Vector3.Forward * -30f + Vector3.Up * 30f, Vector3.Right, 20f, context);

            input.CapsuleContent = model;
            return(input);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculate a bounding box for the model.
        /// </summary>
        /// <param name="model">The model to calculate AABBs for</param>
        public static void CalculateBounding(NodeContent input, ModelContent model)
        {
            BoundingBox    box    = new BoundingBox();
            BoundingSphere sphere = new BoundingSphere();

            CalculateBounding(input, ref box, ref sphere);
            if (model.Tag == null)
            {
                model.Tag = new Dictionary <string, object>();
            }
            (model.Tag as Dictionary <string, object>).Add("BoundingBox", box);
            (model.Tag as Dictionary <string, object>).Add("BoundingSphere", sphere);
        }
Exemplo n.º 6
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            var animationProcessor = new AnimationsProcessor();

            animationProcessor.MaxBones = this.MaxBones;
            animationProcessor.GenerateKeyframesFrequency = this.GenerateKeyframesFrequency;
            animationProcessor.FixRealBoneRoot            = this._fixRealBoneRoot;
            var animation = animationProcessor.Process(input, context);

            ModelContent model = base.Process(input, context);

            model.Tag = animation;
            return(model);
        }
Exemplo n.º 7
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            AnimatedModelData animatedModelData = ExtractSkeletonAndAnimations(input, context);

            Dictionary <string, object> dictionary = new Dictionary <string, object> {
                { "AnimatedModelData", animatedModelData }
            };

            ModelContent modelContent = base.Process(input, context);

            modelContent.Tag = dictionary;

            return(modelContent);
        }
Exemplo n.º 8
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            ModelContent model = base.Process(input, context);

            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    Proccess(part);
                }
            }

            return(model);
        }
Exemplo n.º 9
0
        // Function to process a model from normal content to a model with animation data
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            SetSkinnedEffect(input);

            BoneContent skeleton = ImportSkeleton(input);

            model = base.Process(input, context);

            AnimationDataImport(model, input, context);

            model.Tag = animationData;

            return(model);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initialize skeleton data
        /// </summary>
        /// <param name="modelContent">Model content</param>
        /// <param name="joint">Joint to initialize</param>
        /// <param name="animations">Animation list to feed</param>
        private static JointAnimation[] InitializeJoints(ModelContent modelContent, Joint joint, string[] skinController)
        {
            List <JointAnimation> animations = new List <JointAnimation>();

            List <JointAnimation> boneAnimations = new List <JointAnimation>();

            //Find keyframes for current bone
            var c = FindJointKeyframes(joint.Name, modelContent.Animations);

            if (c != null && c.Length > 0)
            {
                //Set bones
                Array.ForEach(c, (a) =>
                {
                    boneAnimations.Add(new JointAnimation(a.Joint, a.Keyframes));
                });
            }

            if (boneAnimations.Count > 0)
            {
                //Only one bone animation (for now)
                animations.Add(boneAnimations[0]);
            }

            foreach (string controllerName in skinController)
            {
                var controller = modelContent.Controllers[controllerName];

                Matrix ibm = Matrix.Identity;

                if (controller.InverseBindMatrix.ContainsKey(joint.Name))
                {
                    ibm = controller.InverseBindMatrix[joint.Name];
                }

                joint.Offset = ibm;
            }

            if (joint.Childs?.Length > 0)
            {
                foreach (var child in joint.Childs)
                {
                    var ja = InitializeJoints(modelContent, child, skinController);

                    animations.AddRange(ja);
                }
            }

            return(animations.ToArray());
        }
Exemplo n.º 11
0
        public ActionResult ThemMoi()
        {
            IEnumerable <DropdownModel> category = _services.Dropdownlist(0, null, "CHUYENMUCDAOTAO", 1);

            ViewBag.contentParentId = category.Select(x => new SelectListItem {
                Text = x.Text, Value = x.Value.ToString()
            });
            var model = new ModelContent
            {
                contentId = 0
            };

            return(View(model));
        }
Exemplo n.º 12
0
        public override HeightMapInfoContent Process(Texture2DContent input, ContentProcessorContext context)
        {
            MeshBuilder meshBuilder = MeshBuilder.StartMesh("terrain");

            input.ConvertBitmapType(typeof(PixelBitmapContent <float>));
            PixelBitmapContent <float> item = (PixelBitmapContent <float>)input.Mipmaps[0];

            for (int i = 0; i < item.Height; i++)
            {
                for (int j = 0; j < item.Width; j++)
                {
                    Vector3 width = new Vector3(
                        mScale * (j - (item.Width - 1) / 2f),
                        width.Y = (item.GetPixel(j, i) - 1f) * Bumpiness,
                        width.Z = mScale * (i - (item.Height - 1) / 2f)
                        );
                    meshBuilder.CreatePosition(width);
                }
            }
            BasicMaterialContent basicMaterialContent = new BasicMaterialContent();

            basicMaterialContent.SpecularColor = new Vector3(0.4f, 0.4f, 0.4f);
            if (!string.IsNullOrEmpty(TerrainTexture))
            {
                string directoryName = Path.GetDirectoryName(input.Identity.SourceFilename);
                string str           = Path.Combine(directoryName, TerrainTexture);
                basicMaterialContent.Texture = new ExternalReference <TextureContent>(str);
            }
            meshBuilder.SetMaterial(basicMaterialContent);
            int num  = meshBuilder.CreateVertexChannel <Vector2>(VertexChannelNames.TextureCoordinate(0));
            int num1 = 0;

            while (num1 < item.Height - 1)
            {
                for (int k = 0; k < item.Width - 1; k++)
                {
                    AddVertex(meshBuilder, num, item.Width, k, num1);
                    AddVertex(meshBuilder, num, item.Width, k + 1, num1);
                    AddVertex(meshBuilder, num, item.Width, k + 1, num1 + 1);
                    AddVertex(meshBuilder, num, item.Width, k, num1);
                    AddVertex(meshBuilder, num, item.Width, k + 1, num1 + 1);
                    AddVertex(meshBuilder, num, item.Width, k, num1 + 1);
                }
                num1++;
            }
            MeshContent  meshContent  = meshBuilder.FinishMesh();
            ModelContent modelContent = context.Convert <MeshContent, ModelContent>(meshContent, "ModelProcessor");

            return(new HeightMapInfoContent(modelContent, meshContent, mScale, item.Width, item.Height));
        }
Exemplo n.º 13
0
        public override ModelContent Process(NodeContent node, ContentProcessorContext context)
        {
            ModelContent model = base.Process(node, context);

            ProcessChildren(node);

            int i = 0;

            foreach (ModelMeshContent mesh in model.Meshes)
            {
                mesh.Tag = information[i++];
            }

            return(model);
        }
Exemplo n.º 14
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            CalculateTangentFrames(input, context);

            ModelContent modelContent = base.Process(input, context);

            foreach (ModelMeshContent modelMesh in modelContent.Meshes)
            {
                foreach (ModelMeshPartContent modelMeshPart in modelMesh.MeshParts)
                {
                    modelMeshPart.Tag = modelMeshPart.Material.Name;
                }
            }

            return(modelContent);
        }
        /// <summary>
        /// The function to process a model from original content into model content for export
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            // Process the skeleton for skinned character animation
            BoneContent skeleton = ProcessSkeleton(input);

            SwapSkinnedMaterial(input);

            model = base.Process(input, context);

            ProcessAnimations(model, input, context);

            // Add the extra content to the model
            model.Tag = modelExtra;

            return(model);
        }
Exemplo n.º 16
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            foundSkinning_ = false;
            if (!forceShader_.Equals("") || !forceSkinnedShader_.Equals(""))
            {
                ReplaceShaders(input, context, input.Identity);
            }
            ModelContent ret = base.Process(input, context);

            if (ret.Tag == null)
            {
                ret.Tag = new Dictionary <string, object>();
            }
            SetTexturePaths(ret);
            return(ret);
        }
Exemplo n.º 17
0
        //ModelContent modelContent = null;
        //static bool m_First = true;

        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            bool collapsed = BokuPipeline.MaterialsGroup.PreProcess(input);

            // stash our model content so that we can use it to look up meshes
            //
            ModelContent model = base.Process(input, context);

            FindBBoxesRecurse(input, model);

            BokuPipeline.MaterialsGroup.TagMeshParts(model, collapsed);

            /*
             * // Just debug foo, nothing to see here.
             * foreach (ModelMeshContent mesh in model.Meshes)
             * {
             *  foreach (ModelMeshPartContent part in mesh.MeshParts)
             *  {
             *      MaterialContent mat = part.Material;
             *      float alpha = mat.OpaqueData.GetValue<float>("Alpha", -1.0f);
             *      Vector3 diffuse = mat.OpaqueData.GetValue<Vector3>("DiffuseColor", -Vector3.One);
             *      if(alpha != 1.0f)
             *      {
             *      }
             *  }
             * }
             */

            return(model);



            //NodeContentCollection ncc = input.Children;

            //parseChildren(ncc);
            //ModelContent mc2 = base.Process(input, context);


            //mc2.Meshes[0].MeshParts[0];
            //int nMeshes = mc2.Meshes.Count;
            //BoundingBox[] boxes = new BoundingBox[nMeshes];
            //for(int i = 0; i < nMeshes; i++)
            //{
            //    boxes[i] = GetBoundingBox(mc2.Meshes[i]);
            //}
            //return m_ModelContent;
        }
Exemplo n.º 18
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            List <Vector3> lowestPoints = new List <Vector3>();

            lowestPoints = FindLowestPoints(input, lowestPoints);

            ModelContent model = base.Process(input, context);

            int i = 0;

            foreach (ModelMeshContent mesh in model.Meshes)
            {
                mesh.Tag = lowestPoints[i++];
            }

            return(model);
        }
Exemplo n.º 19
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            ModelContent model = base.Process(input, context);

            foreach (ModelMeshContent mm in model.Meshes)
            {
                sphereList.Add(mm.BoundingSphere);
            }
            foreach (BoundingSphere bs in sphereList)
            {
                master = BoundingSphere.CreateMerged(master, bs);
            }

            sphereList.Insert(0, master);
            model.Tag = sphereList;
            return(model);
        }
Exemplo n.º 20
0
        private SkinInfoContentCollection[] ProcessSkinInfo(ModelContent model)
        {
            SkinInfoContentCollection[] info     = new SkinInfoContentCollection[model.Meshes.Count];
            Dictionary <string, int>    boneDict = new Dictionary <string, int>();

            foreach (ModelBoneContent b in model.Bones)
            {
                if (b.Name != null && !boneDict.ContainsKey(b.Name))
                {
                    boneDict.Add(b.Name, b.Index);
                }
            }

            for (int i = 0; i < info.Length; i++)
            {
                info[i] = new SkinInfoContentCollection();
                BoneIndexer indexer = indexers[i];
                ReadOnlyCollection <string> skinnedBoneNames = indexer.SkinnedBoneNames;

                Matrix[] absoluteTransforms = new Matrix[model.Bones.Count];
                CalculateAbsoluteTransforms(model.Bones[0], absoluteTransforms);

                Matrix absoluteMeshTransform;
                if (absoluteMeshTransforms == null)
                {
                    absoluteMeshTransform = absoluteTransforms[model.Meshes[i].ParentBone.Index];
                }
                else
                {
                    absoluteMeshTransform = absoluteMeshTransforms[i];
                }

                for (int j = 0; j < skinnedBoneNames.Count; j++)
                {
                    string          name    = skinnedBoneNames[j];
                    SkinInfoContent content = new SkinInfoContent();
                    content.BoneIndex                = boneDict[name];
                    content.PaletteIndex             = indexer.GetBoneIndex(name);
                    content.InverseBindPoseTransform = absoluteMeshTransform *
                                                       Matrix.Invert(absoluteTransforms[boneDict[name]]);
                    content.BoneName = name;
                    info[i].Add(content);
                }
            }
            return(info);
        }
Exemplo n.º 21
0
        private void InitializeFloor()
        {
            float l = 10f;
            float h = 0f;

            VertexData[] vertices = new VertexData[]
            {
                new VertexData {
                    Position = new Vector3(-l, -h, -l), Normal = Vector3.Up, Texture = new Vector2(0.0f, 0.0f)
                },
                new VertexData {
                    Position = new Vector3(-l, -h, +l), Normal = Vector3.Up, Texture = new Vector2(0.0f, l)
                },
                new VertexData {
                    Position = new Vector3(+l, -h, -l), Normal = Vector3.Up, Texture = new Vector2(l, 0.0f)
                },
                new VertexData {
                    Position = new Vector3(+l, -h, +l), Normal = Vector3.Up, Texture = new Vector2(l, l)
                },
            };

            uint[] indices = new uint[]
            {
                0, 1, 2,
                1, 3, 2,
            };

            var material = MaterialContent.Default;

            material.AmbientColor   = Color.White * 0.4f;
            material.DiffuseTexture = "resources/floor.png";

            var content = ModelContent.GenerateTriangleList(vertices, indices, material);

            var desc = new ModelDescription()
            {
                UseAnisotropicFiltering = true,
                Content = new ContentDescription()
                {
                    ModelContent = content,
                }
            };

            this.AddComponent <Model>(desc, SceneObjectUsages.Ground);
        }
Exemplo n.º 22
0
        private void ProcessModelMeshParts(ModelContent model)
        {
            foreach (ModelMeshContent mesh in model.Meshes)
            {
                foreach (ModelMeshPartContent part in mesh.MeshParts)
                {
                    part.Tag = new ModelMeshPartTag()
                    {
                        BoundingBox = new BoundingBox()
                    };

                    /*
                     * XamlSerializer.SerializationData.Add(new PropertyInstance(part.Tag, "Textures"),
                     *  part.Material.OpaqueData["AttachedTextures"] as Dictionary<TextureUsage, ContentReference<TextureContent>>);
                     */
                }
            }
        }
Exemplo n.º 23
0
        private void AnimationDataImport(ModelContent model, NodeContent input, ContentProcessorContext context)
        {
            for (int i = 0; i < model.Bones.Count; i++)
            {
                bones[model.Bones[i].Name] = i;
            }

            boneTransforms = new Matrix[model.Bones.Count];
            AnimationDataImportRec(input);

            if (animationData.Clips.Count == 0)
            {
                Clip clip = new Clip();
                animationData.Clips.Add(clip);

                string clipName = "Take 001";

                clips[clipName] = clip;

                clip.Name = clipName;
                foreach (ModelBoneContent bone in model.Bones)
                {
                    Clip.Bone clipBone = new Clip.Bone();
                    clipBone.Name = bone.Name;

                    clip.Bones.Add(clipBone);
                }
            }

            foreach (Clip clip in animationData.Clips)
            {
                for (int b = 0; b < bones.Count; b++)
                {
                    List <Clip.Keyframe> keyframes = clip.Bones[b].Keyframes;
                    if (keyframes.Count == 0 || keyframes[0].Time > 0)
                    {
                        Clip.Keyframe keyframe = new Clip.Keyframe();
                        keyframe.Time      = 0;
                        keyframe.Transform = boneTransforms[b];
                        keyframes.Insert(0, keyframe);
                    }
                }
            }
        }
        /// <summary>
        /// The main Process method converts an intermediate format content pipeline NodeContent tree to an animation data format.
        /// </summary>
        public override ModelAnimationClip Process(NodeContent input, ContentProcessorContext context)
        {
            RigidModelProcessor rigidModelProcessor = new RigidModelProcessor();
            ModelContent        model = rigidModelProcessor.Process(input, context);

            if (string.IsNullOrEmpty(AnimationName)) // If no name was set then take the first animation
            {
                foreach (var animation in ((ModelAnimationData)model.Tag).ModelAnimationClips)
                {
                    return(animation.Value);
                }
                throw new InvalidContentException("There is no rigid animation present in this model.");
            }
            if (((ModelAnimationData)model.Tag).ModelAnimationClips.ContainsKey(AnimationName))
            {
                return(((ModelAnimationData)model.Tag).ModelAnimationClips[AnimationName]);
            }
            throw new InvalidContentException("There is no rigid animation present with this name.");
        } // Process
Exemplo n.º 25
0
        public override ModelContent Process(NodeContent input, ContentProcessorContext context)
        {
            //uncomment this to debug the content processor
            //System.Diagnostics.Debugger.Launch();

            LevelTagData tag = new LevelTagData();

            AddPointsTo(GetDataHolder(input, "light_poles"), tag.lightPoleLocations);
            AddPointsTo(GetDataHolder(input, "cars"), tag.cars);
            AddPointsTo(GetDataHolder(input, "mailbox1"), tag.mailbox1);
            AddPointsTo(GetDataHolder(input, "mailbox2"), tag.mailbox2);
            AddPointsTo(GetDataHolder(input, "beer"), tag.beer);

            ModelContent retModel = base.Process(input, context);

            retModel.Tag = tag;

            return(retModel);
        }
Exemplo n.º 26
0
        public override ModelContent Process(NodeContent input,
                                             ContentProcessorContext context)
        {
            CalculateTangentFrames(input, context);
            // The base processor will include the tagent frames in the resulting model
            ModelContent modelContent = base.Process(input, context);

            // Copy each mesh part's material name to it's tag. Chip rendering uses the
            // material name to determine which texture goes on which side.
            foreach (ModelMeshContent modelMesh in modelContent.Meshes)
            {
                foreach (ModelMeshPartContent modelMeshPart in modelMesh.MeshParts)
                {
                    modelMeshPart.Tag = modelMeshPart.Material.Name;
                }
            }

            return(modelContent);
        }
Exemplo n.º 27
0
        public ActionResult Detail(int?Id)
        {
            ModelContent entity;
            int          _languageId = 1;

            if (Id.HasValue && Id > 0)
            {
                Content model = _services.GetById(Id.Value);
                entity = new ModelContent
                {
                    contentId              = model.contentId,
                    contentAlias           = model.contentAlias,
                    contentBody            = model.contentBody,
                    contentThumbnail       = model.contentThumbnail,
                    contentDescription     = model.contentDescription,
                    contentMetaKeywords    = model.contentMetaKeywords,
                    contentMetaTitle       = model.contentMetaTitle,
                    contentName            = model.contentName,
                    contentMetaDescription = model.contentMetaDescription,
                    contentParentId        = model.contentParentId,
                    authorize              = model.authorize,
                    isNew             = model.isNew ?? false,
                    isFeature         = model.isFeature ?? false,
                    contentCreateTime = model.contentCreateTime.ToString("dd/MM/yyyy")
                };
                ViewBag.Title = "Cập nhật tin tức";
            }
            else
            {
                entity = new ModelContent
                {
                    contentId = 0
                };
                ViewBag.Title = "Thêm mới tin tức";
            }
            IEnumerable <DropdownModel> category = _services.Dropdownlist(0, null, "CHUYENMUCTINTUC", _languageId);

            ViewBag.contentParentId = category.Select(x => new SelectListItem {
                Text = x.Text, Value = x.Value.ToString()
            });
            return(View(entity));
        }
Exemplo n.º 28
0
        public override ModelContent Process(NodeContent input,
                                             ContentProcessorContext context)
        {
            MeshContent mesh = input as MeshContent;

            if (mesh != null)
            {
                MeshHelper.CalculateTangentFrames(mesh,
                                                  VertexChannelNames.TextureCoordinate(0),
                                                  VertexChannelNames.Tangent(0),
                                                  VertexChannelNames.Binormal(0));
            }



            // Use base ModelProcessor class to do the actual model processing
            ModelContent model = base.Process(input, context);

            return(model);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Initialize lights
        /// </summary>
        /// <param name="drw">Drawing data</param>
        /// <param name="modelContent">Model content</param>
        private static void InitializeLights(ref DrawingData drw, ModelContent modelContent)
        {
            List <SceneLight> lights = new List <SceneLight>();

            foreach (var key in modelContent.Lights.Keys)
            {
                var l = modelContent.Lights[key];

                if (l.LightType == LightContentTypes.Point)
                {
                    lights.Add(l.CreatePointLight());
                }
                else if (l.LightType == LightContentTypes.Spot)
                {
                    lights.Add(l.CreateSpotLight());
                }
            }

            drw.Lights = lights.ToArray();
        }
Exemplo n.º 30
0
        /// <summary>
        /// Initialize materials
        /// </summary>
        /// <param name="drw">Drawing data</param>
        /// <param name="modelContent">Model content</param>
        private static void InitializeMaterials(ref DrawingData drw, ModelContent modelContent)
        {
            foreach (string mat in modelContent.Materials?.Keys)
            {
                var effectInfo = modelContent.Materials[mat];

                MeshMaterial meshMaterial = new MeshMaterial()
                {
                    Material          = new Material(effectInfo),
                    EmissionTexture   = drw.Textures[effectInfo.EmissionTexture],
                    AmbientTexture    = drw.Textures[effectInfo.AmbientTexture],
                    DiffuseTexture    = drw.Textures[effectInfo.DiffuseTexture],
                    SpecularTexture   = drw.Textures[effectInfo.SpecularTexture],
                    ReflectiveTexture = drw.Textures[effectInfo.ReflectiveTexture],
                    NormalMap         = drw.Textures[effectInfo.NormalMapTexture],
                };

                drw.Materials.Add(mat, meshMaterial);
            }
        }