// Use this for initialization void Start() { int width = 100; int height = 10; int depth = 100; ColoredCubesVolumeData data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width, height, depth)); QuantizedColor green = new QuantizedColor(0, 255, 0, 255); for (int z = 0; z < depth; z++) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { data.SetVoxel(x, y, z, green); } } } ColoredCubesVolume coloredCubesVolume = gameObject.AddComponent <ColoredCubesVolume>(); coloredCubesVolume.data = data; gameObject.AddComponent <ColoredCubesVolumeRenderer>(); }
// Use this for initialization void Start() { // We'll store a reference to the colored cubes volume so we can interact with it later. coloredCubesVolume = gameObject.GetComponent <ColoredCubesVolume>(); if (coloredCubesVolume == null) { Debug.LogError("This 'ClickToDestroy' script should be attached to a game object with a ColoredCubesVolume component"); } }
// Use this for initialization void Start() { mapPosition = transform.position; //get terrain volume = GetComponent <ColoredCubesVolume>(); data = volume.data; fakeVoxelMaterial = Resources.Load("Materials/FakeColoredCubes", typeof(Material)) as Material; diffuseMap = volume.GetComponent <ColoredCubesVolumeRenderer>().material.GetTexture("_DiffuseMap"); }
void Start() { Texture2D image = Resources.Load("Images/OW_TileMap_ORIG") as Texture2D; int width = image.width; int height = 16; int depth = image.height; Region region = new Region(0, 0, 0, width - 1, height - 1, depth - 1); ColoredCubesVolumeData data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(region); ColoredCubesVolume coloredCubesVolume = gameObject.GetComponent <ColoredCubesVolume>(); coloredCubesVolume.data = data; for (int z = 0; z < depth; z++) { for (int x = 0; x < width; x++) { Color color = image.GetPixel(x, z); QuantizedColor qColor = new QuantizedColor( (byte)(color.r * 255), (byte)(color.g * 255), (byte)(color.b * 255), (byte)(color.a * 255)); /*int tileSize = 1; * int tileXOffset = 0; * int tileZOffset = 0; * int tileXPos = (x + tileXOffset) / tileSize; * int tileZPos = (z + tileZOffset) / tileSize;*/ data.SetVoxel(x, 0, z, qColor); //for(int y = height-1; y > 0; y--) { } } } }
IEnumerator CreateMap() { int[,] map = LoadImage(textureLocation); ColoredCubesVolumeData cubesData = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width, maxHeight, depth)); color = new QuantizedColor(255, 255, 255, 255); // coloredCubesVolume = cubesHolder.AddComponent<ColoredCubesVolume>(); // coloredCubesVolume.data = cubesData; // cubesHolder.AddComponent<ColoredCubesVolumeRenderer>(); // cubesHolder.AddComponent <ColoredCubesVolumeCollider>(); for (int z = 0; z < depth; z++) { for (int x = 0; x < width; x++) { for (int y = 0; y < (int)(((float)map[x, z] / 255f) * maxHeight); y++) { //if(map[x,z] > VoxelThresHold){ cubesData.SetVoxel(x, y, z, color); //cubesData.SetVoxel(x, y, z, color); //} } } loadPercentage = (float)z / (float)depth; yield return(null); } Debug.Log("Finish"); cubesData.CommitChanges(); coloredCubesVolume = cubesHolder.AddComponent <ColoredCubesVolume>(); coloredCubesVolume.data = cubesData; cubesHolder.AddComponent <ColoredCubesVolumeRenderer>(); cubesHolder.AddComponent <ColoredCubesVolumeCollider>(); CreateTerrain(); cubesHolder.transform.localScale = new Vector3(3f, 3f, 3f); transform.localScale *= 1f / 3f; }
void Start() { volume = GetComponent <ColoredCubesVolume>(); }
public void setColoredCubes(GameObject coloredCubes) { this.coloredCubes = coloredCubes; this.coloredCubesVolume = coloredCubes.GetComponent <ColoredCubesVolume>(); }
// Use this for initialization void Start() { // We will load our texture from the supplied maze image. If you wish to supply your own image then please // note that in Unity 4 you have to set the 'Read/Write Enabled flag' in the texture import properties. // To do this, find the texture in your project view, go to the import settings in the inspector, change // the 'Texture Type' to 'Advanced' and then check the 'Read/Write Enabled' checkbox. Texture2D mazeImage = Resources.Load("Images/Maze") as Texture2D; // The size of the volume we will generate. Note that our source image cn be considered // to have x and y axes, but we map these to x and z because in Unity3D the y axis is up. int width = mazeImage.width; int height = 32; int depth = mazeImage.height; // Start with some empty volume data and we'll write our maze into this. /// [DoxygenSnippet-CreateEmptyColoredCubesVolumeData] // Create an empty ColoredCubesVolumeData with dimensions width * height * depth ColoredCubesVolumeData data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width - 1, height - 1, depth - 1)); /// [DoxygenSnippet-CreateEmptyColoredCubesVolumeData] //Get the main volume component ColoredCubesVolume coloredCubesVolume = gameObject.GetComponent <ColoredCubesVolume>(); // Attactch the empty data we created previously coloredCubesVolume.data = data; // At this point we have a volume created and can now start writting our maze data into it. // It's best to create these outside of the loop. QuantizedColor red = new QuantizedColor(255, 0, 0, 255); QuantizedColor blue = new QuantizedColor(0, 0, 255, 255); QuantizedColor gray = new QuantizedColor(127, 127, 127, 255); QuantizedColor white = new QuantizedColor(255, 255, 255, 255); // Iterate over every pixel of our maze image. for (int z = 0; z < depth; z++) { for (int x = 0; x < width; x++) { // The exact logic here isn't important for the purpose of the example, but basically we decide which // tile a voxel is part of based on it's position. You can tweak the values to get an dea of what they do. QuantizedColor tileColor; int tileSize = 4; int tileXOffset = 2; int tileZOffset = 2; int tileXPos = (x + tileXOffset) / tileSize; int tileZPos = (z + tileZOffset) / tileSize; if ((tileXPos + tileZPos) % 2 == 1) { tileColor = blue; } else { tileColor = white; } // For each pixel of the maze image determine whether it is a wall or empty space. bool isWall = mazeImage.GetPixel(x, z).r < 0.5; // A black pixel represents a wall // Height of the wall and floor in our maze. int floorHeight = 5; int wallHeight = 20; // Iterate over every voxel in the current column. for (int y = height - 1; y > 0; y--) { // If the current column is a wall then we set every voxel // to gray except for the top one (which we set to red). if (isWall) { if (y < wallHeight) { data.SetVoxel(x, y, z, gray); } else if (y == wallHeight) { data.SetVoxel(x, y, z, red); } } else // Floor is also gray underneath but the top voxel is set to the tile color. { if (y < floorHeight) { data.SetVoxel(x, y, z, gray); } else if (y == floorHeight) { data.SetVoxel(x, y, z, tileColor); } } } } } }
void Awake() { //set appropriate material GetComponent <ColoredCubesVolumeRenderer>().material = Settings.DarkSolidMat; GetComponent <ColoredCubesVolumeRenderer>().material.color = Color.white; //GetComponent<ColoredCubesVolumeRenderer>().material = // (blockType == BlockType.DarkSolid) ? // Settings.DarkSolidMat : // Settings.LightSolidMat; ParticleSystem p; if (blockType == BlockType.DarkSolid) { p = Instantiate(Resources.Load <GameObject>("Prefabs/GameObjects/ShadowBlockPrefabs/DarkSolidParticles")).GetComponent <ParticleSystem>(); } else { p = Instantiate(Resources.Load <GameObject>("Prefabs/GameObjects/ShadowBlockPrefabs/LightSolidParticles")).GetComponent <ParticleSystem>(); } if (p != null) { Vector3 localScale = transform.localScale; transform.localScale = new Vector3(1, 1, 1); p.transform.position = transform.TransformPoint(0.5f * localScale); p.transform.rotation = transform.rotation; transform.localScale = localScale; var shape = p.shape; shape.box = transform.localScale; float v = transform.localScale.x * transform.localScale.y * transform.localScale.z; p.emissionRate = (int)(v / 20); } volume = GetComponent <ColoredCubesVolume>(); updateBlocks = true; pauseFromNoLight = false; init = 0; Vector3 scale = transform.localScale; float scaleX = 1; float scaleY = 1; float scaleZ = 1; WidthX = GetScaledNumBlocks(scale.x, blockSize, out scaleX); WidthY = GetScaledNumBlocks(scale.y, blockSize, out scaleY); WidthZ = GetScaledNumBlocks(scale.z, blockSize, out scaleZ); transform.localScale = new Vector3(scaleX, scaleY, scaleZ); //Debug.Log(widthX + " " + widthY + " " + widthZ); transform.position = new Vector3(transform.position.x + blockSize / 2, transform.position.y + blockSize / 2, transform.position.z + blockSize / 2); int minRegion = 25; int regionX = (int)Mathf.Max(minRegion, WidthX); int regionY = (int)Mathf.Max(minRegion, WidthY); int regionZ = (int)Mathf.Max(minRegion, WidthZ); volume.data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, regionX, regionY, regionZ)); GetComponent <MeshRenderer>().enabled = false; if (blockType == BlockType.DarkSolid) { inDarkColor = new QuantizedColor(0, 200, 0, 255); inLightColor = new QuantizedColor(0, 0, 0, 0); } else { inLightColor = new QuantizedColor(255, 0, 255, 255); inDarkColor = new QuantizedColor(0, 0, 0, 0); } if (printNumBlocks) { Debug.Log(WidthX * WidthY * WidthZ); } layerMask = ~((1 << LayerMask.NameToLayer("Ignored By Voxel Shadows")) | (1 << LayerMask.NameToLayer("Ignore Raycast"))); //GetComponent<VolumeRenderer>().enabled = false; //StartCoroutine("UpdateBlocks"); //updateBlocks = false; //int t = 20; //for (int x = 0; x < t; x++) // for (int y = 0; y < t; y++) // for (int z = 0; z < t; z++) // volume.data.SetVoxel(x, y, z, new QuantizedColor(0, 0, 0, 0)); //t = size; //for (int x = 0; x < t; x++) // for (int y = 0; y < t; y++) // for(int z = 0; z < t; z++) // volume.data.SetVoxel(x, y, z, new QuantizedColor(1, 0, 0, 255)); //volume.data.CommitChanges(); }
// Use this for initialization void Start() { world = gameObject; coloredCubesVolume = gameObject.GetComponent <ColoredCubesVolume>(); }