public NumberEntity(InitParam initParam) { Debug.Assert(initParam.Numbers.Length == 10, "set texture array whitch represents 0-9 number"); m_initParam = initParam; m_plane = DrawModel.CreateFloor(0.3f, 1.0f, Vector4.Zero); m_text = "".ToArray(); SetPose(Matrix.Identity); }
public static DrawModel CreateFloor(float geometryScale, float uvScale, Vector4 offset) { var drawSys = DrawSystem.GetInstance(); var d3d = drawSys.D3D; float gs = geometryScale; float us = uvScale; var vertices = new _VertexCommon[] { new _VertexCommon() { Position = new Vector4(-gs, 0, gs, 1), Texcoord = new Vector2(0, 0), Normal = Vector3.UnitY }, new _VertexCommon() { Position = new Vector4(gs, 0, gs, 1), Texcoord = new Vector2(us, 0), Normal = Vector3.UnitY }, new _VertexCommon() { Position = new Vector4(gs, 0, -gs, 1), Texcoord = new Vector2(us, us), Normal = Vector3.UnitY }, new _VertexCommon() { Position = new Vector4(-gs, 0, gs, 1), Texcoord = new Vector2(0, 0), Normal = Vector3.UnitY }, new _VertexCommon() { Position = new Vector4(gs, 0, -gs, 1), Texcoord = new Vector2(us, us), Normal = Vector3.UnitY }, new _VertexCommon() { Position = new Vector4(-gs, 0, -gs, 1), Texcoord = new Vector2(0, us), Normal = Vector3.UnitY }, }; Aabb aabb = Aabb.Invalid(); for (int i = 0; i < vertices.Length; ++i) { vertices[i].Position += offset; vertices[i].Position.W = 1; aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position)); } var model = new DrawModel(""); var mesh = DrawUtil.CreateMeshData <_VertexCommon>(d3d, PrimitiveTopology.TriangleList, vertices); model.m_nodeList.Add(new Node() { Mesh = mesh, Material = DebugMaterial.Create(), IsDebug = false, HasBone = false }); model.m_bb = aabb; return(model); }
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); } }
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); }
public void DrawDebugModel(Matrix masterTrans) { var drawSys = DrawSystem.GetInstance(); var context = drawSys.GetDrawContext(); foreach (var node in m_nodeArray) { if (node.DbgDrawModel == null) { // create model in first draw time var model = DrawModel.CreateBone(node.Bone.Name, node.Bone.Length, Color.Yellow, Vector4.Zero); //var model = DrawModel.CreateGizmo(node.Bone.Name, 1.0f); node.DbgDrawModel = model; } var mesh = node.DbgDrawModel.NodeList[0].Mesh; var worldTransform = GetModelTransform(node.Index) * masterTrans; var material = node.DbgDrawModel.NodeList[0].Material; context.DrawDebugModel(worldTransform, mesh, DrawSystem.RenderMode.Transparency); } }
private void _RegisterDebugEntity() { var entitySys = EntitySystem.GetInstance(); var entity = new GameEntity("frustum"); var layoutC = new LayoutComponent(); layoutC.Transform = Matrix.Identity; entity.AddComponent(layoutC); var drawC = new EasyDrawComponent((IDrawContext context, Matrix layout, DrawModel lastDrawModel) => { if (lastDrawModel != null) { lastDrawModel.Dispose(); } var cameraSys = CameraSystem.GetInstance(); if (cameraSys.IngameCamera != cameraSys.ActiveCamera) { // frustum is visible in editor mode var drawModel = DrawModel.CreateFrustum("frustum", _GetFrustumMatrix(), Color.Cyan); foreach (var node in drawModel.NodeList) { context.DrawDebugModel(layout, node.Mesh, DrawSystem.RenderMode.Transparency); } return(drawModel); } else { return(null); } }); entity.AddComponent(drawC); m_dbgModelEntity = entity; }
public static DrawModel CreateFrustum(String uid, Matrix viewProjectionMatrix, Color4 color) { var drawSys = DrawSystem.GetInstance(); var d3d = drawSys.D3D; viewProjectionMatrix.Invert(); var points = new Vector4[8]; points[0] = Vector3.Transform(new Vector3(-1, -1, 0), viewProjectionMatrix); points[1] = Vector3.Transform(new Vector3(1, -1, 0), viewProjectionMatrix); points[2] = Vector3.Transform(new Vector3(-1, 1, 0), viewProjectionMatrix); points[3] = Vector3.Transform(new Vector3(1, 1, 0), viewProjectionMatrix); points[4] = Vector3.Transform(new Vector3(-1, -1, 1), viewProjectionMatrix); points[5] = Vector3.Transform(new Vector3(1, -1, 1), viewProjectionMatrix); points[6] = Vector3.Transform(new Vector3(-1, 1, 1), viewProjectionMatrix); points[7] = Vector3.Transform(new Vector3(1, 1, 1), viewProjectionMatrix); var vertices = new _VertexDebug[] { new _VertexDebug() { Position = points[0] }, new _VertexDebug() { Position = points[1] }, new _VertexDebug() { Position = points[1] }, new _VertexDebug() { Position = points[3] }, new _VertexDebug() { Position = points[3] }, new _VertexDebug() { Position = points[2] }, new _VertexDebug() { Position = points[2] }, new _VertexDebug() { Position = points[0] }, new _VertexDebug() { Position = points[4] }, new _VertexDebug() { Position = points[5] }, new _VertexDebug() { Position = points[5] }, new _VertexDebug() { Position = points[7] }, new _VertexDebug() { Position = points[7] }, new _VertexDebug() { Position = points[6] }, new _VertexDebug() { Position = points[6] }, new _VertexDebug() { Position = points[4] }, new _VertexDebug() { Position = points[0] }, new _VertexDebug() { Position = points[4] }, new _VertexDebug() { Position = points[1] }, new _VertexDebug() { Position = points[5] }, new _VertexDebug() { Position = points[2] }, new _VertexDebug() { Position = points[6] }, new _VertexDebug() { Position = points[3] }, new _VertexDebug() { Position = points[7] }, }; Aabb aabb = Aabb.Invalid(); for (int i = 0; i < vertices.Length; ++i) { vertices[i].Position.X /= vertices[i].Position.W; vertices[i].Position.Y /= vertices[i].Position.W; vertices[i].Position.Z /= vertices[i].Position.W; vertices[i].Position.W = 1; vertices[i].Color = color; aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position)); } var model = new DrawModel(uid); model.m_nodeList.Add(new Node() { Mesh = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices), Material = DebugMaterial.Create(), IsDebug = true, HasBone = false, }); model.m_bb = aabb; return(model); }
public static DrawModel CreateBox(String uid, Aabb box, Color4 color) { var drawSys = DrawSystem.GetInstance(); var d3d = drawSys.D3D; Vector3 min = box.Min; Vector3 max = box.Max; var vertices = new _VertexDebug[] { new _VertexDebug() { Position = new Vector4(min.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, min.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, min.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(max.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, max.Z, 1) }, new _VertexDebug() { Position = new Vector4(min.X, max.Y, min.Z, 1) }, }; Aabb aabb = Aabb.Invalid(); for (int i = 0; i < vertices.Length; ++i) { vertices[i].Position.W = 1; vertices[i].Color = color; aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position)); } var model = new DrawModel(uid); model.m_nodeList.Add(new Node() { Mesh = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices), Material = DebugMaterial.Create(), IsDebug = true, HasBone = false, }); model.m_bb = aabb; return(model); }
public static DrawModel CreateBone(String uid, float length, Color4 color, Vector4 offset) { var drawSys = DrawSystem.GetInstance(); var d3d = drawSys.D3D; float w = 0.1f * length; float L = length; var vertices = new _VertexDebug[] { // bottom pyramid new _VertexDebug() { Position = new Vector4(0, 0, 0, 1) }, new _VertexDebug() { Position = new Vector4(-w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, 0, 1) }, new _VertexDebug() { Position = new Vector4(-w, w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, 0, 1) }, new _VertexDebug() { Position = new Vector4(w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, 0, 1) }, new _VertexDebug() { Position = new Vector4(w, w, w, 1) }, // middle plane new _VertexDebug() { Position = new Vector4(w, w, w, 1) }, new _VertexDebug() { Position = new Vector4(-w, w, w, 1) }, new _VertexDebug() { Position = new Vector4(-w, w, w, 1) }, new _VertexDebug() { Position = new Vector4(-w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(-w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(w, w, w, 1) }, // top pyramid new _VertexDebug() { Position = new Vector4(0, 0, L, 1) }, new _VertexDebug() { Position = new Vector4(-w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, L, 1) }, new _VertexDebug() { Position = new Vector4(w, -w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, L, 1) }, new _VertexDebug() { Position = new Vector4(-w, w, w, 1) }, new _VertexDebug() { Position = new Vector4(0, 0, L, 1) }, new _VertexDebug() { Position = new Vector4(w, w, w, 1) }, }; Aabb aabb = Aabb.Invalid(); for (int i = 0; i < vertices.Length; ++i) { vertices[i].Position += offset; vertices[i].Position.W = 1; vertices[i].Color = color; aabb.ExtendByPoint(MathUtil.ToVector3(vertices[i].Position)); } var model = new DrawModel(uid); model.m_nodeList.Add(new Node() { Mesh = DrawUtil.CreateMeshData <_VertexDebug>(d3d, PrimitiveTopology.LineList, vertices), Material = DebugMaterial.Create(), IsDebug = true, HasBone = false, }); model.m_bb = aabb; return(model); }
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); }
/// <summary> /// Update component /// </summary> /// <param name="dT">spend time [sec]</param> public override void Update(double dT) { if (ModelContext.DrawModel == null) { return; } var drawSys = DrawSystem.GetInstance(); var cullingSys = CullingSystem.GetInstance(); var context = drawSys.GetDrawContext(); var dbg = DrawSystem.GetInstance().DebugCtrl; var layout = m_layoutC.Transform; CullingSystem.FrustumCullingResult result = cullingSys.CheckFrustumCulling(ModelContext.DrawModel.BoundingBox, layout); if (!result.IsVisible) { // out of view-volume } else { // Add command for draw mdoel foreach (var node in ModelContext.DrawModel.NodeList) { if (UpdateLine == GameEntityComponent.UpdateLines.PreDraw) { // use draw buffer drawSys.GetDrawBuffer().AppendStaticModel(layout, result.Z, ref node.Mesh, node.Material); } else if (UpdateLine == GameEntityComponent.UpdateLines.Draw) { Matrix[] boneMatrices = null; if (m_skeletonC != null) { // has skeleton boneMatrices = m_skeletonC.Skeleton.GetAllSkinningTransforms(); } MaterialBase material = node.Material; context.DrawModel(layout, Color4.White, node.Mesh, material, DrawSystem.RenderMode.Opaque, boneMatrices); } } } /* * // Add command for debug mdoel * if (dbg.IsEnableDrawTangentFrame && ModelContext.DebugModel != null) * { * foreach (var node in ModelContext.DebugModel.NodeList) * { * var command = DrawCommand.CreateDrawDebugCommand(node.Material, layout, node.Mesh); * drawSys.AddDrawCommand(command); * } * } */ /* * // Add command for draw shadow * if (ModelContext.EnableCastShadow) * { * foreach (var node in ModelContext.DrawModel.NodeList) * { * var command = DrawCommand.CreateDrawShadowCommand(layout, node.Mesh); * drawSys.AddDrawCommand(command); * } * * } */ // draw aabb if (dbg.IsEnableAabb) { if (m_dbgBoundingBoxModel == null) { // create model in first draw time var model = DrawModel.CreateBox("aabb", ModelContext.DrawModel.BoundingBox, Color.Pink); m_dbgBoundingBoxModel = model; } var mesh = m_dbgBoundingBoxModel.NodeList[0].Mesh; MaterialBase material = m_dbgBoundingBoxModel.NodeList[0].Material; context.DrawDebugModel(layout, mesh, DrawSystem.RenderMode.Transparency); } // draw bones for debug if (dbg.IsEnableDrawBone) { if (m_skeletonC != null) { m_skeletonC.Skeleton.DrawDebugModel(layout); } } }
public Context() { EnableCastShadow = false; DrawModel = null; DebugModel = null; }