CSG in the player: build time baking and runtime editing

未关闭
#64 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp, unity
领域
game-dev

调研方向

Start by tracing ChiselModelManager.UpdateModels and its #if UNITY_EDITOR block, then follow the build-time scene processing and asset lookups described in the issue. Check how paint settings, hotspot layouts, surface parameter identities, and editor-only mesh data are supplied to player builds, including IL2CPP constraints. Done means an unsaved scene builds with all models visible, and runtime brush edits rebuild correctly in a player build with player tests.

由索引模型根据 Issue 内容生成。

描述

enhancement

The CSG only runs in the editor. A build should either bake the models into plain meshes, or keep them editable in the player.

Done when (in 6.6 and Unity 7)

  • Baked: a player built from a scene saved with stale meshes shows them up to date, and contains no Chisel components or code.
  • Runtime: in a player, changing a brush and calling ChiselRuntime.Update() changes its mesh, tested in a player build.

Design

One setting per build, "CSG in the player", off by default:

Setting Code in the player Scenes in the player
Off (baked) No Chisel assemblies or Burst CSG jobs Plain meshes and colliders
On (runtime) Core, components, Burst jobs Chisel components, with meshes up to date at build time
  • The setting should be a build profile sub-asset (BuildProfile.AddComponent) that writes CHISEL_RUNTIME into the profile's scriptingDefines; CI can use BuildPlayerOptions.extraScriptingDefines. Check that a define set in IPreprocessBuildWithReport is too late, so it has to be in place before the build starts.
  • With the setting off the code should go too: core, components and dots.extensions should get "defineConstraints": [ "UNITY_EDITOR || CHISEL_RUNTIME" ] (try || in 6.6 and Unity 7 first). A build preprocess should fail clearly when user code references Chisel without the same constraint.

Build step (both settings)

  • There should be one Bake(Scene), called from IProcessSceneWithReport (6.6) and AssetPostprocessor.OnProcessScene (Unity 7, where the interface is deprecated), like ChiselDrawModesProcessScene, whose debug renderer hiding should move into it.
  • It should build every model.
  • Baked:
    • should strip the Chisel components, partial and selection meshes and debug renderers, leaving MeshFilter, MeshRenderer and MeshCollider
  • Runtime:
    • should keep the components, with the meshes it built
    • should optionally keep partial and selection meshes and debug renderers, for a CSG editor that runs in the player (partial and selection meshes are #if UNITY_EDITOR in ChiselRenderableObjects today, so that code has to compile in a player too)
    • should write the project's materials into a preloaded asset (a player has no ProjectSettings/)
    • should store each model's lightmap UV settings (texels per unit, padding, maximum size), so a player can lay out lightmap UVs as the editor does
  • Check first:
    • whether the processed scene is isolated from the scenes open in the editor.
    • The managers are static, CompactHierarchyManager.Flush builds every dirty tree, and some lookups are global (ChiselPaintManager's FindObjectsByType, the decal hierarchy scan). Each model is its own CSGTree, so the CSG results themselves can't mix.
  • Scene processing:
    • Should be cached by Unity.
    • It can run in a worker process isolated from the editor.
    • If a lightmapped model's rebuilt meshes differ from the ones saved in the scene, its lightmaps no longer fit: warn to rebake the lighting.
    • The callbacks also fire when a scene loads in the editor's Play mode, so we might want to skip this for Play mode.

Runtime (setting on)

  • Updating:
    • add ChiselRuntime.Update(), which the game would call after editing; it should call ChiselNodeHierarchyManager.Update() and UpdateModels()
    • everything should be done when ChiselRuntime.Update() returns: MeshColliders should be baked immediately, not deferred as in the editor (ChiselColliderObjects.DeferBaking off)
    • make UpdateModels work in a player; only the lightmap resolution update (the player would get the settings from the build step) and the editor's saved mesh reuse (it uses AssetDatabase) should stay editor only
    • in Play mode only ChiselRuntime.Update() should update the models: ChiselModelComponent.UpdateModelSettingsLookup() and ChiselModelManager.BuildTheNodesOfNow() should not call UpdateModels() then
  • Noticing changes:
    • ChiselRuntime.Update() should check Transform.hasChanged on the registered nodes to find moved ones
    • edits should go through the Chisel component setters (e.g. ChiselBoxComponent.Max), not their serialized fields; check that every setter marks its component dirty
  • Loading:
    • for now ChiselRuntime.Update() should rebuild every model; properly detecting when sub-meshes should be updated or not (when unchanged) at build time is #106 and can be tackled later
    • the project's materials should come from the asset the build step preloads
  • Limits:
    • we don't support lightmaps at runtime
    • a runtime player would carry Unity.Entities (used only for blobs) and its world bootstrap: replace the blobs or set UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP
  • Not tested: Burst and native containers under IL2CPP, MeshCollider cooking cost.

Order: the build step and baking first, then runtime.

主要语言
C#
星标
135
派生
15
平均合并
25 分钟
30 天内合并 PR
108

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

RadicalCSG/com.chisel 的其他 Issue

查看 RadicalCSG/com.chisel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。