BakedPointCloud ImportAsBakedPointCloud(string path) { VoxReader voxReader = new VoxReader(); VoxModel model = voxReader.LoadModel(path); if (model == null) { return(null); } List <Vector3> positions = new List <Vector3>(); List <Color> colors = new List <Color>(); var colorsPalette = model.Palette; for (int i = 0; i < model.VoxelFrames.Count; i++) { VoxelData data = model.VoxelFrames[i]; FileToVoxCore.Schematics.Tools.Vector3 worldPositionFrame = model.TransformNodeChunks[i + 1].TranslationAt(); if (worldPositionFrame == FileToVoxCore.Schematics.Tools.Vector3.zero) { continue; } for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int indexColor = data.Get(x, y, z); var color = colorsPalette[indexColor]; if (color != FileToVoxCore.Drawing.Color.Empty) { positions.Add(new Vector3(z + worldPositionFrame.X, y + worldPositionFrame.Z, x + worldPositionFrame.Y)); colors.Add(color.ToUnityColor()); } } } } } BakedPointCloud bakedPointCloud = ScriptableObject.CreateInstance <BakedPointCloud>(); bakedPointCloud.Initialize(positions, colors); bakedPointCloud.name = Path.GetFileNameWithoutExtension(path); return(bakedPointCloud); }
public override Schematic WriteSchematic() { Schematic schematic = new Schematic(); FileToVoxCore.Drawing.Color[] colorsPalette = mVoxModel.Palette; using (ProgressBar progressbar = new ProgressBar()) { int minX = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().X).TranslationAt().X; int minY = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Y).TranslationAt().Y; int minZ = (int)mVoxModel.TransformNodeChunks.MinBy(t => t.TranslationAt().Z).TranslationAt().Z; for (int i = 0; i < mVoxModel.VoxelFrames.Count; i++) { VoxelData data = mVoxModel.VoxelFrames[i]; Vector3 worldPositionFrame = mVoxModel.TransformNodeChunks[i + 1].TranslationAt(); if (worldPositionFrame == Vector3.zero) { continue; } for (int y = 0; y < data.VoxelsTall; y++) { for (int z = 0; z < data.VoxelsDeep; z++) { for (int x = 0; x < data.VoxelsWide; x++) { int indexColor = data.Get(x, y, z); FileToVoxCore.Drawing.Color color = colorsPalette[indexColor]; if (color != FileToVoxCore.Drawing.Color.Empty) { schematic.AddVoxel((int)(z + worldPositionFrame.X - minX), (int)(y + (worldPositionFrame.Z - minZ)), (int)(x + worldPositionFrame.Y - minY), color.ColorToUInt()); } } } } progressbar.Report(i / (float)mVoxModel.VoxelFrames.Count); } } return(schematic); }