mesheditor 0.0.0-stage → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +853 -2
- package/dist-lib/esm/AIAgentService.d.ts +106 -0
- package/dist-lib/esm/AIAgentService.js +1471 -0
- package/dist-lib/esm/MeshEditorApp.d.ts +412 -0
- package/dist-lib/esm/MeshEditorApp.js +9092 -0
- package/dist-lib/esm/MeshEditorService.d.ts +459 -0
- package/dist-lib/esm/MeshEditorService.js +7083 -0
- package/dist-lib/esm/Neural3DGeneratorService.d.ts +88 -0
- package/dist-lib/esm/Neural3DGeneratorService.js +1397 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.d.ts +16 -0
- package/dist-lib/esm/adapters/BrowserPlatformAdapter.js +25 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.d.ts +32 -0
- package/dist-lib/esm/adapters/ElectronPlatformAdapter.js +336 -0
- package/dist-lib/esm/adapters/HostAppAdapter.d.ts +54 -0
- package/dist-lib/esm/adapters/HostAppAdapter.js +75 -0
- package/dist-lib/esm/adapters/PlatformAdapter.d.ts +98 -0
- package/dist-lib/esm/adapters/PlatformAdapter.js +1 -0
- package/dist-lib/esm/adapters/index.d.ts +13 -0
- package/dist-lib/esm/adapters/index.js +15 -0
- package/dist-lib/esm/assets/fonts/Droid_Sans_Bold.json +1 -0
- package/dist-lib/esm/assets/fonts/Droid_Sans_Regular.json +1 -0
- package/dist-lib/esm/assets/fonts/Kenney_Future_Regular.json +1 -0
- package/dist-lib/esm/baking/TextureBaker.d.ts +84 -0
- package/dist-lib/esm/baking/TextureBaker.js +709 -0
- package/dist-lib/esm/builtInSkills.d.ts +19 -0
- package/dist-lib/esm/builtInSkills.js +186 -0
- package/dist-lib/esm/compression/ModelCompressor.d.ts +87 -0
- package/dist-lib/esm/compression/ModelCompressor.js +553 -0
- package/dist-lib/esm/decals/DecalController.d.ts +147 -0
- package/dist-lib/esm/decals/DecalController.js +1031 -0
- package/dist-lib/esm/decals/decalAssetUrls.d.ts +1 -0
- package/dist-lib/esm/decals/decalAssetUrls.js +16 -0
- package/dist-lib/esm/geometry/architecture.d.ts +114 -0
- package/dist-lib/esm/geometry/architecture.js +832 -0
- package/dist-lib/esm/geometry/bevelModifier.d.ts +59 -0
- package/dist-lib/esm/geometry/bevelModifier.js +345 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.d.ts +127 -0
- package/dist-lib/esm/geometry/facetSurfaceUtils.js +676 -0
- package/dist-lib/esm/geometry/roundedBox.d.ts +15 -0
- package/dist-lib/esm/geometry/roundedBox.js +133 -0
- package/dist-lib/esm/index.d.ts +21 -0
- package/dist-lib/esm/index.js +50 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.d.ts +59 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionController.js +483 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.d.ts +76 -0
- package/dist-lib/esm/pathExtrusion/PathExtrusionStudio.js +1792 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.d.ts +95 -0
- package/dist-lib/esm/pathExtrusion/PathFactory.js +627 -0
- package/dist-lib/esm/pathExtrusion/index.d.ts +4 -0
- package/dist-lib/esm/pathExtrusion/index.js +4 -0
- package/dist-lib/esm/pathExtrusion/types.d.ts +50 -0
- package/dist-lib/esm/pathExtrusion/types.js +1 -0
- package/dist-lib/esm/plugin.d.ts +250 -0
- package/dist-lib/esm/plugin.js +144 -0
- package/dist-lib/esm/rigging/WeightPaintController.d.ts +162 -0
- package/dist-lib/esm/rigging/WeightPaintController.js +1421 -0
- package/dist-lib/esm/sculpting/SculptController.d.ts +146 -0
- package/dist-lib/esm/sculpting/SculptController.js +2038 -0
- package/dist-lib/esm/sdf/index.d.ts +2 -0
- package/dist-lib/esm/sdf/index.js +2 -0
- package/dist-lib/esm/sdf/sdfPrimitives.d.ts +97 -0
- package/dist-lib/esm/sdf/sdfPrimitives.js +402 -0
- package/dist-lib/esm/sdf/surfaceNets.d.ts +29 -0
- package/dist-lib/esm/sdf/surfaceNets.js +399 -0
- package/dist-lib/esm/styles.d.ts +11 -0
- package/dist-lib/esm/styles.js +32 -0
- package/dist-lib/esm/template.d.ts +12 -0
- package/dist-lib/esm/template.js +19 -0
- package/dist-lib/esm/textMesh/TextMeshController.d.ts +61 -0
- package/dist-lib/esm/textMesh/TextMeshController.js +405 -0
- package/dist-lib/esm/textures/AITextureGenerator.d.ts +119 -0
- package/dist-lib/esm/textures/AITextureGenerator.js +945 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.d.ts +62 -0
- package/dist-lib/esm/textures/ExternalImageGeneratorService.js +879 -0
- package/dist-lib/esm/tools/AbstractTool.d.ts +68 -0
- package/dist-lib/esm/tools/AbstractTool.js +128 -0
- package/dist-lib/esm/tools/ToolExecutionContext.d.ts +40 -0
- package/dist-lib/esm/tools/ToolExecutionContext.js +1 -0
- package/dist-lib/esm/tools/ToolInterface.d.ts +104 -0
- package/dist-lib/esm/tools/ToolInterface.js +1 -0
- package/dist-lib/esm/tools/ToolRegistry.d.ts +43 -0
- package/dist-lib/esm/tools/ToolRegistry.js +115 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/ApplyMaterialTool.js +48 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/AutoUVMappingTool.js +54 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.d.ts +42 -0
- package/dist-lib/esm/tools/builtin/BakeTexturesTool.js +81 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.d.ts +51 -0
- package/dist-lib/esm/tools/builtin/BooleanOperationTool.js +86 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.d.ts +78 -0
- package/dist-lib/esm/tools/builtin/BuildVoxelMeshTool.js +170 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.d.ts +75 -0
- package/dist-lib/esm/tools/builtin/CloneArrayTool.js +115 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.d.ts +118 -0
- package/dist-lib/esm/tools/builtin/CreateArchTool.js +89 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/CreateColumnTool.js +105 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/CreateLatheTool.js +60 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/CreateMaterialTool.js +212 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.d.ts +120 -0
- package/dist-lib/esm/tools/builtin/CreateMoldingTool.js +95 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.d.ts +162 -0
- package/dist-lib/esm/tools/builtin/CreatePrimitiveTool.js +302 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.d.ts +120 -0
- package/dist-lib/esm/tools/builtin/CreateRoofTool.js +108 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.d.ts +101 -0
- package/dist-lib/esm/tools/builtin/CreateRoundedBoxTool.js +79 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.d.ts +224 -0
- package/dist-lib/esm/tools/builtin/CreateSdfMeshTool.js +238 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.d.ts +135 -0
- package/dist-lib/esm/tools/builtin/CreateStairsTool.js +119 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.d.ts +94 -0
- package/dist-lib/esm/tools/builtin/CreateTextMeshTool.js +131 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/CreateTubeTool.js +59 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.d.ts +145 -0
- package/dist-lib/esm/tools/builtin/CreateWallTool.js +124 -0
- package/dist-lib/esm/tools/builtin/DecalTool.d.ts +76 -0
- package/dist-lib/esm/tools/builtin/DecalTool.js +143 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.d.ts +20 -0
- package/dist-lib/esm/tools/builtin/DeleteMeshTool.js +42 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.d.ts +21 -0
- package/dist-lib/esm/tools/builtin/ExecuteBabylonCodeTool.js +96 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.d.ts +114 -0
- package/dist-lib/esm/tools/builtin/ExtrudePolygonTool.js +77 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.d.ts +104 -0
- package/dist-lib/esm/tools/builtin/ExtrudeShapeTool.js +68 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.d.ts +36 -0
- package/dist-lib/esm/tools/builtin/FacetArcTool.js +57 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/FacetCutThroughTool.js +49 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/FacetExtrudeTool.js +49 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.d.ts +34 -0
- package/dist-lib/esm/tools/builtin/FacetInsetTool.js +55 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.d.ts +131 -0
- package/dist-lib/esm/tools/builtin/GenerateNeuralMeshTool.js +455 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/GenerateTextureTool.js +216 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.d.ts +11 -0
- package/dist-lib/esm/tools/builtin/GetSceneInfoTool.js +12 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.d.ts +28 -0
- package/dist-lib/esm/tools/builtin/MergeMeshesTool.js +56 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.d.ts +87 -0
- package/dist-lib/esm/tools/builtin/PlanModelTool.js +155 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.d.ts +50 -0
- package/dist-lib/esm/tools/builtin/RetopologizeMeshTool.js +116 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.d.ts +55 -0
- package/dist-lib/esm/tools/builtin/RigWeightTool.js +139 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.d.ts +138 -0
- package/dist-lib/esm/tools/builtin/SculptMeshTool.js +255 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.d.ts +21 -0
- package/dist-lib/esm/tools/builtin/SeparateMeshTool.js +31 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.d.ts +30 -0
- package/dist-lib/esm/tools/builtin/SolidifyMeshTool.js +57 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.d.ts +66 -0
- package/dist-lib/esm/tools/builtin/SpawnBaseMeshTool.js +105 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.d.ts +23 -0
- package/dist-lib/esm/tools/builtin/SubDSmoothTool.js +37 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.d.ts +23 -0
- package/dist-lib/esm/tools/builtin/SubdivideMeshTool.js +39 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.d.ts +78 -0
- package/dist-lib/esm/tools/builtin/TransformMeshTool.js +69 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.d.ts +48 -0
- package/dist-lib/esm/tools/builtin/UVUnwrapTool.js +107 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.d.ts +60 -0
- package/dist-lib/esm/tools/builtin/VoxelPainterTool.js +153 -0
- package/dist-lib/esm/tools/builtin/index.d.ts +44 -0
- package/dist-lib/esm/tools/builtin/index.js +44 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/AIAgentEditorTool.js +43 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.d.ts +15 -0
- package/dist-lib/esm/tools/editor/AITextureEditorTool.js +28 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.d.ts +29 -0
- package/dist-lib/esm/tools/editor/AbstractEditorTool.js +56 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/AnimationPlayerEditorTool.js +29 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.d.ts +21 -0
- package/dist-lib/esm/tools/editor/BakingEditorTool.js +44 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.d.ts +20 -0
- package/dist-lib/esm/tools/editor/CSGEditorTool.js +42 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.d.ts +20 -0
- package/dist-lib/esm/tools/editor/CompressModelEditorTool.js +48 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/CreatePrimitiveEditorTool.js +36 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/DecalEditorTool.js +36 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.d.ts +23 -0
- package/dist-lib/esm/tools/editor/FacetEditorTool.js +80 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.d.ts +18 -0
- package/dist-lib/esm/tools/editor/MaterialEditorTool.js +43 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/MeshPropertiesEditorTool.js +37 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/OutlinerEditorTool.js +34 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.d.ts +26 -0
- package/dist-lib/esm/tools/editor/PathExtrusionEditorTool.js +72 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/RiggingEditorTool.js +66 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/SceneEnvironmentEditorTool.js +35 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.d.ts +28 -0
- package/dist-lib/esm/tools/editor/SculptEditorTool.js +70 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.d.ts +16 -0
- package/dist-lib/esm/tools/editor/TextMeshEditorTool.js +30 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.d.ts +17 -0
- package/dist-lib/esm/tools/editor/TextureOptimizerEditorTool.js +28 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.d.ts +27 -0
- package/dist-lib/esm/tools/editor/UVUnwrapEditorTool.js +70 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.d.ts +26 -0
- package/dist-lib/esm/tools/editor/VoxelPainterEditorTool.js +68 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.d.ts +30 -0
- package/dist-lib/esm/tools/editor/aiQuickPrompts.js +228 -0
- package/dist-lib/esm/tools/editor/index.d.ts +32 -0
- package/dist-lib/esm/tools/editor/index.js +54 -0
- package/dist-lib/esm/tools/editor/toolViews.d.ts +10 -0
- package/dist-lib/esm/tools/editor/toolViews.js +53 -0
- package/dist-lib/esm/tools/editorTools.d.ts +5 -0
- package/dist-lib/esm/tools/editorTools.js +5 -0
- package/dist-lib/esm/tools/index.d.ts +8 -0
- package/dist-lib/esm/tools/index.js +8 -0
- package/dist-lib/esm/tools/textureUtils.d.ts +18 -0
- package/dist-lib/esm/tools/textureUtils.js +288 -0
- package/dist-lib/esm/types.d.ts +164 -0
- package/dist-lib/esm/types.js +1 -0
- package/dist-lib/esm/uv/UVUnwrapController.d.ts +108 -0
- package/dist-lib/esm/uv/UVUnwrapController.js +1022 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.d.ts +15 -0
- package/dist-lib/esm/voxel/CustomVoxelMesher.js +169 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.d.ts +54 -0
- package/dist-lib/esm/voxel/TextureAtlasManager.js +630 -0
- package/dist-lib/esm/voxel/VoxelPainterController.d.ts +100 -0
- package/dist-lib/esm/voxel/VoxelPainterController.js +671 -0
- package/dist-lib/esm/voxel/index.d.ts +4 -0
- package/dist-lib/esm/voxel/index.js +4 -0
- package/dist-lib/esm/voxel/types.d.ts +78 -0
- package/dist-lib/esm/voxel/types.js +1 -0
- package/dist-lib/esm/web-component/MeshEditorElement.d.ts +103 -0
- package/dist-lib/esm/web-component/MeshEditorElement.js +246 -0
- package/dist-lib/esm/web-component/index.d.ts +1 -0
- package/dist-lib/esm/web-component/index.js +1 -0
- package/dist-lib/index.umd.js +3 -0
- package/dist-lib/mesheditor.css +2 -0
- package/dist-lib/mesheditor.css.map +1 -0
- package/dist-lib/standalone/mesheditor-element.bundle.js +3 -0
- package/package.json +114 -4
- package/skills/README.md +48 -0
- package/skills/figure-sculptor.md +297 -0
- package/skills/image-to-mesh.md +18 -0
- package/skills/mesh-updater.md +27 -0
- package/skills/neural-3d-generator.md +53 -0
- package/skills/procedural-modeler.md +267 -0
- package/skills/voxel-painter.md +21 -0
- package/src/mesheditor.css +6477 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Mesh, Scene } from '@babylonjs/core';
|
|
2
|
+
import { TextureAtlasDefinition, VoxelBlock, VoxelPaletteItem } from './types';
|
|
3
|
+
export interface VoxelMesherOptions {
|
|
4
|
+
voxelSize?: number;
|
|
5
|
+
meshName?: string;
|
|
6
|
+
atlas?: TextureAtlasDefinition;
|
|
7
|
+
}
|
|
8
|
+
export declare class CustomVoxelMesher {
|
|
9
|
+
/**
|
|
10
|
+
* Generates an optimized 3D mesh from a collection of voxel blocks with interior face culling.
|
|
11
|
+
* Internal faces between two solid voxels are not generated.
|
|
12
|
+
* If an atlas is used, UV coordinates are mapped to each block's atlas frame.
|
|
13
|
+
*/
|
|
14
|
+
static build(scene: Scene, blocks: VoxelBlock[], paletteMap: Map<string, VoxelPaletteItem>, options?: VoxelMesherOptions): Mesh | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Color3, Mesh, PBRMaterial, Texture, VertexData, } from '@babylonjs/core';
|
|
2
|
+
export class CustomVoxelMesher {
|
|
3
|
+
/**
|
|
4
|
+
* Generates an optimized 3D mesh from a collection of voxel blocks with interior face culling.
|
|
5
|
+
* Internal faces between two solid voxels are not generated.
|
|
6
|
+
* If an atlas is used, UV coordinates are mapped to each block's atlas frame.
|
|
7
|
+
*/
|
|
8
|
+
static build(scene, blocks, paletteMap, options = {}) {
|
|
9
|
+
if (!blocks || blocks.length === 0)
|
|
10
|
+
return null;
|
|
11
|
+
const voxelSize = options.voxelSize || 1.0;
|
|
12
|
+
const meshName = options.meshName || 'voxel_model';
|
|
13
|
+
const half = voxelSize * 0.5;
|
|
14
|
+
// Fast lookup map for 3D coordinate culling
|
|
15
|
+
const grid = new Map();
|
|
16
|
+
for (const b of blocks) {
|
|
17
|
+
grid.set(`${b.x},${b.y},${b.z}`, b);
|
|
18
|
+
}
|
|
19
|
+
// Group blocks by material / atlas
|
|
20
|
+
const blocksByGroup = new Map();
|
|
21
|
+
for (const b of blocks) {
|
|
22
|
+
const pal = paletteMap.get(b.paletteId);
|
|
23
|
+
const isAtlasTile = !!(pal?.atlasTile && pal?.atlasId);
|
|
24
|
+
const groupKey = isAtlasTile
|
|
25
|
+
? `atlas_${pal.atlasId}`
|
|
26
|
+
: pal?.textureUrl || pal?.texture?.name || b.paletteId;
|
|
27
|
+
let list = blocksByGroup.get(groupKey);
|
|
28
|
+
if (!list) {
|
|
29
|
+
list = [];
|
|
30
|
+
blocksByGroup.set(groupKey, list);
|
|
31
|
+
}
|
|
32
|
+
list.push(b);
|
|
33
|
+
}
|
|
34
|
+
const createdSubMeshes = [];
|
|
35
|
+
// Helper to test if a neighboring voxel is solid
|
|
36
|
+
const isSolid = (x, y, z) => {
|
|
37
|
+
const neighbor = grid.get(`${x},${y},${z}`);
|
|
38
|
+
if (!neighbor)
|
|
39
|
+
return false;
|
|
40
|
+
const neighborPal = paletteMap.get(neighbor.paletteId);
|
|
41
|
+
if (neighborPal?.isLiquid)
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
for (const [groupKey, voxelList] of blocksByGroup.entries()) {
|
|
46
|
+
const positions = [];
|
|
47
|
+
const normals = [];
|
|
48
|
+
const uvs = [];
|
|
49
|
+
const indices = [];
|
|
50
|
+
let vertOffset = 0;
|
|
51
|
+
for (const b of voxelList) {
|
|
52
|
+
const cx = b.x * voxelSize;
|
|
53
|
+
const cy = b.y * voxelSize;
|
|
54
|
+
const cz = b.z * voxelSize;
|
|
55
|
+
const pal = paletteMap.get(b.paletteId);
|
|
56
|
+
const tile = pal?.atlasTile;
|
|
57
|
+
const u0 = tile ? tile.uMin : 0.0;
|
|
58
|
+
const u1 = tile ? tile.uMax : 1.0;
|
|
59
|
+
const v0 = tile ? tile.vMin : 0.0;
|
|
60
|
+
const v1 = tile ? tile.vMax : 1.0;
|
|
61
|
+
// +X Face (Right)
|
|
62
|
+
if (!isSolid(b.x + 1, b.y, b.z)) {
|
|
63
|
+
positions.push(cx + half, cy - half, cz - half, cx + half, cy + half, cz - half, cx + half, cy + half, cz + half, cx + half, cy - half, cz + half);
|
|
64
|
+
normals.push(1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0);
|
|
65
|
+
uvs.push(u0, v0, u0, v1, u1, v1, u1, v0);
|
|
66
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
67
|
+
vertOffset += 4;
|
|
68
|
+
}
|
|
69
|
+
// -X Face (Left)
|
|
70
|
+
if (!isSolid(b.x - 1, b.y, b.z)) {
|
|
71
|
+
positions.push(cx - half, cy - half, cz + half, cx - half, cy + half, cz + half, cx - half, cy + half, cz - half, cx - half, cy - half, cz - half);
|
|
72
|
+
normals.push(-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0);
|
|
73
|
+
uvs.push(u0, v0, u0, v1, u1, v1, u1, v0);
|
|
74
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
75
|
+
vertOffset += 4;
|
|
76
|
+
}
|
|
77
|
+
// +Y Face (Top)
|
|
78
|
+
if (!isSolid(b.x, b.y + 1, b.z)) {
|
|
79
|
+
positions.push(cx - half, cy + half, cz - half, cx - half, cy + half, cz + half, cx + half, cy + half, cz + half, cx + half, cy + half, cz - half);
|
|
80
|
+
normals.push(0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0);
|
|
81
|
+
uvs.push(u0, v0, u0, v1, u1, v1, u1, v0);
|
|
82
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
83
|
+
vertOffset += 4;
|
|
84
|
+
}
|
|
85
|
+
// -Y Face (Bottom)
|
|
86
|
+
if (!isSolid(b.x, b.y - 1, b.z)) {
|
|
87
|
+
positions.push(cx - half, cy - half, cz + half, cx - half, cy - half, cz - half, cx + half, cy - half, cz - half, cx + half, cy - half, cz + half);
|
|
88
|
+
normals.push(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0);
|
|
89
|
+
uvs.push(u0, v0, u0, v1, u1, v1, u1, v0);
|
|
90
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
91
|
+
vertOffset += 4;
|
|
92
|
+
}
|
|
93
|
+
// +Z Face (Front)
|
|
94
|
+
if (!isSolid(b.x, b.y, b.z + 1)) {
|
|
95
|
+
positions.push(cx - half, cy - half, cz + half, cx + half, cy - half, cz + half, cx + half, cy + half, cz + half, cx - half, cy + half, cz + half);
|
|
96
|
+
normals.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
|
|
97
|
+
uvs.push(u0, v0, u1, v0, u1, v1, u0, v1);
|
|
98
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
99
|
+
vertOffset += 4;
|
|
100
|
+
}
|
|
101
|
+
// -Z Face (Back)
|
|
102
|
+
if (!isSolid(b.x, b.y, b.z - 1)) {
|
|
103
|
+
positions.push(cx + half, cy - half, cz - half, cx - half, cy - half, cz - half, cx - half, cy + half, cz - half, cx + half, cy + half, cz - half);
|
|
104
|
+
normals.push(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);
|
|
105
|
+
uvs.push(u0, v0, u1, v0, u1, v1, u0, v1);
|
|
106
|
+
indices.push(vertOffset, vertOffset + 1, vertOffset + 2, vertOffset, vertOffset + 2, vertOffset + 3);
|
|
107
|
+
vertOffset += 4;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (indices.length === 0)
|
|
111
|
+
continue;
|
|
112
|
+
const subMesh = new Mesh(`${meshName}_part_${groupKey}`, scene);
|
|
113
|
+
const vertexData = new VertexData();
|
|
114
|
+
vertexData.positions = positions;
|
|
115
|
+
vertexData.normals = normals;
|
|
116
|
+
vertexData.uvs = uvs;
|
|
117
|
+
vertexData.indices = indices;
|
|
118
|
+
vertexData.applyToMesh(subMesh);
|
|
119
|
+
// Assign Material
|
|
120
|
+
const samplePal = paletteMap.get(voxelList[0].paletteId);
|
|
121
|
+
if (groupKey.startsWith('atlas_') && options.atlas) {
|
|
122
|
+
const mat = new PBRMaterial(`mat_${options.atlas.name}`, scene);
|
|
123
|
+
mat.albedoTexture = options.atlas.texture;
|
|
124
|
+
mat.roughness = 0.6;
|
|
125
|
+
mat.metallic = 0.1;
|
|
126
|
+
mat.backFaceCulling = false;
|
|
127
|
+
subMesh.material = mat;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const mat = new PBRMaterial(`mat_${meshName}_${groupKey.replace(/[^a-zA-Z0-9_]/g, '_')}`, scene);
|
|
131
|
+
if (samplePal?.texture) {
|
|
132
|
+
mat.albedoTexture = samplePal.texture;
|
|
133
|
+
}
|
|
134
|
+
else if (samplePal?.textureUrl) {
|
|
135
|
+
mat.albedoTexture = new Texture(samplePal.textureUrl, scene);
|
|
136
|
+
}
|
|
137
|
+
else if (samplePal?.color) {
|
|
138
|
+
mat.albedoColor = Color3.FromHexString(samplePal.color);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
mat.albedoColor = new Color3(0.6, 0.6, 0.6);
|
|
142
|
+
}
|
|
143
|
+
mat.roughness = 0.55;
|
|
144
|
+
mat.metallic = 0.1;
|
|
145
|
+
mat.backFaceCulling = false;
|
|
146
|
+
subMesh.material = mat;
|
|
147
|
+
}
|
|
148
|
+
createdSubMeshes.push(subMesh);
|
|
149
|
+
}
|
|
150
|
+
if (createdSubMeshes.length === 0)
|
|
151
|
+
return null;
|
|
152
|
+
let finalMesh;
|
|
153
|
+
if (createdSubMeshes.length === 1) {
|
|
154
|
+
finalMesh = createdSubMeshes[0];
|
|
155
|
+
finalMesh.name = meshName;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const merged = Mesh.MergeMeshes(createdSubMeshes, true, true, undefined, false, true);
|
|
159
|
+
if (!merged)
|
|
160
|
+
return null;
|
|
161
|
+
merged.name = meshName;
|
|
162
|
+
finalMesh = merged;
|
|
163
|
+
}
|
|
164
|
+
finalMesh.isPickable = true;
|
|
165
|
+
finalMesh.computeWorldMatrix(true);
|
|
166
|
+
finalMesh.refreshBoundingInfo();
|
|
167
|
+
return finalMesh;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Scene } from '@babylonjs/core';
|
|
2
|
+
import { TextureAtlasDefinition } from './types';
|
|
3
|
+
export declare class TextureAtlasManager {
|
|
4
|
+
private atlases;
|
|
5
|
+
private scene;
|
|
6
|
+
constructor(scene: Scene);
|
|
7
|
+
getAtlases(): TextureAtlasDefinition[];
|
|
8
|
+
getAtlas(id: string): TextureAtlasDefinition | undefined;
|
|
9
|
+
removeAtlas(id: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Generates a procedural 4x4 terrain and architecture texture atlas.
|
|
12
|
+
* Useful out-of-the-box for block building without needing external files.
|
|
13
|
+
*/
|
|
14
|
+
createProceduralTerrainAtlas(name?: string): TextureAtlasDefinition;
|
|
15
|
+
/**
|
|
16
|
+
* Loads a custom TextureAtlas from an image data URL / URL and grid columns & rows.
|
|
17
|
+
*/
|
|
18
|
+
createGridAtlasFromImage(name: string, imageSrc: string, columns?: number, rows?: number, tileNames?: string[]): Promise<TextureAtlasDefinition>;
|
|
19
|
+
/**
|
|
20
|
+
* Universal parser for TexturePacker JSON (Array or Hash), XML (Starling, Cocos, Sparrow),
|
|
21
|
+
* or TPS files.
|
|
22
|
+
*/
|
|
23
|
+
parseAtlasDescriptor(descriptorInput: any): {
|
|
24
|
+
frames: Array<{
|
|
25
|
+
name: string;
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
w: number;
|
|
29
|
+
h: number;
|
|
30
|
+
}>;
|
|
31
|
+
imagePath?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Parses XML / TPS / Starling / Cocos texture atlas formats.
|
|
35
|
+
*/
|
|
36
|
+
parseXmlAtlasDescriptor(xmlText: string): {
|
|
37
|
+
frames: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
w: number;
|
|
42
|
+
h: number;
|
|
43
|
+
}>;
|
|
44
|
+
imagePath?: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Loads an Atlas from an image and a JSON/XML/TPS spritesheet or frames specification.
|
|
48
|
+
*/
|
|
49
|
+
createAtlasFromJson(name: string, imageSrc: string, jsonDescriptor: any): Promise<TextureAtlasDefinition>;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts a cropped sub-image data URL for an individual frame from an atlas at native pixel resolution.
|
|
52
|
+
*/
|
|
53
|
+
extractFrameDataUrl(atlasId: string, frameId: string): string | null;
|
|
54
|
+
}
|