Ejemplo n.º 1
0
        private static MapLayoutResource _LoadLayout(int id)
        {
            var pathFormat = "Map/m{0}/m{0}.blend";
            var scene      = BlenderScene.FromFile(String.Format(pathFormat, id));

            return(MapLayoutResource.FromScene("parts", scene));
        }
Ejemplo n.º 2
0
        public PlayerEntity()
            : base("player")
        {
            var entitySys = EntitySystem.GetInstance();
            var mapSys    = MapSystem.GetInstance();

            //var path = "Chr/c9000/test.blend";
            //var searchPath = "Chr/c9000";
            var path       = "Chr/c9100/c9100.blend";
            var searchPath = "Chr/c9100";
            var scene      = BlenderScene.FromFile(path);

            if (scene != null)
            {
                var drawModel = DrawModel.FromScene(path + "/draw", scene, searchPath);
                var animRes   = AnimResource.FromBlenderScene(path + "/anim", scene);
                //var debugModel = DrawModel.CreateTangentFrame(path + "/debug", scene);

                if (drawModel.BoneArray.Length != 0)
                {
                    var skeletonC = new SkeletonComponent(drawModel.BoneArray);
                    AddComponent(skeletonC);
                }

                var layoutC = new LayoutComponent();
                layoutC.Transform = Matrix.Identity;
                AddComponent(layoutC);

                //var markerC = new ModelMarkerComponent(scene);
                //AddComponent(markerC);

                var modelC = new ModelComponent(GameEntityComponent.UpdateLines.Draw);
                modelC.ModelContext.EnableCastShadow = true;
                modelC.ModelContext.DrawModel        = drawModel;
                //modelC.ModelContext.DebugModel = debugModel;
                AddComponent(modelC);

                var animC = new AnimComponent(animRes);
                AddComponent(animC);

                var behaviorC = new ChrBehaviorComponent();
                AddComponent(behaviorC);

                var minimapC = new MinimapComponent();
                AddComponent(minimapC);

                MapLocation startLocation = mapSys.GetStartInfo();
                //var inputC = new GodViewInputComponent();
                var inputC = new FpsInputComponent(startLocation);
                AddComponent(inputC);
            }
        }
Ejemplo n.º 3
0
        private DrawModel _LoadParts(int modelId)
        {
            var pathFormat = "Parts/p{0}/p{0}.blend";
            var scene      = BlenderScene.FromFile(String.Format(pathFormat, modelId));

            var drawModel = DrawModel.FromScene("p" + modelId + "/draw", scene);

            m_drawModelList.Add(new _ModelInfo()
            {
                Model = drawModel, ModelId = modelId
            });
            return(drawModel);
        }
Ejemplo n.º 4
0
        public static AnimResource FromBlenderScene(String uid, BlenderScene scene)
        {
            var animeRes = new AnimResource(uid);

            foreach (var n in scene.NodeList)
            {
                if (animeRes.m_animData == null && n.Animation != null)
                {
                    // found anim res
                    animeRes.m_animData = n.Animation;
                }
            }

            return(animeRes);
        }
Ejemplo n.º 5
0
        public static MapLayoutResource FromScene(String uid, BlenderScene scene)
        {
            var res = new MapLayoutResource(uid);

            foreach (var n in scene.LinkList)
            {
                var match   = _ModelIdRegex.Match(n.TargetFileName);
                int modelId = int.Parse(match.Groups[1].Value);
                res.m_entryList.Add(new Entry()
                {
                    ModelId = modelId, Layout = n.Layout
                });
            }

            return(res);
        }
Ejemplo n.º 6
0
        public static BlenderScene FromFile(string path)
        {
            var repository = new BlendTypeRepository();
            var loader     = new BlendLoader(repository);
            var entityList = loader.FromFile(path);

            if (entityList == null)
            {
                return(null);
            }

            var scene = new BlenderScene();

            if (!scene._LoadScene(repository, entityList))
            {
                return(null);
            }

            return(scene);
        }
