private void toShadow(VectorInt3 position, VoxelHandler handler, bool spot = false) { VoxelShadowHandler vsh = null; bool glost = (handler.position.z != 0); position.z = 0; if (real_.ContainsKey(position)) { vsh = real_ [position]; } else { vsh = new VoxelShadowHandler(); vsh._position = position; vsh._realSpot = false; vsh._ghostSpot = false; real_ [position] = vsh; } if (!glost) { vsh._realSpot = vsh._realSpot || spot; vsh._ghostSpot = vsh._ghostSpot || spot; } else { vsh._ghostSpot = vsh._ghostSpot || spot; } }
public void build(VoxelProduct product) { product.min = new Vector3(999, 999, 999); product.max = new Vector3(-999, -999, -999); product.main.voxels = new Dictionary <VectorInt3, VoxelHandler>(); // Debug.Log (product.main.voxels.Count); for (int i = 0; i < data_.Length; ++i) { VoxelData d = data_ [i]; var min = product.min; var max = product.max; min.x = Mathf.Min(min.x, d.pos.x); min.y = Mathf.Min(min.y, d.pos.y); min.z = Mathf.Min(min.z, d.pos.z); max.x = Mathf.Max(max.x, d.pos.x); max.y = Mathf.Max(max.y, d.pos.y); max.z = Mathf.Max(max.z, d.pos.z); product.min = min; product.max = max; } for (int i = 0; i < data_.Length; ++i) { VoxelHandler handler = data2Handler(data_[i]); product.main.voxels.Add(handler.position, handler); } }
public void build(VoxelProduct product) { product.min = new Vector3(999, 999, 999); product.max = new Vector3(-999, -999, -999); product.voxels = new Dictionary <VectorInt3, VoxelHandler>(); // Debug.Log (product.voxels.Count); for (int i = 0; i < data_.Length; ++i) { VoxelData d = data_ [i]; product.min.x = Mathf.Min(product.min.x, d.pos.x); product.min.y = Mathf.Min(product.min.y, d.pos.y); product.min.z = Mathf.Min(product.min.z, d.pos.z); product.max.x = Mathf.Max(product.max.x, d.pos.x); product.max.y = Mathf.Max(product.max.y, d.pos.y); product.max.z = Mathf.Max(product.max.z, d.pos.z); } for (int i = 0; i < data_.Length; ++i) { VoxelHandler handler = data2Handler(data_[i]); if (product.voxels.ContainsKey(handler.position)) { Debug.Log(data_.Length); Debug.Log(handler.position.x + ":" + handler.position.y + ":" + handler.position.z); } product.voxels.Add(handler.position, handler); } }
public override void build (VoxelMesh mesh, VoxelHandler handler) { VoxelEmitter emitter = (VoxelEmitter)GameObject.Instantiate (_emitter); emitter.transform.parent = mesh.transform; emitter.transform.position = new Vector3 (handler.position.x, handler.position.y, handler.position.z);//position; //emitter.transform.eulerAngles =c.transform.eulerAngles; emitter.gameObject.SetActive (true); //emitter.transform = c.transform.rotation; }
public override void build(VoxelMesh mesh, VoxelHandler handler) { VoxelEmitter emitter = (VoxelEmitter)GameObject.Instantiate(_emitter); emitter.transform.parent = mesh.transform; emitter.transform.position = new Vector3(handler.position.x, handler.position.y, handler.position.z); //position; //emitter.transform.eulerAngles =c.transform.eulerAngles; emitter.gameObject.SetActive(true); //emitter.transform = c.transform.rotation; }
private VoxelHandler data2Handler(VoxelData data) { VoxelHandler handler = new VoxelHandler(); handler.position = new VectorInt3(data.pos.x, data.pos.y, data.pos.z); handler.color = data.color; handler.id = data.id; return(handler); }
private void createVoxel(VoxelHandler handler) { Voxel_ vox = (Voxel_)GameObject.Instantiate(_prototype); vox.transform.SetParent(_root.transform); vox.transform.localRotation = Quaternion.LookRotation(Vector3.up); handler.setup(vox); }
private void shadowTest(VoxelHandler handler, VectorInt3 shadow, VectorInt3 light, byte index, Vector3 face) { if (voxels.ContainsKey(handler.position + shadow)) { handler.shadowAdd(index, face); } else if (!voxels.ContainsKey(handler.position + light)) { handler.lightAdd(index, face); } }
private VoxelHandler data2Handler (VoxelData data) { VoxelHandler handler = new VoxelHandler(); handler.position = new VectorInt3(data.pos.x, data.pos.y, data.pos.z); handler.color = data.color; handler.id = data.id; return handler; }
public void build(VoxelData[] datas) { if (empty) { createHandler(datas); if (_root != null) { for (int i = 0; i < _datas.Length; ++i) { VoxelHandler d = _datas[i]; this.createVoxel(_datas[i]); } } this.shadowBuild(); this.buildMesh(); } }
public void doPowder(Color[] colors, Powder powder, VectorInt3 min, VectorInt3 max) { VectorInt3 mi = min + this._offset; //VectorInt3 mx = max + this._offset; foreach (VoxelFace.Rect r in powder.rect) { for (int x = r.min.x; x < r.max.x; ++x) { for (int y = r.min.y; y < r.max.y; ++y) { for (int z = r.min.z; z < r.max.z; ++z) { VoxelHandler handler = _mesh.getVoxel(new VectorInt3(x, y, z) + mi); // Debug.Log ("x" + x + "y" +y +"z" + z); if (handler != null) { foreach (VectorInt4 vertice in handler.vertices) { colors[vertice.x] = r.color; colors[vertice.y] = r.color; colors[vertice.z] = r.color; colors[vertice.w] = r.color; } } } } } } foreach (VoxelFace.Point p in powder.point) { VoxelHandler handler = _mesh.getVoxel(p.position + mi); if (handler != null) { foreach (VectorInt4 vertice in handler.vertices) { colors[vertice.x] = p.color; colors[vertice.y] = p.color; colors[vertice.z] = p.color; colors[vertice.w] = p.color; } } } }
private void build(int from, int to, Dictionary <VectorInt3, VoxelHandler> voxs) { // Debug.Log ("from:" + from + ", to" + to); List <VectorInt3> keys = new List <VectorInt3> (voxs.Keys); for (int i = from; i < to; ++i) { VectorInt3 key = keys [i]; VoxelHandler value = voxs [key]; if (!voxs.ContainsKey(key + new VectorInt3(0, -1, 0))) { addRect(Vector3.back, key, value.color); } if (!voxs.ContainsKey(key + new VectorInt3(0, 1, 0))) { addRect(Vector3.forward, key, value.color); } if (!voxs.ContainsKey(key + new VectorInt3(0, 0, 1))) { addRect(Vector3.up, key, value.color); } if (!voxs.ContainsKey(key + new VectorInt3(0, 0, -1))) { addRect(Vector3.down, key, value.color); } if (!voxs.ContainsKey(key + new VectorInt3(1, 0, 0))) { addRect(Vector3.left, key, value.color); } if (!voxs.ContainsKey(key + new VectorInt3(-1, 0, 0))) { addRect(Vector3.right, key, value.color); } } }
private void build(VoxelProduct.Product main, int from, int to, Dictionary <Vector3Int, VoxelHandler> voxs, Dictionary <Vector3Int, VoxelHandler> all) { List <Vector3Int> keys = new List <Vector3Int> (voxs.Keys); for (int i = from; i < to; ++i) { Vector3Int key = keys [i]; VoxelHandler value = voxs [key]; if (!all.ContainsKey(key + new Vector3Int(0, 0, -1))) { addRect(main, Vector3.back, key, value.color); } if (!all.ContainsKey(key + new Vector3Int(0, 0, 1))) { addRect(main, Vector3.forward, key, value.color); } if (!all.ContainsKey(key + new Vector3Int(0, 1, 0))) { addRect(main, Vector3.up, key, value.color); } if (!all.ContainsKey(key + new Vector3Int(0, -1, 0))) { addRect(main, Vector3.down, key, value.color); } if (!all.ContainsKey(key + new Vector3Int(1, 0, 0))) { addRect(main, Vector3.left, key, value.color); } if (!all.ContainsKey(key + new Vector3Int(-1, 0, 0))) { addRect(main, Vector3.right, key, value.color); } } }
private VoxelHandler data2Handler(VoxelData data) { VoxelHandler handler = new VoxelHandler(); VectorInt3 position; if (_XReverse) { position.x = (int)this.max_.x - data.pos.x + (int)this.min_.x; } else { position.x = data.pos.x; } if (_ZReverse) { position.y = (int)this.max_.y - data.pos.y + (int)this.min_.y; } else { position.y = data.pos.y; } if (_YReverse) { position.z = (int)this.max_.z - data.pos.z + (int)this.min_.z; } else { position.z = data.pos.z; } handler.position = position; handler.color = data.color; handler.id = data.id; return(handler); }
public void change(int index) { Debug.Log(index); VoxelModel model = _model [index]; VoxelData[] datas = model.data; Color[] colors = _voxelMesh._mesh.mesh.colors; Debug.LogWarning("datas" + datas); for (int i = 0; i < datas.Length; ++i) { VoxelHandler handler = _voxelMesh.getVoxel(new VectorInt3(datas[i].pos.x, datas[i].pos.y, datas[i].pos.z)); if (handler != null) { foreach (VectorInt4 vertice in handler.vertices) { colors[vertice.x] = datas[i].color; colors[vertice.y] = datas[i].color; colors[vertice.z] = datas[i].color; colors[vertice.w] = datas[i].color; } } } _voxelMesh._mesh.mesh.colors = colors; }
public virtual void build (VoxelMesh mesh, VoxelHandler handler) { }
public void buildMesh() { VoxelDrawMesh draw = new VoxelDrawMesh(); Dictionary <VectorInt3, VoxelHandler> voxs = this.voxels; foreach (KeyValuePair <VectorInt3, VoxelHandler> kv in voxs) { if (!voxs.ContainsKey(kv.Key + new VectorInt3(0, -1, 0))) { VectorInt4 v = draw.addRect(Vector3.back, kv.Key, VoxelHandler.GetUV(kv.Value.back), VoxelHandler.GetUV(kv.Value.lback), kv.Value.color); kv.Value.vertices.Add(v); } if (!voxs.ContainsKey(kv.Key + new VectorInt3(0, 1, 0))) { VectorInt4 v = draw.addRect(Vector3.forward, kv.Key, VoxelHandler.GetUV(kv.Value.front), VoxelHandler.GetUV(kv.Value.lfront), kv.Value.color); kv.Value.vertices.Add(v); } if (!voxs.ContainsKey(kv.Key + new VectorInt3(0, 0, 1))) { VectorInt4 v = draw.addRect(Vector3.up, kv.Key, VoxelHandler.GetUV(kv.Value.up), VoxelHandler.GetUV(kv.Value.lup), kv.Value.color); kv.Value.vertices.Add(v); } if (!voxs.ContainsKey(kv.Key + new VectorInt3(0, 0, -1))) { VectorInt4 v = draw.addRect(Vector3.down, kv.Key, VoxelHandler.GetUV(kv.Value.down), VoxelHandler.GetUV(kv.Value.ldown), kv.Value.color); kv.Value.vertices.Add(v); } if (!voxs.ContainsKey(kv.Key + new VectorInt3(1, 0, 0))) { VectorInt4 v = draw.addRect(Vector3.left, kv.Key, VoxelHandler.GetUV(kv.Value.left), VoxelHandler.GetUV(kv.Value.lleft), kv.Value.color); kv.Value.vertices.Add(v); } if (!voxs.ContainsKey(kv.Key + new VectorInt3(-1, 0, 0))) { VectorInt4 v = draw.addRect(Vector3.right, kv.Key, VoxelHandler.GetUV(kv.Value.right), VoxelHandler.GetUV(kv.Value.lright), kv.Value.color); kv.Value.vertices.Add(v); } } //Resources. _mesh = draw.crateMeshFilter("VoxelMesh", _material); if (_offset != null) { _mesh.gameObject.transform.SetParent(this._offset.transform); } else { _mesh.gameObject.transform.SetParent(this.transform); } _mesh.gameObject.transform.localPosition = Vector3.zero; _mesh.gameObject.transform.localScale = Vector3.one; _mesh.gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero); _mesh.gameObject.SetActive(true); Renderer renderer = _mesh.GetComponent <Renderer> (); renderer.material = this._material; showMesh(); }
private void shadowTest(VoxelHandler handler, VectorInt3 shadow, VectorInt3 light, byte index, Vector3 face) { if (voxels.ContainsKey (handler.position + shadow)) { handler.shadowAdd (index, face); } else if (!voxels.ContainsKey (handler.position + light)) { handler.lightAdd (index, face); } }
private VoxelHandler data2Handler(VoxelData data) { VoxelHandler handler = new VoxelHandler(); VectorInt3 position; if (_XReverse) { position.x = (int)this.max_.x - data.x + (int)this.min_.x; } else { position.x = data.x; } if (_YReverse) { position.y = (int)this.max_.y - data.y + (int)this.min_.y; } else { position.y = data.y; } if (_ZReverse) { position.z = (int)this.max_.z - data.z + (int)this.min_.z; } else { position.z = data.z; } handler.position = position; handler.color = data.color; handler.id = data.id; return handler; }
private void createVoxel(VoxelHandler handler) { //VoxelHandler handler = new VoxelHandler (); Voxel vox = (Voxel)GameObject.Instantiate (_prototype); vox.transform.SetParent (_root.transform); vox.transform.localRotation = Quaternion.LookRotation(Vector3.up); handler.setup (vox); /* var voxs = this.voxels; if (voxs.ContainsKey(handler.position)) { voxs.Remove(handler.position); } voxs.Add (handler.position, handler); */ }
private void toShadow(VectorInt3 position, VoxelHandler handler, bool spot = false){ VoxelShadowHandler vsh = null; bool glost = (handler.position.z != 0); position.z = 0; if (real_.ContainsKey (position)) { vsh = real_ [position]; } else { vsh = new VoxelShadowHandler (); vsh._position = position; vsh._realSpot = false; vsh._ghostSpot = false; real_ [position] = vsh; } if (!glost) { vsh._realSpot = vsh._realSpot || spot; vsh._ghostSpot = vsh._ghostSpot || spot; } else { vsh._ghostSpot = vsh._ghostSpot || spot; } }
public virtual void build(VoxelMesh mesh, VoxelHandler handler) { }