Voxel editing#1024
Draft
andybak wants to merge 9 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a runtime VOX pipeline for Open Brush: in-memory VOX import/export, a mutable runtime voxel document, reusable mesh generation, and HTTP/Lua APIs to generate/edit/spawn/export VOX content, with persistence into .tilt saves.
Changes:
- Added core runtime VOX types:
RuntimeVoxDocument,VoxMeshBuilder,VoxWriter, and per-callVoxImportOptions, plus expandedVoxImporteringestion options. - Added runtime VOX HTTP commands and Lua wrappers (plus example scripts/pages) to create/edit/palette/spawn/export documents.
- Integrated runtime VOX state into save/load (
metadata.jsonindex + embeddedvox/*.voxsubfiles) and added editor tests.
Reviewed changes
Copilot reviewed 20 out of 32 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| VOX_RUNTIME_API_HANDOVER.md | Implementation handover/plan and status tracker for VOX runtime editing initiative. |
| Assets/Scripts/VoxSerialization/VoxWriter.cs.meta | Unity meta for new VOX writer script. |
| Assets/Scripts/VoxSerialization/VoxWriter.cs | Deterministic VOX v150 writer (chunks + basic scene graph for multi-model). |
| Assets/Scripts/VoxSerialization.meta | Unity folder meta for VOX serialization folder. |
| Assets/Scripts/VoxMeshBuilder.cs.meta | Unity meta for new mesh builder script. |
| Assets/Scripts/VoxMeshBuilder.cs | Extracted reusable greedy/cubes voxel meshing for both file models and runtime models. |
| Assets/Scripts/VoxImportOptions.cs.meta | Unity meta for new import options script. |
| Assets/Scripts/VoxImportOptions.cs | Per-call import/build options (mesh mode/material/collider/root name). |
| Assets/Scripts/VoxImporter.cs | Stream/bytes ingestion, per-call options, and delegation to VoxMeshBuilder. |
| Assets/Scripts/SketchControlsScript.cs | Clears runtime VOX state on “New Sketch”. |
| Assets/Scripts/Save/SketchSnapshot.cs | Embeds runtime VOX subfiles into .tilt and writes VOX index into metadata. |
| Assets/Scripts/Save/SketchMetadata.cs | Adds RuntimeVoxState + RuntimeVoxIndex metadata field. |
| Assets/Scripts/Save/SaveLoadScript.cs | Restores runtime VOX docs from .tilt metadata/subfiles during load. |
| Assets/Scripts/RuntimeVoxDocument.cs.meta | Unity meta for new runtime document script. |
| Assets/Scripts/RuntimeVoxDocument.cs | Mutable runtime voxel document (models, voxels, palette, conversions, export bytes). |
| Assets/Scripts/API/Lua/Wrappers/VoxApiWrapper.cs.meta | Unity meta for new VOX Lua wrapper. |
| Assets/Scripts/API/Lua/Wrappers/VoxApiWrapper.cs | Lua API for runtime VOX docs/models (edit/palette/spawn/export). |
| Assets/Scripts/API/Lua/LuaManager.cs | Registers Vox Lua API class. |
| Assets/Scripts/API/ApiMethods.Vox.cs.meta | Unity meta for new VOX HTTP API methods. |
| Assets/Scripts/API/ApiMethods.Vox.cs | HTTP command endpoints for runtime VOX doc/model editing, spawn, export/import, persistence glue. |
| Assets/Resources/ScriptExamples/vox_runtime_api.html.meta | Unity meta for VOX HTTP example page. |
| Assets/Resources/ScriptExamples/vox_runtime_api.html | Interactive HTTP playground for runtime VOX commands. |
| Assets/Resources/LuaScriptExamples/ToolScript.VoxPainter.lua.meta | Unity meta for VOX painter tool script. |
| Assets/Resources/LuaScriptExamples/ToolScript.VoxPainter.lua | Interactive voxel painting Lua tool using runtime VOX APIs. |
| Assets/Resources/LuaScriptExamples/BackgroundScript.VoxRuntimeDemo.lua.meta | Unity meta for VOX demo background script. |
| Assets/Resources/LuaScriptExamples/BackgroundScript.VoxRuntimeDemo.lua | Demo Lua script for runtime VOX create/edit/spawn/export. |
| Assets/Editor/Tests/TestVoxMeshBuilder.cs.meta | Unity meta for VOX mesh builder tests. |
| Assets/Editor/Tests/TestVoxMeshBuilder.cs | Editor tests for greedy vs cube meshing on in-memory VOX fixtures. |
| Assets/Editor/Tests/TestVoxImportOptions.cs.meta | Unity meta for VOX import options tests. |
| Assets/Editor/Tests/TestVoxImportOptions.cs | Editor tests verifying VoxImportOptions defaults/overrides. |
| Assets/Editor/Tests/TestRuntimeVoxDocument.cs.meta | Unity meta for runtime VOX document tests. |
| Assets/Editor/Tests/TestRuntimeVoxDocument.cs | Editor tests for runtime voxel CRUD, mesh build, and VOX byte roundtrips. |
Files not reviewed (12)
- Assets/Editor/Tests/TestRuntimeVoxDocument.cs.meta: Language not supported
- Assets/Editor/Tests/TestVoxImportOptions.cs.meta: Language not supported
- Assets/Editor/Tests/TestVoxMeshBuilder.cs.meta: Language not supported
- Assets/Resources/LuaScriptExamples/BackgroundScript.VoxRuntimeDemo.lua.meta: Language not supported
- Assets/Resources/LuaScriptExamples/ToolScript.VoxPainter.lua.meta: Language not supported
- Assets/Resources/ScriptExamples/vox_runtime_api.html.meta: Language not supported
- Assets/Scripts/API/ApiMethods.Vox.cs.meta: Language not supported
- Assets/Scripts/API/Lua/Wrappers/VoxApiWrapper.cs.meta: Language not supported
- Assets/Scripts/RuntimeVoxDocument.cs.meta: Language not supported
- Assets/Scripts/VoxImportOptions.cs.meta: Language not supported
- Assets/Scripts/VoxMeshBuilder.cs.meta: Language not supported
- Assets/Scripts/VoxSerialization.meta: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+549
to
+560
| Vector3Int offset = new Vector3Int(minX, minY, minZ); | ||
| m_size = new Vector3Int( | ||
| maxX - minX + 1, | ||
| maxY - minY + 1, | ||
| maxZ - minZ + 1 | ||
| ); | ||
|
|
||
| foreach (RuntimeVoxDocument.RuntimeVoxel voxel in model.EnumerateVoxels(palette)) | ||
| { | ||
| Vector3Int normalized = voxel.Position - offset; | ||
| m_voxels[normalized] = voxel.Color; | ||
| } |
Comment on lines
+803
to
+806
| if (previousRoot != null) | ||
| { | ||
| UnityEngine.Object.Destroy(previousRoot); | ||
| } |
Comment on lines
+411
to
+426
| foreach (VoxSceneState state in s_voxSceneByDocument.Values) | ||
| { | ||
| if (state.Root != null) | ||
| { | ||
| UnityEngine.Object.Destroy(state.Root); | ||
| } | ||
| } | ||
| s_voxSceneByDocument.Clear(); | ||
|
|
||
| foreach (GameObject root in s_spawnedVoxRoots) | ||
| { | ||
| if (root != null) | ||
| { | ||
| UnityEngine.Object.Destroy(root); | ||
| } | ||
| } |
Comment on lines
+330
to
+333
| for (int i = m_SceneRoot.transform.childCount - 1; i >= 0; i--) | ||
| { | ||
| UnityEngine.Object.Destroy(m_SceneRoot.transform.GetChild(i).gameObject); | ||
| } |
Comment on lines
+289
to
+294
| { | ||
| if (m_SceneRoot != null) | ||
| { | ||
| UnityEngine.Object.Destroy(m_SceneRoot); | ||
| m_SceneRoot = null; | ||
| } |
Comment on lines
+183
to
+187
| translation: new Vector3Int( | ||
| (int)model.TransformOffset.x, | ||
| (int)model.TransformOffset.y, | ||
| (int)model.TransformOffset.z), | ||
| name: model.Name); |
Comment on lines
+56
to
+75
| public void VoxMeshBuilder_BuildsFromRuntimeModel() | ||
| { | ||
| var document = new RuntimeVoxDocument(); | ||
| RuntimeVoxDocument.RuntimeModel model = document.CreateModel("mesh", new Vector3Int(4, 4, 4)); | ||
| document.ReplacePaletteEntry(1, new Color32(255, 0, 0, 255)); | ||
|
|
||
| model.AddOrUpdateVoxel(new Vector3Int(0, 0, 0), 1); | ||
| model.AddOrUpdateVoxel(new Vector3Int(1, 0, 0), 1); | ||
|
|
||
| var builder = new VoxMeshBuilder(); | ||
| Mesh optimized = builder.GenerateOptimizedMesh(model, document.Palette); | ||
| Mesh cubes = builder.GenerateSeparateCubesMesh(model, document.Palette); | ||
|
|
||
| Assert.NotNull(optimized); | ||
| Assert.NotNull(cubes); | ||
| Assert.AreEqual(24, optimized.vertexCount); | ||
| Assert.AreEqual(36, optimized.triangles.Length); | ||
| Assert.AreEqual(48, cubes.vertexCount); | ||
| Assert.AreEqual(72, cubes.triangles.Length); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.