Ejemplo n.º 7
0
        public static DrawModel FromScene(String uid, BlenderScene scene, string fileSearchPath)
        {
            var drawSys        = DrawSystem.GetInstance();
            var drawRepository = drawSys.ResourceRepository;
            var d3d            = drawSys.D3D;

            var  model   = new DrawModel(uid);
            bool hasBone = BlenderUtil.GetLengthOf(scene.NodeList[0].BoneArray) > 0;// boneArray is set to the first node
            var  aabb    = Aabb.Invalid();

            foreach (var n in scene.NodeList)
            {
                if (n.MaterialData.Type == MaterialBase.MaterialTypes.Marker)
                {
                    // marker material is used as 'Marker'
                    continue;
                }

                if (n.Vertics.Count() == 0)
                {
                    // empty vertex list
                    continue;
                }

                // Build a vertex buffer(s)
                var vertices1 = n.Vertics
                                .Select(v => new _VertexCommon()
                {
                    Position = v.Position,
                    Normal   = v.Normal,
                    Texcoord = v.Texcoord
                }).ToArray();

                var vertices2 = n.Vertics
                                .Select(v => v.Tangent).ToArray();

                // update aabb
                foreach (var v in vertices1)
                {
                    aabb.ExtendByPoint(MathUtil.ToVector3(v.Position));
                }

                var node = new Node();
                node.Material = n.MaterialData;
                node.IsDebug  = false;
                node.HasBone  = hasBone;
                if (node.HasBone)
                {
                    // if model has bone, we create a bone vertex info
                    var vertices3 = n.Vertics
                                    .Select(v =>
                    {
                        Debug.Assert(BlenderUtil.GetLengthOf(v.BoneIndices) == BlenderUtil.GetLengthOf(v.BoneWeights), "both of bone index and bone weight must be matched");
                        //Debug.Assert(BlenderUtil.GetLengthOf(v.BoneWeights) <= _VertexBoneWeight.MAX_COUNT, "length of bone weight is over :" + BlenderUtil.GetLengthOf(v.BoneWeights));
                        Debug.Assert(BlenderUtil.GetLengthOf(v.BoneWeights) != 0, "no bone entry");
                        var tmp = new _VertexBoneWeight()
                        {
                            Index0  = BlenderUtil.GetLengthOf(v.BoneIndices) > 0 ? v.BoneIndices[0] : 0,
                            Weight0 = BlenderUtil.GetLengthOf(v.BoneWeights) > 0 ? v.BoneWeights[0] : 0.0f,
                            Index1  = BlenderUtil.GetLengthOf(v.BoneIndices) > 1 ? v.BoneIndices[1] : 0,
                            Weight1 = BlenderUtil.GetLengthOf(v.BoneWeights) > 1 ? v.BoneWeights[1] : 0.0f,
                            Index2  = BlenderUtil.GetLengthOf(v.BoneIndices) > 2 ? v.BoneIndices[2] : 0,
                            Weight2 = BlenderUtil.GetLengthOf(v.BoneWeights) > 2 ? v.BoneWeights[2] : 0.0f,
                            Index3  = BlenderUtil.GetLengthOf(v.BoneIndices) > 3 ? v.BoneIndices[3] : 0,
                            Weight3 = BlenderUtil.GetLengthOf(v.BoneWeights) > 3 ? v.BoneWeights[3] : 0.0f,
                        };
                        float sumWeight = tmp.Weight0 + tmp.Weight1 + tmp.Weight2 + tmp.Weight3;
                        tmp.Weight0    /= sumWeight;
                        tmp.Weight1    /= sumWeight;
                        tmp.Weight2    /= sumWeight;
                        tmp.Weight3    /= sumWeight;
                        return(tmp);
                    }).ToArray();

                    node.Mesh = DrawUtil.CreateMeshData(d3d, PrimitiveTopology.TriangleList, vertices1, vertices2, vertices3);
                }
                else
                {
                    node.Mesh = DrawUtil.CreateMeshData(d3d, PrimitiveTopology.TriangleList, vertices1, vertices2);
                }

                // add dispoable

/*
 * foreach (var buf in node.Mesh.Buffers)
 * {
 *  model._AddDisposable(buf.Buffer);
 * }
 */

                // create skeleton
                if (model.m_boneArray == null && n.BoneArray != null)
                {
                    model.m_boneArray = (DrawSystem.BoneData[])n.BoneArray.Clone();
                }

                // load new texture
                foreach (var texInfo in n.TextureInfos.Values)
                {
                    if (!drawRepository.Contains(texInfo.Name))
                    {
                        var tex = TextureView.FromFile(texInfo.Name, drawSys.D3D, Path.Combine(fileSearchPath, texInfo.Name));
                        drawRepository.AddResource(tex);
                    }
                }

                // copy textures from cache
                foreach (DrawSystem.TextureTypes textureType in Enum.GetValues(typeof(DrawSystem.TextureTypes)))
                {
                    if (n.TextureInfos.ContainsKey(textureType))
                    {
                        node.Material.SetTextureData(
                            textureType,
                            new DrawSystem.TextureData
                        {
                            Resource = drawRepository.FindResource <TextureView>(n.TextureInfos[textureType].Name),
                            UvScale  = n.TextureInfos[textureType].UvScale,
                        });
                    }
                }

                model.m_nodeList.Add(node);
            }

            model.m_bb = aabb;
            return(model);
        }
Ejemplo n.º 8
0
 public static DrawModel FromScene(String uid, BlenderScene scene)
 {
     return(FromScene(uid, scene, "Image/"));
 }