void Start() { thisCell = gameObject.GetComponent <Cell3D>(); thisCell.data = new CellData { Position = gameObject.GetComponent <Transform>().position, X = X, Y = Y }; thisCell.enabled = false; }
public GridPartition3D(Vector3 min, Vector3 max, int rows, int cols, int stacks) { cells = new Cell3D[rows * cols * stacks]; for (int i = 0; i < cells.Length; i++) { cells[i] = new Cell3D(); } this.rows = rows; this.cols = cols; this.stacks = stacks; UpdateMinMax(min, max); }
public GridPartition3D(Vector3 min, Vector3 max, int rows, int cols, int stacks) { cells = new Cell3D[rows * cols * stacks]; for (int i = 0; i < cells.Length; i++) { cells[i] = new Cell3D(); } this.rows = rows; this.cols = cols; this.stacks = stacks; UpdateMinMax(min, max); }
public void LoadGrid(CellData _cell, float XposMod, float ZPosMod) { GameObject tempCell = Instantiate(Cell3DPrefab, transform); Transform tempCellTransform = tempCell.GetComponent <Transform>(); tempCell.SetActive(true); tempCellTransform.localScale = new Vector3((tempCellTransform.lossyScale.x / tempCellTransform.localScale.x) * XMod, 0.1f, (tempCellTransform.lossyScale.z / tempCellTransform.localScale.z) * ZMod); //tempCellTransform.position = _cell.Position; tempCellTransform.position = new Vector3((gridOrigin.x + XMod / 2) + XMod * XposMod, 0, (gridOrigin.z + ZMod / 2) + +ZMod * ZPosMod); Cell3D cellvalue = tempCell.GetComponent <Cell3D>(); cellvalue.data = _cell; cellvalue.data.graphics3D = tempCell; cellvalue.UpdateTypes(); }
public void Load3DGrid(CellData _cell, float XposMod, float ZPosMod) { GameObject tempCell = Instantiate(Cell3DPrefab, transform); Transform tempCellTransform = tempCell.GetComponent <Transform>(); tempCell.SetActive(true); tempCellTransform.localScale = new Vector3((tempCellTransform.lossyScale.x / tempCellTransform.localScale.x) * XMod3D, 0.1f, (tempCellTransform.lossyScale.z / tempCellTransform.localScale.z) * ZMod3D); tempCellTransform.position = new Vector3((gridOrigin.x + XMod3D / 2) + XMod3D * XposMod, 0, (gridOrigin.z + ZMod3D / 2) + +ZMod3D * ZPosMod); Cell3D cellvalue = tempCell.GetComponent <Cell3D>(); cellvalue.data = _cell; cellvalue.data.graphics3D = tempCell; cellvalue.GetComponent <MeshRenderer>().enabled = false; cellvalue.NotInEditor = true; cellvalue.UpdateTypes(); }
/// <summary> /// "пересобрать ячейки" /// </summary> void RebuildCells() { foreach (var cell in CellsList) { cell.Particles.Clear(); } CellNet = null; CellsList.Clear(); if (AllParticles.Count == 0) { return; } xmin = AllParticles.Min(p => p.X) - hmax * 0.5; ymin = AllParticles.Min(p => p.Y) - hmax * 0.5; zmin = AllParticles.Min(p => p.Z) - hmax * 0.5; xmax = AllParticles.Max(p => p.X) + hmax * 0.5; ymax = AllParticles.Max(p => p.Y) + hmax * 0.5; zmax = AllParticles.Max(p => p.Z) + hmax * 0.5; Nrows = (int)Ceiling((ymax - ymin) / hmax); Ncols = (int)Ceiling((xmax - xmin) / hmax); Naisles = (int)Ceiling((zmax - zmin) / hmax); CellNet = new Cell3D[Ncols, Nrows, Naisles]; for (int i = 0; i < Ncols; i++) { for (int j = 0; j < Nrows; j++) { for (int k = 0; k < Naisles; k++) { double x0 = xmin + i * hmax; double x1 = x0 + hmax; double y0 = ymin + j * hmax; double y1 = y0 + hmax; double z0 = zmin + j * hmax; double z1 = z0 + hmax; CellNet[i, j, k] = new Cell3D(i, j, k, x0, x1, y0, y1, z0, z1); CellsList.Add(CellNet[i, j, k]); } } } }
public void CreateEmptyMesh(int X_extent, int Y_extent, int Z_extent) { CellMesh.Clear();//开新空间 for (int i = 0; i < X_extent; i++) { List <List <Cell3D> > columnYZ = new List <List <Cell3D> >(); for (int j = 0; j < Y_extent; j++) { List <Cell3D> columnZ = new List <Cell3D>(); List <bool> columnOfIsDiscoveredZ = new List <bool>(); for (int k = 0; k < Z_extent; k++) { Cell3D c = new Cell3D(i, j, k);//物理坐标 columnZ.Add(c); columnOfIsDiscoveredZ.Add(false); } columnYZ.Add(columnZ); } CellMesh.Add(columnYZ); } }
public override void GenerateContacts(ref List <RigidBody3D> bodies, ref List <Contact3D> contacts, float dt) { //Clear all cells for (int i = 0; i < cells.Length; i++) { cells[i].Clear(); } //Insert bodies into all cells they overlap for (int i = 0; i < bodies.Count; i++) { AABB3D bounds = bodies[i].MotionBounds; Vector3 min = bounds.GetMin(); Vector3 max = bounds.GetMax(); int startRow = (int)(min.X * invWidth * rows); startRow = (int)Math.Max(startRow, 0); int startCol = (int)(min.Y * invHeight * cols); startCol = (int)Math.Max(startCol, 0); int startStack = (int)(min.Z * invDepth * stacks); startStack = (int)Math.Max(startStack, 0); int endRow = (int)(max.X * invWidth * rows); endRow = (int)Math.Min(endRow, rows - 1); int endCol = (int)(max.Y * invHeight * cols); endCol = (int)Math.Min(endCol, cols - 1); int endStack = (int)(max.Z * invDepth * stacks); endStack = (int)Math.Min(endStack, stacks - 1); for (int j = startRow; j <= endRow; j++) { for (int k = startCol; k <= endCol; k++) { for (int l = startStack; l <= endStack; l++) { cells[(j * cols) + (k * rows) + l].AddObject(i); } } } } //Loop through each cell, add speculative contacts to each object in the cell for (int i = 0; i < cells.Length; i++) { if (cells[i].Indices.Count <= 0) { continue; } Cell3D currentCell = cells[i]; foreach (int index1 in currentCell.Indices) { foreach (int index2 in currentCell.Indices) { if (index1 == index2) { continue; } RigidBody3D a = bodies[index1]; RigidBody3D b = bodies[index2]; if (a.InvMass != 0 || b.InvMass != 0) { //Add a speculative contact contacts.Add(a.GenerateContact(b, dt)); } } } } }