public void ApplyColorSpace(Color[, ,] colorMap, Vector3 origin, Vector3 voxelDimensions) { for (int i = 0; i < particle_count; i++) { Vector3 particlePos = particles[i].position; if (particlePos.x < origin.x || particlePos.y < origin.y || particlePos.z < origin.z) { continue; } int ind_x = Mathf.RoundToInt((particlePos.x - origin.x) / voxelDimensions.x); int ind_y = Mathf.RoundToInt((particlePos.y - origin.y) / voxelDimensions.y); int ind_z = Mathf.RoundToInt((particlePos.z - origin.z) / voxelDimensions.z); if (ind_x >= colorMap.GetLength(0) || ind_y >= colorMap.GetLength(1) || ind_z >= colorMap.GetLength(2)) { continue; } particles[i].startColor = colorMap[ind_x, ind_y, ind_z]; } OnParticlesUpdated(); }
public void SaveCSV(Color[,,] voxArray, int seqID, int sculptureID) { string voxCSV = ""; for (int x = 0; x < voxArray.GetLength(0); x++) { for (int z = 0; z < voxArray.GetLength(1); z++) { for (int y = 0; y < voxArray.GetLength(2); y++) { voxCSV += x + ", " + z + ", " + y + ", "; voxCSV += voxArray[x, z, y].r.ToString() + ", "; voxCSV += voxArray[x, z, y].g.ToString() + ", "; voxCSV += voxArray[x, z, y].b.ToString() + ", "; voxCSV += voxArray[x, z, y].a.ToString() + "\n"; } } } byte[] bytes = Encoding.UTF8.GetBytes(voxCSV); if (!Directory.Exists(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter)) { Directory.CreateDirectory(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter); } File.WriteAllBytes(Application.dataPath + "/../Subject-" + testerID + "/" + generatedSculpturesCounter + "/sculpture_" + sculptureID + "_" + ".csv", bytes); }
/// <summary> /// Apply a spatial color mapping to the points in the point cloud. /// </summary> /// <param name="colorMap">The dense, voxel-based defining the colors distribution of the space.</param> public void ApplyColorSpace(Color[, ,] colorMap, Vector3 origin, Vector3 voxelDimensions) { for (int i = 0; i < particle_count; i++) { Vector3 particlePos = particles[i].position; // Check that the point is within the voxel space's bounds. if (particlePos.x < origin.x || particlePos.y < origin.y || particlePos.z < origin.z) { continue; } // Find the indices of the voxel that the point belongs in. int ind_x = Mathf.RoundToInt((particlePos.x - origin.x) / voxelDimensions.x); int ind_y = Mathf.RoundToInt((particlePos.y - origin.y) / voxelDimensions.y); int ind_z = Mathf.RoundToInt((particlePos.z - origin.z) / voxelDimensions.z); if (ind_x >= colorMap.GetLength(0) || ind_y >= colorMap.GetLength(1) || ind_z >= colorMap.GetLength(2)) { continue; } particles[i].startColor = colorMap[ind_x, ind_y, ind_z]; } // Trigger a particle system update. OnParticlesUpdated(); }
internal void Init() { for (int z = 0; z < block.GetLength(0); z++) { for (int x = 0; x < block.GetLength(1); x++) { for (int y = 0; y < block.GetLength(2); y++) { block[z, x, y] = Settings.Colors[z]; } } } }
private void GenerateTexture() { if (_data == null) { throw new ArgumentNullException(); } int width = _data.GetLength(0); int length = _data.GetLength(1); int height = _data.GetLength(2); if (width != length || width != height || length != height) { throw new ArgumentOutOfRangeException(); } int size = width; if (_texture != null) { Texture2D.DestroyImmediate(_texture); } _texture = new Texture2D(size * size, size, TextureFormat.ARGB32, false); var textureData = new Color[size * size * size]; for (int w = 0; w < size; w++) { for (int l = 0; l < size; l++) { for (int h = 0; h < size; h++) { int index = w + h * size + l * size * size; textureData[index] = _data[w, l, h]; } } } _texture.SetPixels(textureData); }
public static Texture3D GenerateSeedPositionTexture3DFromArray(Color[,,] array) { var tex = new Texture3D(array.GetLength(0), array.GetLength(1), array.GetLength(2), TextureFormat.ARGB32, false) { wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Point }; for (int x = 0; x < array.GetLength(0); x++) { for (int y = 0; y < array.GetLength(1); y++) { for (int z = 0; z < array.GetLength(2); z++) { tex.SetPixel(x, y, z, array[x, y, z]); } } } tex.Apply(); return(tex); }