public GeneratedVoxelModel( Texture3D modelData, Vector2 origin, SymmetryOutcome symmetryOutcome, ColorOutcome colorOutcome) { this.modelData = modelData; this.origin = origin; this.symmetryOutcome = symmetryOutcome; this.colorOutcome = colorOutcome; }
public ColorOutcome Recolor( ref Texture2D tex, int frame, ColorConfig colorConfig, BackgroundColorConfig backgroundColorConfig, OutlineConfig outlineConfig, ColorOutcome colorOutcome) { if (colorOutcome == ColorOutcome.None || colorOutcome == null) { colorOutcome = new ColorOutcome(); if (frame == 0) { colorOutcome.generatedColors = cachedGeneratedColors = GenerateColors(colorConfig, backgroundColorConfig); } else { colorOutcome.generatedColors = cachedGeneratedColors; } colorOutcome.backgroundColor = SetBackgroundColor(); colorOutcome.outlineColor = OutlineColor(outlineConfig, frame, colorOutcome.generatedColors); } var colors = tex.GetPixels(); var increment = 1f / colorConfig.colorCountPerSprite; var newColors = new Color[colors.Length]; for (var index = 0; index < colors.Length; index++) { var gray = colors[index].grayscale; for (var i = 0; i < colorConfig.colorCountPerSprite; i++) { if (gray >= i * increment && gray <= (i + 1) * increment) { newColors[index] = colorOutcome.generatedColors[i]; } } } tex.SetPixels(newColors); return(colorOutcome); Color SetBackgroundColor() { if (!cam) { cam = Camera.main; } var backgroundColor = BackgroundColor(backgroundColorConfig, colorConfig, frame, colorOutcome.generatedColors); cam.backgroundColor = backgroundColor; return(backgroundColor); } }
public ColorOutcome Recolor( ref GeneratedVoxelModel generatedVoxel, ColorConfig configurationColorConfig, BackgroundColorConfig configurationBackgroundColorConfig, OutlineConfig configurationOutlineConfig) { // generate the colors to use for the model var colorOutcome = new ColorOutcome(); colorOutcome.generatedColors = GenerateColors(configurationColorConfig); // get the current (grayscale) colors of the model var colors = generatedVoxel.modelData.GetPixels(); // determine how many different colors we will have in the final model var increment = 1f / configurationColorConfig.colorCountPerSprite; // create a new list to hold the new colors for the voxels var newColors = new Color[colors.Length]; // loop through each grayscale color and re-assign it to the new color according to the grayscale range for (var index = 0; index < colors.Length; index++) { var color = colors[index]; var gray = color.grayscale; for (var i = 0; i < configurationColorConfig.colorCountPerSprite; i++) { if (gray >= i * increment && gray <= (i + 1) * increment) { newColors[index] = colorOutcome.generatedColors[i]; } } } // set the values generatedVoxel.modelData.SetPixels(newColors); generatedVoxel.modelData.Apply(); return(colorOutcome); }
public GeneratedTexture(Texture2D texture, Texture2D normal, Vector2 origin, SymmetryOutcome symmetryOutcome, ColorOutcome colorOutcome) { this.texture = texture; this.normal = normal; this.origin = origin; this.symmetryOutcome = symmetryOutcome; this.colorOutcome = colorOutcome; }