public void Draw(Box2 rectangle, Texture2D texture, Vector2 textureCoordinates0, Vector2 textureCoordinates1, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = (sbyte)GetTextureIndex(texture), TextureCoordinates0 = textureCoordinates0, TextureCoordinates1 = textureCoordinates1 }; }
void FillQuad(ref Mesh quad, ref QuadData data) { _vertices[0].pos.x = data.pt1.x; _vertices[0].pos.y = data.pt1.y; _vertices[0].uv.x = data.uv1.x; _vertices[0].uv.y = data.uv1.y; _vertices[1].pos.x = data.pt2.x; _vertices[1].pos.y = data.pt2.y; _vertices[1].uv.x = data.uv2.x; _vertices[1].uv.y = data.uv2.y; _vertices[2].pos.x = data.pt3.x; _vertices[2].pos.y = data.pt3.y; _vertices[2].uv.x = data.uv3.x; _vertices[2].uv.y = data.uv3.y; _vertices[3].pos.x = data.pt4.x; _vertices[3].pos.y = data.pt4.y; _vertices[3].uv.x = data.uv4.x; _vertices[3].uv.y = data.uv4.y; MeshUpdateFlags flag = GetMeshUpdateFlags(); const int indexCount = 6; const int vertexCount = 4; // 設定 Mesh Topologiy SubMeshDescriptor desc = new SubMeshDescriptor(0, indexCount, MeshTopology.Triangles); quad.SetSubMesh(0, desc, flag); // 宣告 index buffer 結構 quad.SetIndexBufferParams(indexCount, IndexFormat.UInt16); // 宣告 vertex buffer 結構 quad.SetVertexBufferParams(vertexCount, _layouts); quad.SetVertexBufferData(_vertices, 0, 0, vertexCount, 0, flag); quad.SetIndexBufferData(_indices, 0, 0, indexCount, flag); }
/// <summary> /// 构造函数 /// </summary> /// <param name="sizex"> 地图X方向大小 </param> /// <param name="sizez"> 地图Z方向大小 </param> public PathMap(int sizex, int sizez, float start_x = 0, float start_z = 0, float quadsize = 1) { m_sizeX = sizex; m_sizeZ = sizez; m_startx = start_x; m_startz = start_z; m_quad_size = quadsize; m_Data = new QuadData[sizex, sizez]; for (int i = 0; i < m_sizeX; i++) { for (int k = 0; k < m_sizeZ; k++) { m_Data[i, k] = new QuadData(); m_Data[i, k].data = null; m_Data[i, k].size = 0; m_Data[i, k].block = 0; m_Data[i, k].dynamicID = 0; m_Data[i, k].movespeed = 0; } } }
public void Draw(Box2 rectangle, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = -1 }; }
private void initQuadtree() { quadtree = new RegionQuadtree <Color>(qtResolution); quadtree.AutoExpand = true; rects = new Dictionary <AABB2i, QuadData>(); Action <object, RegionQuadtree <Color> .QuadEventArgs <Color> > onQuadAdded = (s, a) => { var aabb = a.AABB; var quadColor = a.Value; var outlineColor = new Color(0, 0, 0, 100); var rectPoints = new List <Vector2f> { new Vector2f(aabb.LowerBound.X, aabb.LowerBound.Y) * qtMultiplier, new Vector2f(aabb.LowerBound.X + aabb.Width, aabb.LowerBound.Y) * qtMultiplier, new Vector2f(aabb.LowerBound.X + aabb.Width, aabb.LowerBound.Y + aabb.Height) * qtMultiplier, new Vector2f(aabb.LowerBound.X, aabb.LowerBound.Y + aabb.Height) * qtMultiplier, }; const float outlineIntend = 1f; var outlinePoints = new List <Vector2f> { rectPoints[0] + new Vector2f(outlineIntend, outlineIntend), rectPoints[1] + new Vector2f(-outlineIntend, outlineIntend), rectPoints[2] + new Vector2f(-outlineIntend, -outlineIntend), rectPoints[3] + new Vector2f(outlineIntend, -outlineIntend), }; var quadData = new QuadData(); // quad if (freeQuadIndexes.Count > 0) { quadData.quadIndex = freeQuadIndexes[freeQuadIndexes.Count - 1]; freeQuadIndexes.RemoveAt(freeQuadIndexes.Count - 1); } else { quadData.quadIndex = quadVertexArray.VertexCount; quadVertexArray.Resize(quadVertexArray.VertexCount + 4); } for (uint i = 0; i < 4; i++) { quadVertexArray[quadData.quadIndex + i] = new Vertex(rectPoints[(int)i], quadColor); } // outline if (freeOutlineIndexes.Count > 0) { quadData.outlineIndex = freeOutlineIndexes[freeOutlineIndexes.Count - 1]; freeOutlineIndexes.RemoveAt(freeOutlineIndexes.Count - 1); } else { quadData.outlineIndex = outlineVertexArray.VertexCount; outlineVertexArray.Resize(outlineVertexArray.VertexCount + 8); } outlineVertexArray[quadData.outlineIndex] = new Vertex(outlinePoints[0] + new Vector2f(-outlineIntend, 0f), outlineColor); outlineVertexArray[quadData.outlineIndex + 1] = new Vertex(outlinePoints[1] + new Vector2f(-outlineIntend, 0f), outlineColor); outlineVertexArray[quadData.outlineIndex + 2] = new Vertex(outlinePoints[1] + new Vector2f(0f, -outlineIntend), outlineColor); outlineVertexArray[quadData.outlineIndex + 3] = new Vertex(outlinePoints[2] + new Vector2f(0f, -outlineIntend), outlineColor); outlineVertexArray[quadData.outlineIndex + 4] = new Vertex(outlinePoints[2] + new Vector2f(outlineIntend, 0f), outlineColor); outlineVertexArray[quadData.outlineIndex + 5] = new Vertex(outlinePoints[3] + new Vector2f(outlineIntend, 0f), outlineColor); outlineVertexArray[quadData.outlineIndex + 6] = new Vertex(outlinePoints[3] + new Vector2f(0f, outlineIntend), outlineColor); outlineVertexArray[quadData.outlineIndex + 7] = new Vertex(outlinePoints[0] + new Vector2f(0f, outlineIntend), outlineColor); rects.Add(aabb, quadData); }; quadtree.OnQuadAdded += new EventHandler <RegionQuadtree <Color> .QuadEventArgs <Color> >(onQuadAdded); Action <object, RegionQuadtree <Color> .QuadEventArgs <Color> > onQuadRemoving = (s, a) => { var quadData = rects[a.AABB]; // quad freeQuadIndexes.Add(quadData.quadIndex); for (uint i = 0; i < 4; i++) { quadVertexArray[quadData.quadIndex + i] = new Vertex(new Vector2f(), Color.Transparent); } // outline freeOutlineIndexes.Add(quadData.outlineIndex); for (uint i = 0; i < 8; i++) { outlineVertexArray[quadData.outlineIndex + i] = new Vertex(new Vector2f(), Color.Transparent); } rects.Remove(a.AABB); }; quadtree.OnQuadRemoving += new EventHandler <RegionQuadtree <Color> .QuadEventArgs <Color> >(onQuadRemoving); Action <object, RegionQuadtree <Color> .QuadChangedEventArgs <Color> > onQuadChanged = (s, a) => { var quadData = rects[a.AABB]; var quadColor = a.Value; var outlineColor = new Color(0, 0, 0, 100); for (uint i = 0; i < 4; i++) { quadVertexArray[quadData.quadIndex + i] = new Vertex(quadVertexArray[quadData.quadIndex + i].Position, quadColor); } for (uint i = 0; i < 8; i++) { outlineVertexArray[quadData.outlineIndex + i] = new Vertex(outlineVertexArray[quadData.outlineIndex + i].Position, outlineColor); } }; quadtree.OnQuadChanged += new EventHandler <RegionQuadtree <Color> .QuadChangedEventArgs <Color> >(onQuadChanged); Action <object, RegionQuadtree <Color> .QuadExpandEventArgs <Color> > onExpand = (s, a) => { var oldRoot = quadtree; var newRoot = a.NewRoot; this.quadtree = newRoot; qtResolution++; position -= new Vector2f(a.Offset.X, a.Offset.Y) * qtMultiplier; resolutionText.DisplayedString = "Resolution " + quadtree.AABB.Width * qtMultiplier + "x" + quadtree.AABB.Height * qtMultiplier; }; quadtree.OnExpand += new EventHandler <RegionQuadtree <Color> .QuadExpandEventArgs <Color> >(onExpand); quadtree.Set(Color.White); }
public static Tuple <List <Vector2>, List <int> > MarchingAszklars(bool[,] ptsAvaiable, double uWidth, double vWidth, bool uCycled, bool vCycled, Func <Vector2, bool> check) { var vertices = new List <Vector2>(); var indices = new List <int>(); int uDensity = ptsAvaiable.GetLength(1); double uStep = uWidth / (uDensity - 1); int vDensity = ptsAvaiable.GetLength(0); double vStep = vWidth / (vDensity - 1); var vertAvai = new QuadData[vDensity, uDensity]; { var vert = new QuadData() { Corner = -1, Down = -1, Right = -1 }; for (int i = 0; i < vDensity; i++) { for (int j = 0; j < uDensity; j++) { vertAvai[i, j] = vert; } } } for (int i = 0; i < uDensity - 1; i++) { for (int j = 0; j < vDensity - 1; j++) { if (ptsAvaiable[j, i]) { vertAvai[j, i].Corner = vertices.Count; vertices.Add(new Vector2(i * uStep, j * vStep)); } if (ptsAvaiable[j, i] != ptsAvaiable[j + 1, i]) { vertAvai[j, i].Down = vertices.Count; vertices.Add(FindPoint(new Vector2(i * uStep, j * vStep), new Vector2(i * uStep, (j + 1) * vStep), check)); } if (ptsAvaiable[j, i] != ptsAvaiable[j, i + 1]) { vertAvai[j, i].Right = vertices.Count; vertices.Add(FindPoint(new Vector2(i * uStep, j * vStep), new Vector2((i + 1) * uStep, j * vStep), check)); } } } for (int i = 0; i < uDensity - 1; i++) { if (ptsAvaiable[vDensity - 1, i]) { vertAvai[vDensity - 1, i].Corner = vertices.Count; vertices.Add(new Vector2(i * uStep, (vDensity - 1) * vStep)); } if (ptsAvaiable[vDensity - 1, i] != ptsAvaiable[vDensity - 1, i + 1]) { vertAvai[vDensity - 1, i].Right = vertices.Count; vertices.Add(FindPoint(new Vector2(i * uStep, (vDensity - 1) * vStep), new Vector2((i + 1) * uStep, (vDensity - 1) * vStep), check)); } } for (int i = 0; i < vDensity - 1; i++) { if (ptsAvaiable[i, uDensity - 1]) { vertAvai[i, uDensity - 1].Corner = vertices.Count; vertices.Add(new Vector2((uDensity - 1) * uStep, i * vStep)); } if (ptsAvaiable[i, uDensity - 1] != ptsAvaiable[i + 1, uDensity - 1]) { vertAvai[i, uDensity - 1].Down = vertices.Count; vertices.Add(FindPoint(new Vector2((uDensity - 1) * uStep, i * vStep), new Vector2((uDensity - 1) * uStep, (i + 1) * vStep), check)); } } if (ptsAvaiable[vDensity - 1, uDensity - 1]) { vertAvai[vDensity - 1, uDensity - 1].Corner = vertices.Count; vertices.Add(new Vector2(uWidth, vWidth)); } for (int i = 0; i < uDensity - 1; i++) { for (int j = 0; j < vDensity - 1; j++) { var lu = ptsAvaiable[j, i]; var ru = ptsAvaiable[j, i + 1]; var ld = ptsAvaiable[j + 1, i]; var rd = ptsAvaiable[j + 1, i + 1]; if (lu && ld) { indices.Add(vertAvai[j, i].Corner); indices.Add(vertAvai[j + 1, i].Corner); } if (lu && !ld) { indices.Add(vertAvai[j, i].Corner); indices.Add(vertAvai[j, i].Down); } if (!lu && ld) { indices.Add(vertAvai[j, i].Down); indices.Add(vertAvai[j + 1, i].Corner); } if (lu && ru) { indices.Add(vertAvai[j, i].Corner); indices.Add(vertAvai[j, i + 1].Corner); } if (lu && !ru) { indices.Add(vertAvai[j, i].Corner); indices.Add(vertAvai[j, i].Right); } if (!lu && ru) { indices.Add(vertAvai[j, i].Right); indices.Add(vertAvai[j, i + 1].Corner); } if (lu != ru && ru == ld) { indices.Add(vertAvai[j, i].Right); indices.Add(vertAvai[j, i].Down); } if (lu == rd && lu != ld) { indices.Add(vertAvai[j, i].Down); indices.Add(vertAvai[j + 1, i].Right); } if (ru != lu && lu == rd) { indices.Add(vertAvai[j, i].Right); indices.Add(vertAvai[j, i + 1].Down); } if (ld == ru && ld != rd) { indices.Add(vertAvai[j, i + 1].Down); indices.Add(vertAvai[j + 1, i].Right); } if (lu == ld && ru == rd && lu != ru) { indices.Add(vertAvai[j, i].Right); indices.Add(vertAvai[j + 1, i].Right); } if (lu == ru && ld == rd && lu != ld) { indices.Add(vertAvai[j, i].Down); indices.Add(vertAvai[j, i + 1].Down); } } } if (!uCycled) { for (int j = 0; j < vDensity - 1; j++) { var lu = ptsAvaiable[j, uDensity - 1]; var ld = ptsAvaiable[j + 1, uDensity - 1]; if (lu && ld) { indices.Add(vertAvai[j, uDensity - 1].Corner); indices.Add(vertAvai[j + 1, uDensity - 1].Corner); } if (lu && !ld) { indices.Add(vertAvai[j, uDensity - 1].Corner); indices.Add(vertAvai[j, uDensity - 1].Down); } if (!lu && ld) { indices.Add(vertAvai[j, uDensity - 1].Down); indices.Add(vertAvai[j + 1, uDensity - 1].Corner); } } } if (!vCycled) { for (int i = 0; i < uDensity - 1; i++) { var lu = ptsAvaiable[vDensity - 1, i]; var ru = ptsAvaiable[vDensity - 1, i + 1]; if (lu && ru) { indices.Add(vertAvai[vDensity - 1, i].Corner); indices.Add(vertAvai[vDensity - 1, i + 1].Corner); } if (lu && !ru) { indices.Add(vertAvai[vDensity - 1, i].Corner); indices.Add(vertAvai[vDensity - 1, i].Right); } if (!lu && ru) { indices.Add(vertAvai[vDensity - 1, i].Right); indices.Add(vertAvai[vDensity - 1, i + 1].Corner); } } } return(new Tuple <List <Vector2>, List <int> >(vertices, indices)); }
public QuadComponent(Entity entity, QuadData quadData) : base(entity) { this.quadData = quadData; }
/// <summary> /// Schedules the job to refresh the mesh data structures data with the given quads data. /// </summary> /// <param name="quadData"></param> /// <param name="innerBatchLoopCount"></param> /// <param name="dependsOn"></param> /// <returns></returns> public JobHandle ScheduleBuildMesh(QuadData quadData, int innerBatchLoopCount, JobHandle dependsOn = default) { return(ScheduleBuildMesh(quadData.quadPositions, quadData.quadNormals, quadData.quadDimensions, quadData.quadRotations, quadData.quadColors, innerBatchLoopCount, dependsOn)); }
public void Draw(Box2 rectangle, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = -1 }; }
public void Draw(Box2 rectangle, Texture2D texture, Vector2 textureCoordinates0, Vector2 textureCoordinates1, Color4ub color) { if (m_queueSize == m_queueCapacity) { Flush(); } m_queue[m_queueSize++] = new QuadData() { Transform = new Matrix3x2( m_transform.M00 * rectangle.Size.X, m_transform.M01 * rectangle.Size.X, m_transform.M10 * rectangle.Size.Y, m_transform.M11 * rectangle.Size.Y, m_transform.M00 * rectangle.Position.X + m_transform.M10 * rectangle.Position.Y + m_transform.M20, m_transform.M01 * rectangle.Position.X + m_transform.M11 * rectangle.Position.Y + m_transform.M21 ), Color = color, Texture = (sbyte)GetTextureIndex(texture), TextureCoordinates0 = textureCoordinates0, TextureCoordinates1 = textureCoordinates1 }; }