예제 #1
0
        void BuildLayer(VoxBuildLayer layer)
        {
            int3 localPosition;

            for (int i = 0; i < layer.voxes.Count; i++)
            {
                var vox       = layer.voxes[i];
                var position  = layer.positions[i];
                var operation = layer.operations[i];
                //Debug.LogError("Building Vox: " + vox.size + " at position " + position);
                for (localPosition.x = 0; localPosition.x < vox.size.x; localPosition.x++)
                {
                    for (localPosition.y = 0; localPosition.y < vox.size.y; localPosition.y++)
                    {
                        for (localPosition.z = 0; localPosition.z < vox.size.z; localPosition.z++)
                        {
                            int partIndex = VoxelRaycastSystem.GetVoxelArrayIndex(localPosition, vox.size);
                            if (operation == VoxOperation.FlipX)
                            {
                                partIndex = VoxelRaycastSystem.GetVoxelArrayIndex(new int3(vox.size.x - 1 - localPosition.x, localPosition.y, localPosition.z), vox.size);
                            }
                            var newPosition = localPosition + position;
                            int newIndex    = VoxelRaycastSystem.GetVoxelArrayIndex(newPosition, size);
                            if (vox.data[partIndex] != 0)
                            {
                                data[newIndex] = vox.data[partIndex];
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        // need to use vox layers instead, each layer has a list of voxes and positions
        public void Build(VoxBuildLayer bodyLayer, VoxBuildLayer gearLayer, //List<VoxData> voxes, List<int3> positions, List<VoxOperation> operations,
                          int3 newSize)
        {
            if (bodyLayer.voxes.Count == 0)
            {
                Debug.LogError("0 Voxes..Cannot build vox. Remember to have core on item.");
                return;
            }
            //Debug.LogError("Building Vox with: " + voxes.Count + " voxes. Size is: " + newSize);
            var oldData = data.ToArray();
            var oldSize = size;

            // i should also change bytes depending on colours, using a colour lookup or something
            if (colorsR.Length == 0)
            {
                var newPart = bodyLayer.voxes[0];
                InitializeColors(newPart.colorsR.Length);
                for (int i = 0; i < newPart.colorsR.Length; i++)
                {
                    colorsR[i] = newPart.colorsR[i];
                    colorsG[i] = newPart.colorsG[i];
                    colorsB[i] = newPart.colorsB[i];
                }
            }
            // get new size first
            size  = newSize;
            scale = new float3(0.5f, 0.5f, 0.5f);
            //UnityEngine.Debug.LogError("New size is set to: " + size + " from " + oldSize);

            // create new data
            InitializeData();
            int3 localPosition;

            for (localPosition.x = 0; localPosition.x < size.x; localPosition.x++)
            {
                for (localPosition.y = 0; localPosition.y < size.y; localPosition.y++)
                {
                    for (localPosition.z = 0; localPosition.z < size.z; localPosition.z++)
                    {
                        int newIndex = VoxelRaycastSystem.GetVoxelArrayIndex(localPosition, size);
                        data[newIndex] = 0;
                    }
                }
            }

            // first add in old parts
            BuildLayer(bodyLayer);
            BuildLayer(gearLayer);
        }