@divinevoxel/vlox 0.0.75 → 0.0.76
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/Builder/RayProvider.d.ts +6 -0
- package/Builder/RayProvider.js +1 -0
- package/Builder/Tools/Box/BoxSelection.d.ts +12 -0
- package/Builder/Tools/Box/BoxSelection.js +27 -0
- package/Builder/Tools/Box/BoxTool.d.ts +31 -0
- package/Builder/Tools/Box/BoxTool.js +91 -0
- package/Builder/Tools/Box/BoxToolTemplate.d.ts +13 -0
- package/Builder/Tools/Box/BoxToolTemplate.js +23 -0
- package/Builder/Tools/Brush/BrushTool.d.ts +48 -0
- package/Builder/Tools/Brush/BrushTool.js +146 -0
- package/Builder/Tools/BuilderToolBase.d.ts +3 -0
- package/Builder/Tools/BuilderToolBase.js +3 -0
- package/Builder/Tools/Hand/HandTool.d.ts +22 -0
- package/Builder/Tools/Hand/HandTool.js +56 -0
- package/Builder/Tools/Path/PahtTool.d.ts +29 -0
- package/Builder/Tools/Path/PahtTool.js +117 -0
- package/Builder/Tools/Wand/WandTool.d.ts +28 -0
- package/Builder/Tools/Wand/WandTool.js +67 -0
- package/Builder/Tools/Wrench/WrenchTool.d.ts +47 -0
- package/Builder/Tools/Wrench/WrenchTool.js +175 -0
- package/Builder/VoxelBuildSpace.d.ts +61 -0
- package/Builder/VoxelBuildSpace.js +165 -0
- package/Builder/VoxelBuilder.types.d.ts +0 -0
- package/Builder/VoxelBuilder.types.js +1 -0
- package/Builder/World/InitTasks.d.ts +1 -0
- package/Builder/World/InitTasks.js +134 -0
- package/Builder/World/VoxelBuildSpaceWorld.d.ts +4 -0
- package/Builder/World/VoxelBuildSpaceWorld.js +10 -0
- package/Contexts/Render/DivineVoxelEngineRender.d.ts +5 -5
- package/Contexts/World/DivineVoxelEngineWorld.d.ts +5 -5
- package/Mesher/Functions/Base/MeshSectionBase.js +3 -0
- package/Mesher/Functions/MeshVoxel.js +2 -0
- package/Mesher/Geomtry/VoxelMeshBVHBuilder.d.ts +2 -2
- package/Mesher/Models/Common/Calc/CalcConstants.d.ts +1 -1
- package/Mesher/Models/Procedures/Default/OutlinedTextureProcedure.js +8 -8
- package/Tasks/Paint/Erase/EraseVoxel.js +1 -1
- package/Tasks/Paint/Paint/PaintVoxel.js +1 -1
- package/Templates/Archive/ArchivedVoxelTemplate.d.ts +1 -0
- package/Templates/Archive/ArchivedVoxelTemplate.js +4 -0
- package/Templates/Archive/Functions/CreateArchivedTemplate.js +4 -2
- package/Templates/Cursor/TemplateCursor.js +3 -1
- package/Templates/Cursor/TemplateProxy.d.ts +1 -0
- package/Templates/Cursor/TemplateProxy.js +14 -0
- package/Templates/Full/FullVoxelTemplate.d.ts +1 -0
- package/Templates/Full/FullVoxelTemplate.js +4 -0
- package/Templates/Path/VoxelPath.d.ts +4 -0
- package/Templates/Path/VoxelPath.js +17 -0
- package/Templates/Path/VoxelPath.types.d.ts +1 -0
- package/Templates/Selection/VoxelBFSSelection.d.ts +3 -0
- package/Templates/Selection/VoxelBFSSelection.js +11 -0
- package/Templates/Selection/VoxelBoxSelection.d.ts +3 -0
- package/Templates/Selection/VoxelBoxSelection.js +11 -0
- package/Templates/Selection/VoxelPointSelection.d.ts +17 -0
- package/Templates/Selection/VoxelPointSelection.js +48 -0
- package/Templates/Selection/VoxelSelecton.d.ts +3 -0
- package/Templates/Selection/VoxelSurfaceSelection.d.ts +3 -0
- package/Templates/Selection/VoxelSurfaceSelection.js +18 -0
- package/Templates/Selection/VoxelTemplateSelection.d.ts +3 -0
- package/Templates/Selection/VoxelTemplateSelection.js +10 -0
- package/Templates/Shapes/BasicVoxelShapeTemplate.d.ts +1 -0
- package/Templates/Shapes/BoxVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/BoxVoxelTemplate.js +8 -0
- package/Templates/Shapes/ConeVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/ConeVoxelTemplate.js +4 -0
- package/Templates/Shapes/CylinderVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/CylinderVoxelTemplate.js +4 -0
- package/Templates/Shapes/EllipsoidVoxelTemplate.d.ts +23 -0
- package/Templates/Shapes/EllipsoidVoxelTemplate.js +89 -0
- package/Templates/Shapes/OctahedronVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/OctahedronVoxelTemplate.js +4 -0
- package/Templates/Shapes/PyramidVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/PyramidVoxelTemplate.js +8 -0
- package/Templates/Shapes/SphereVoxelTemplate.d.ts +3 -12
- package/Templates/Shapes/SphereVoxelTemplate.js +21 -59
- package/Templates/Shapes/TorusVoxelTemplate.d.ts +1 -0
- package/Templates/Shapes/TorusVoxelTemplate.js +4 -0
- package/Templates/Shapes/VoxelShapeTemplate.types.d.ts +2 -0
- package/Templates/Shapes/VoxelShapeTemplate.types.js +6 -1
- package/Templates/VoxelTemplates.types.d.ts +1 -0
- package/Textures/Classes/TextureAnimationTexture.d.ts +1 -1
- package/Util/BinaryBuffer/Functions/BinaryBufferConvert.d.ts +1 -1
- package/Util/BinaryBuffer/Functions/BinaryBufferToTypedArray.d.ts +1 -1
- package/Util/LocationData.d.ts +1 -1
- package/Voxels/Cursor/VoxelCursor.interface.d.ts +2 -0
- package/Voxels/Cursor/VoxelCursor.interface.js +2 -0
- package/Voxels/Interaction/Functions/PickVoxelWorld.js +15 -43
- package/Voxels/Interaction/VoxelPickResult.d.ts +1 -0
- package/Voxels/Interaction/VoxelPickResult.js +3 -0
- package/Voxels/State/Schema/BinarySchemaNode.d.ts +2 -1
- package/Voxels/State/Schema/BinarySchemaNode.js +5 -2
- package/Voxels/State/Schema/Conditions/SameVoxelConditions.js +2 -0
- package/Voxels/Types/PaintVoxelData.d.ts +11 -1
- package/Voxels/Types/PaintVoxelData.js +100 -14
- package/World/Archive/Functions/Shared/LightSegments.d.ts +1 -1
- package/World/Sector/Sector.d.ts +1 -1
- package/WorldSimulation/Dimensions/SimulationSector.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { VoxelSurfaceSelection } from "../../../Templates/Selection/VoxelSurfaceSelection";
|
|
2
|
+
import { VoxelBFSSelection } from "../../../Templates/Selection/VoxelBFSSelection";
|
|
3
|
+
import { BuilderToolBase } from "../BuilderToolBase";
|
|
4
|
+
export var WandToolModes;
|
|
5
|
+
(function (WandToolModes) {
|
|
6
|
+
WandToolModes["Place"] = "Place";
|
|
7
|
+
WandToolModes["Extrude"] = "Extrude";
|
|
8
|
+
WandToolModes["Remove"] = "Remove";
|
|
9
|
+
})(WandToolModes || (WandToolModes = {}));
|
|
10
|
+
export class WandTool extends BuilderToolBase {
|
|
11
|
+
space;
|
|
12
|
+
static ToolId = "Wand";
|
|
13
|
+
static ModeArray = [
|
|
14
|
+
WandToolModes.Place,
|
|
15
|
+
WandToolModes.Extrude,
|
|
16
|
+
WandToolModes.Remove,
|
|
17
|
+
];
|
|
18
|
+
mode = WandToolModes.Place;
|
|
19
|
+
maxCount = 1000;
|
|
20
|
+
extrusion = 0;
|
|
21
|
+
get selection() {
|
|
22
|
+
if (this.mode == WandToolModes.Place ||
|
|
23
|
+
this.mode == WandToolModes.Extrude) {
|
|
24
|
+
return this.surfaceSelection;
|
|
25
|
+
}
|
|
26
|
+
return this.bfsSelection;
|
|
27
|
+
}
|
|
28
|
+
surfaceSelection = new VoxelSurfaceSelection();
|
|
29
|
+
bfsSelection = new VoxelBFSSelection();
|
|
30
|
+
constructor(space) {
|
|
31
|
+
super();
|
|
32
|
+
this.space = space;
|
|
33
|
+
}
|
|
34
|
+
async updatePlacer(picked) {
|
|
35
|
+
if (this.mode == WandToolModes.Place ||
|
|
36
|
+
this.mode == WandToolModes.Extrude) {
|
|
37
|
+
this.surfaceSelection.fromJSON(await this.space.getSurfaceSelection(picked.position, picked.normal, this.extrusion, this.maxCount));
|
|
38
|
+
}
|
|
39
|
+
if (this.mode == WandToolModes.Remove) {
|
|
40
|
+
this.bfsSelection.fromJSON(await this.space.getBFSSelection(picked.position, this.maxCount));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async use(picked, voxelData, usePlacingStrategy = true) {
|
|
44
|
+
if (this.mode == WandToolModes.Place) {
|
|
45
|
+
if (!this.space.bounds.intersectsPoint(picked.normalPosition))
|
|
46
|
+
return false;
|
|
47
|
+
if (usePlacingStrategy) {
|
|
48
|
+
const newData = this.space.getPlaceState(voxelData, picked);
|
|
49
|
+
if (newData)
|
|
50
|
+
voxelData = newData;
|
|
51
|
+
}
|
|
52
|
+
const template = await this.space.getSurfaceSelectionTemplate(picked.position, picked.normal, this.extrusion, this.maxCount, voxelData);
|
|
53
|
+
await this.space.paintTemplate(template.position, template.toJSON());
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (this.mode == WandToolModes.Extrude) {
|
|
57
|
+
const template = await this.space.getSurfaceSelectionTemplate(picked.position, picked.normal, this.extrusion, this.maxCount, true);
|
|
58
|
+
await this.space.paintTemplate(template.position, template.toJSON());
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (this.mode == WandToolModes.Remove) {
|
|
62
|
+
const template = await this.space.getBFSSelectionTemplate(picked.position, this.maxCount);
|
|
63
|
+
await this.space.eraseTemplate(template.position, template.toJSON());
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { VoxelPickResult } from "../../../Voxels/Interaction/VoxelPickResult";
|
|
2
|
+
import { VoxelBuildSpace } from "../../VoxelBuildSpace";
|
|
3
|
+
import { PaintVoxelData } from "../../../Voxels";
|
|
4
|
+
import { VoxelPointSelection } from "../../../Templates/Selection/VoxelPointSelection";
|
|
5
|
+
import { BuilderToolBase } from "../BuilderToolBase";
|
|
6
|
+
interface WrenchToolEvents {
|
|
7
|
+
picked: {};
|
|
8
|
+
}
|
|
9
|
+
export type WrenchToolVoxelScehmaNodes = {
|
|
10
|
+
type: "string";
|
|
11
|
+
values: string[];
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: "number";
|
|
17
|
+
min: number;
|
|
18
|
+
max: number;
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
value: number;
|
|
22
|
+
};
|
|
23
|
+
type WrenchToolSchemas = {
|
|
24
|
+
stateSchema: WrenchToolVoxelScehmaNodes[];
|
|
25
|
+
modSchema: WrenchToolVoxelScehmaNodes[];
|
|
26
|
+
};
|
|
27
|
+
export declare class WrenchTool extends BuilderToolBase<WrenchToolEvents> {
|
|
28
|
+
space: VoxelBuildSpace;
|
|
29
|
+
static ToolId: string;
|
|
30
|
+
private mode;
|
|
31
|
+
selection: VoxelPointSelection;
|
|
32
|
+
paintData: PaintVoxelData;
|
|
33
|
+
private _pickedResult;
|
|
34
|
+
constructor(space: VoxelBuildSpace);
|
|
35
|
+
isUpdating(): boolean;
|
|
36
|
+
stopUpdating(): void;
|
|
37
|
+
updatePlacer(picked: VoxelPickResult): void;
|
|
38
|
+
private processSchema;
|
|
39
|
+
updatePickedSchema(schema: WrenchToolSchemas): PaintVoxelData | undefined;
|
|
40
|
+
getPickedSchema(): WrenchToolSchemas | null;
|
|
41
|
+
/**Get an array of all possible state varations for the current mod of the selected voxel. */
|
|
42
|
+
getStateValues(): PaintVoxelData[] | null;
|
|
43
|
+
/**Get an array of all possible mod varations for the current state of the selected voxel. */
|
|
44
|
+
getModValues(): PaintVoxelData[] | null;
|
|
45
|
+
use(): Promise<true | undefined>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { PaintVoxelData } from "../../../Voxels";
|
|
2
|
+
import { VoxelPointSelection } from "../../../Templates/Selection/VoxelPointSelection";
|
|
3
|
+
import { BuilderToolBase } from "../BuilderToolBase";
|
|
4
|
+
import { SchemaRegister } from "../../../Voxels/State/SchemaRegister";
|
|
5
|
+
import { VoxelPalettesRegister } from "../../../Voxels/Data/VoxelPalettesRegister";
|
|
6
|
+
var WrenchToolModes;
|
|
7
|
+
(function (WrenchToolModes) {
|
|
8
|
+
WrenchToolModes["Pick"] = "Pick";
|
|
9
|
+
WrenchToolModes["Update"] = "Update";
|
|
10
|
+
})(WrenchToolModes || (WrenchToolModes = {}));
|
|
11
|
+
export class WrenchTool extends BuilderToolBase {
|
|
12
|
+
space;
|
|
13
|
+
static ToolId = "Wrench";
|
|
14
|
+
mode = WrenchToolModes.Pick;
|
|
15
|
+
selection = new VoxelPointSelection();
|
|
16
|
+
paintData = PaintVoxelData.Create();
|
|
17
|
+
_pickedResult = null;
|
|
18
|
+
constructor(space) {
|
|
19
|
+
super();
|
|
20
|
+
this.space = space;
|
|
21
|
+
}
|
|
22
|
+
isUpdating() {
|
|
23
|
+
if (this._pickedResult !== null && this.mode == WrenchToolModes.Update)
|
|
24
|
+
return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
stopUpdating() {
|
|
28
|
+
this.mode = WrenchToolModes.Pick;
|
|
29
|
+
this._pickedResult = null;
|
|
30
|
+
}
|
|
31
|
+
updatePlacer(picked) {
|
|
32
|
+
console.log("update placer", this.mode);
|
|
33
|
+
if (this.mode == WrenchToolModes.Pick) {
|
|
34
|
+
this._pickedResult = picked;
|
|
35
|
+
this.selection.reConstruct(picked.position);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
processSchema(schema) {
|
|
39
|
+
const nodes = [];
|
|
40
|
+
for (const node of schema.nodes) {
|
|
41
|
+
if (node.valuePalette) {
|
|
42
|
+
nodes.push({
|
|
43
|
+
id: node.name,
|
|
44
|
+
label: node.name,
|
|
45
|
+
values: [...node.valuePalette._palette],
|
|
46
|
+
type: "string",
|
|
47
|
+
value: "",
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
nodes.push({
|
|
52
|
+
id: node.name,
|
|
53
|
+
label: node.name,
|
|
54
|
+
min: 0,
|
|
55
|
+
max: Math.pow(2, node.data.bitSize) - 1,
|
|
56
|
+
type: "number",
|
|
57
|
+
value: 0,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return nodes;
|
|
62
|
+
}
|
|
63
|
+
updatePickedSchema(schema) {
|
|
64
|
+
if (!this._pickedResult)
|
|
65
|
+
return;
|
|
66
|
+
const trueVoxelId = this._pickedResult.voxel.getVoxelId();
|
|
67
|
+
const voxelSchemas = SchemaRegister.getVoxelSchemas(this._pickedResult.voxel.getStringId());
|
|
68
|
+
voxelSchemas.state.startEncoding(this._pickedResult.voxel.getState());
|
|
69
|
+
voxelSchemas.mod.startEncoding(this._pickedResult.voxel.getMod());
|
|
70
|
+
for (const node of schema.stateSchema) {
|
|
71
|
+
if (node.type == "string") {
|
|
72
|
+
voxelSchemas.state.setValue(node.id, node.value);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
voxelSchemas.state.setNumber(node.id, node.value);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const node of schema.modSchema) {
|
|
79
|
+
if (node.type == "string") {
|
|
80
|
+
voxelSchemas.mod.setValue(node.id, node.value);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
voxelSchemas.mod.setNumber(node.id, node.value);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const currentRaw = this._pickedResult.voxel.getRaw();
|
|
87
|
+
const rawVoxelData = [
|
|
88
|
+
VoxelPalettesRegister.getVoxelId(trueVoxelId, voxelSchemas.state.getEncoded(), voxelSchemas.mod.getEncoded()),
|
|
89
|
+
currentRaw[1],
|
|
90
|
+
currentRaw[2],
|
|
91
|
+
currentRaw[3],
|
|
92
|
+
];
|
|
93
|
+
this.paintData = PaintVoxelData.FromRaw(rawVoxelData);
|
|
94
|
+
return this.paintData;
|
|
95
|
+
}
|
|
96
|
+
getPickedSchema() {
|
|
97
|
+
if (!this._pickedResult)
|
|
98
|
+
return null;
|
|
99
|
+
const id = this._pickedResult.voxel.getStringId();
|
|
100
|
+
const voxelSchemas = SchemaRegister.getVoxelSchemas(id);
|
|
101
|
+
voxelSchemas.state.startEncoding(this._pickedResult.voxel.getState());
|
|
102
|
+
voxelSchemas.mod.startEncoding(this._pickedResult.voxel.getMod());
|
|
103
|
+
console.warn("get picked schemas", { id }, SchemaRegister.stateSchemaData);
|
|
104
|
+
return {
|
|
105
|
+
stateSchema: this.processSchema(voxelSchemas.state),
|
|
106
|
+
modSchema: this.processSchema(voxelSchemas.mod),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**Get an array of all possible state varations for the current mod of the selected voxel. */
|
|
110
|
+
getStateValues() {
|
|
111
|
+
if (!this._pickedResult)
|
|
112
|
+
return null;
|
|
113
|
+
const voxelStates = [];
|
|
114
|
+
const voxelId = this._pickedResult.voxel.id;
|
|
115
|
+
const [trueId, , mod] = VoxelPalettesRegister.voxels[voxelId];
|
|
116
|
+
const stateArray = VoxelPalettesRegister.voxelRecord[trueId][mod];
|
|
117
|
+
const rawVoxelData = [0, 0, 0, 0];
|
|
118
|
+
for (let i = 0; i < stateArray.length; i++) {
|
|
119
|
+
const value = stateArray[i];
|
|
120
|
+
if (value === undefined || value <= 0)
|
|
121
|
+
continue;
|
|
122
|
+
rawVoxelData[0] = value;
|
|
123
|
+
voxelStates.push(PaintVoxelData.FromRaw(rawVoxelData));
|
|
124
|
+
}
|
|
125
|
+
return voxelStates;
|
|
126
|
+
}
|
|
127
|
+
/**Get an array of all possible mod varations for the current state of the selected voxel. */
|
|
128
|
+
getModValues() {
|
|
129
|
+
if (!this._pickedResult)
|
|
130
|
+
return null;
|
|
131
|
+
const voxelStates = [];
|
|
132
|
+
const voxelId = this._pickedResult.voxel.id;
|
|
133
|
+
const [trueId, state] = VoxelPalettesRegister.voxels[voxelId];
|
|
134
|
+
const modArray = VoxelPalettesRegister.voxelRecord[trueId];
|
|
135
|
+
const rawVoxelData = [0, 0, 0, 0];
|
|
136
|
+
for (let i = 0; i < modArray.length; i++) {
|
|
137
|
+
const stateArray = modArray[i];
|
|
138
|
+
if (stateArray === undefined || !stateArray.length)
|
|
139
|
+
continue;
|
|
140
|
+
let id = -1;
|
|
141
|
+
for (let j = 0; j < stateArray.length; j++) {
|
|
142
|
+
id = VoxelPalettesRegister.voxelRecord[trueId][i][state];
|
|
143
|
+
if (id === undefined || id < 0)
|
|
144
|
+
continue;
|
|
145
|
+
rawVoxelData[0] = id;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (id === undefined || id < 0)
|
|
149
|
+
continue;
|
|
150
|
+
voxelStates.push(PaintVoxelData.FromRaw(rawVoxelData));
|
|
151
|
+
}
|
|
152
|
+
return voxelStates;
|
|
153
|
+
}
|
|
154
|
+
async use() {
|
|
155
|
+
if (this.mode == WrenchToolModes.Pick) {
|
|
156
|
+
if (this._pickedResult && !this._pickedResult.voxel.isAir()) {
|
|
157
|
+
this._pickedResult = this._pickedResult.clone();
|
|
158
|
+
this.dispatch("picked", {});
|
|
159
|
+
this.mode = WrenchToolModes.Update;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
this._pickedResult = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (this.mode == WrenchToolModes.Update) {
|
|
167
|
+
await this.space.paintVoxel([
|
|
168
|
+
this.selection.origin.x,
|
|
169
|
+
this.selection.origin.y,
|
|
170
|
+
this.selection.origin.z,
|
|
171
|
+
], this.paintData);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Vec3Array, Vector3Like } from "@amodx/math";
|
|
2
|
+
import { BoundingBox } from "@amodx/math/Geomtry/Bounds/BoundingBox";
|
|
3
|
+
import { DivineVoxelEngineRender } from "../Contexts/Render";
|
|
4
|
+
import { VoxelPathData } from "../Templates/Path/VoxelPath.types";
|
|
5
|
+
import { IVoxelTemplateData } from "../Templates/VoxelTemplates.types";
|
|
6
|
+
import { PaintVoxelData } from "../Voxels";
|
|
7
|
+
import { VoxelPickResult } from "../Voxels/Interaction/VoxelPickResult";
|
|
8
|
+
import { RayProvider } from "./RayProvider";
|
|
9
|
+
import { FullVoxelTemplate } from "../Templates/Full/FullVoxelTemplate";
|
|
10
|
+
import { BoundsMinMaxData } from "@amodx/math/Geomtry/Bounds/BoundsInterface";
|
|
11
|
+
import { VoxelSurfaceSelectionData } from "Templates/Selection/VoxelSurfaceSelection";
|
|
12
|
+
import { VoxelBFSSelectionData } from "Templates/Selection/VoxelBFSSelection";
|
|
13
|
+
export type VoxelSpaceUpdateData = {
|
|
14
|
+
type: "clear";
|
|
15
|
+
} | {
|
|
16
|
+
type: "paint-voxel";
|
|
17
|
+
position: Vec3Array;
|
|
18
|
+
voxel: PaintVoxelData;
|
|
19
|
+
} | {
|
|
20
|
+
type: "erase-voxel";
|
|
21
|
+
position: Vec3Array;
|
|
22
|
+
} | {
|
|
23
|
+
type: "paint-voxel-template";
|
|
24
|
+
position: Vec3Array;
|
|
25
|
+
template: IVoxelTemplateData<any>;
|
|
26
|
+
} | {
|
|
27
|
+
type: "erase-voxel-template";
|
|
28
|
+
position: Vec3Array;
|
|
29
|
+
template: IVoxelTemplateData<any>;
|
|
30
|
+
} | {
|
|
31
|
+
type: "paint-voxel-path";
|
|
32
|
+
position: Vec3Array;
|
|
33
|
+
path: VoxelPathData;
|
|
34
|
+
} | {
|
|
35
|
+
type: "erase-voxel-path";
|
|
36
|
+
position: Vec3Array;
|
|
37
|
+
path: VoxelPathData;
|
|
38
|
+
};
|
|
39
|
+
export declare class VoxelBuildSpace {
|
|
40
|
+
DVER: DivineVoxelEngineRender;
|
|
41
|
+
rayProvider: RayProvider;
|
|
42
|
+
beforeUpdate: (data: VoxelSpaceUpdateData) => void;
|
|
43
|
+
afterUpdate: (data: VoxelSpaceUpdateData) => void;
|
|
44
|
+
bounds: BoundingBox;
|
|
45
|
+
constructor(DVER: DivineVoxelEngineRender, rayProvider: RayProvider, min?: Vector3Like, max?: Vector3Like);
|
|
46
|
+
pick(rayOrigin: Vector3Like, rayDirection: Vector3Like, length: number): Promise<VoxelPickResult | null>;
|
|
47
|
+
createTemplate(bounds: BoundsMinMaxData): Promise<FullVoxelTemplate>;
|
|
48
|
+
getSurfaceSelection(position: Vector3Like, normal: Vector3Like, extrusion: number, maxSize?: number): Promise<VoxelSurfaceSelectionData>;
|
|
49
|
+
getSurfaceSelectionTemplate(position: Vector3Like, normal: Vector3Like, extrusion: number, maxSize: number, voxelDataOrExtrude: true | PaintVoxelData): Promise<FullVoxelTemplate>;
|
|
50
|
+
getBFSSelection(position: Vector3Like, maxSize?: number): Promise<VoxelBFSSelectionData>;
|
|
51
|
+
getBFSSelectionTemplate(position: Vector3Like, maxSize?: number): Promise<FullVoxelTemplate>;
|
|
52
|
+
getPlaceState(data: PaintVoxelData, picked: VoxelPickResult, alt?: number | null): PaintVoxelData | undefined;
|
|
53
|
+
private _update;
|
|
54
|
+
private _doUpdate;
|
|
55
|
+
paintVoxel(position: Vec3Array | Vector3Like, voxel: PaintVoxelData): Promise<void>;
|
|
56
|
+
eraseVoxel(position: Vec3Array | Vector3Like): Promise<void>;
|
|
57
|
+
paintTemplate(position: Vec3Array | Vector3Like | Vector3Like, template: IVoxelTemplateData<any>): Promise<void>;
|
|
58
|
+
eraseTemplate(position: Vec3Array | Vector3Like, template: IVoxelTemplateData<any>): Promise<void>;
|
|
59
|
+
paintPath(position: Vec3Array | Vector3Like, path: VoxelPathData): Promise<void>;
|
|
60
|
+
erasePath(position: Vec3Array | Vector3Like, path: VoxelPathData): Promise<void>;
|
|
61
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Vector3Like } from "@amodx/math";
|
|
2
|
+
import { BoundingBox } from "@amodx/math/Geomtry/Bounds/BoundingBox";
|
|
3
|
+
import { PaintVoxelData } from "../Voxels";
|
|
4
|
+
import { VoxelPlacingStrategyRegister } from "../Voxels/Interaction/Placing/VoxelPlacingStrategyRegister";
|
|
5
|
+
import { VoxelPickResult } from "../Voxels/Interaction/VoxelPickResult";
|
|
6
|
+
import { SchemaRegister } from "../Voxels/State/SchemaRegister";
|
|
7
|
+
import { FullVoxelTemplate } from "../Templates/Full/FullVoxelTemplate";
|
|
8
|
+
export class VoxelBuildSpace {
|
|
9
|
+
DVER;
|
|
10
|
+
rayProvider;
|
|
11
|
+
beforeUpdate;
|
|
12
|
+
afterUpdate;
|
|
13
|
+
bounds;
|
|
14
|
+
constructor(DVER, rayProvider, min = Vector3Like.Create(-Infinity, -Infinity, -Infinity), max = Vector3Like.Create(Infinity, Infinity, Infinity)) {
|
|
15
|
+
this.DVER = DVER;
|
|
16
|
+
this.rayProvider = rayProvider;
|
|
17
|
+
this.bounds = new BoundingBox(min, max);
|
|
18
|
+
}
|
|
19
|
+
async pick(rayOrigin, rayDirection, length) {
|
|
20
|
+
const pickedVoxel = await this.DVER.threads.world.runTaskAsync("pick-voxel", [
|
|
21
|
+
[rayOrigin.x, rayOrigin.y, rayOrigin.z],
|
|
22
|
+
[rayDirection.x, rayDirection.y, rayDirection.z],
|
|
23
|
+
length,
|
|
24
|
+
]);
|
|
25
|
+
if (pickedVoxel === null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return VoxelPickResult.FromJSON(pickedVoxel);
|
|
29
|
+
}
|
|
30
|
+
async createTemplate(bounds) {
|
|
31
|
+
const templateData = await this.DVER.threads.world.runTaskAsync("create-voxel-template", [
|
|
32
|
+
[0, ...Vector3Like.ToArray(bounds.min)],
|
|
33
|
+
bounds,
|
|
34
|
+
]);
|
|
35
|
+
return new FullVoxelTemplate(templateData);
|
|
36
|
+
}
|
|
37
|
+
async getSurfaceSelection(position, normal, extrusion, maxSize) {
|
|
38
|
+
return await this.DVER.threads.world.runTaskAsync("get-voxel-surface-selection", [position, normal, extrusion, maxSize]);
|
|
39
|
+
}
|
|
40
|
+
async getSurfaceSelectionTemplate(position, normal, extrusion, maxSize, voxelDataOrExtrude) {
|
|
41
|
+
return new FullVoxelTemplate(await this.DVER.threads.world.runTaskAsync("get-voxel-surface-selection-template", [position, normal, extrusion, maxSize, voxelDataOrExtrude]));
|
|
42
|
+
}
|
|
43
|
+
async getBFSSelection(position, maxSize) {
|
|
44
|
+
return await this.DVER.threads.world.runTaskAsync("get-voxel-bfs-selection", [position, maxSize]);
|
|
45
|
+
}
|
|
46
|
+
async getBFSSelectionTemplate(position, maxSize) {
|
|
47
|
+
return new FullVoxelTemplate(await this.DVER.threads.world.runTaskAsync("get-voxel-bfs-selection-template", [position, maxSize]));
|
|
48
|
+
}
|
|
49
|
+
getPlaceState(data, picked, alt = null) {
|
|
50
|
+
const strategy = VoxelPlacingStrategyRegister.get(data.id);
|
|
51
|
+
if (!strategy)
|
|
52
|
+
return data;
|
|
53
|
+
const state = strategy.getState(picked, alt);
|
|
54
|
+
if (!state) {
|
|
55
|
+
data.state = 0;
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
const schema = SchemaRegister.getVoxelSchemas(data.id);
|
|
59
|
+
data.state = schema.state.readString(state);
|
|
60
|
+
}
|
|
61
|
+
async _update(update) {
|
|
62
|
+
if (update.type == "paint-voxel") {
|
|
63
|
+
await this.DVER.threads.world.runTaskAsync("paint-voxel", [
|
|
64
|
+
[0, ...update.position],
|
|
65
|
+
PaintVoxelData.ToRaw(update.voxel),
|
|
66
|
+
]);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (update.type == "erase-voxel") {
|
|
70
|
+
await this.DVER.threads.world.runTaskAsync("erase-voxel", [
|
|
71
|
+
0,
|
|
72
|
+
...update.position,
|
|
73
|
+
]);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (update.type == "paint-voxel-template") {
|
|
77
|
+
await this.DVER.threads.world.runTaskAsync("paint-voxel-template", [
|
|
78
|
+
[0, ...update.position],
|
|
79
|
+
update.template,
|
|
80
|
+
]);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (update.type == "erase-voxel-template") {
|
|
84
|
+
await this.DVER.threads.world.runTaskAsync("erase-voxel-template", [
|
|
85
|
+
[0, ...update.position],
|
|
86
|
+
update.template,
|
|
87
|
+
]);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (update.type == "paint-voxel-path") {
|
|
91
|
+
await this.DVER.threads.world.runTaskAsync("paint-voxel-path", [
|
|
92
|
+
[0, ...update.position],
|
|
93
|
+
update.path,
|
|
94
|
+
]);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (update.type == "erase-voxel-path") {
|
|
98
|
+
await this.DVER.threads.world.runTaskAsync("erase-voxel-path", [
|
|
99
|
+
[0, ...update.position],
|
|
100
|
+
update.path,
|
|
101
|
+
]);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async _doUpdate(data) {
|
|
106
|
+
if (this.beforeUpdate)
|
|
107
|
+
this.beforeUpdate(data);
|
|
108
|
+
await this._update(data);
|
|
109
|
+
if (this.afterUpdate)
|
|
110
|
+
this.afterUpdate(data);
|
|
111
|
+
}
|
|
112
|
+
async paintVoxel(position, voxel) {
|
|
113
|
+
await this._doUpdate({
|
|
114
|
+
type: "paint-voxel",
|
|
115
|
+
position: Array.isArray(position)
|
|
116
|
+
? position
|
|
117
|
+
: Vector3Like.ToArray(position),
|
|
118
|
+
voxel,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async eraseVoxel(position) {
|
|
122
|
+
await this._doUpdate({
|
|
123
|
+
type: "erase-voxel",
|
|
124
|
+
position: Array.isArray(position)
|
|
125
|
+
? position
|
|
126
|
+
: Vector3Like.ToArray(position),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async paintTemplate(position, template) {
|
|
130
|
+
await this._doUpdate({
|
|
131
|
+
type: "paint-voxel-template",
|
|
132
|
+
position: Array.isArray(position)
|
|
133
|
+
? position
|
|
134
|
+
: Vector3Like.ToArray(position),
|
|
135
|
+
template,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async eraseTemplate(position, template) {
|
|
139
|
+
await this._doUpdate({
|
|
140
|
+
type: "erase-voxel-template",
|
|
141
|
+
position: Array.isArray(position)
|
|
142
|
+
? position
|
|
143
|
+
: Vector3Like.ToArray(position),
|
|
144
|
+
template,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async paintPath(position, path) {
|
|
148
|
+
await this._doUpdate({
|
|
149
|
+
type: "paint-voxel-path",
|
|
150
|
+
position: Array.isArray(position)
|
|
151
|
+
? position
|
|
152
|
+
: Vector3Like.ToArray(position),
|
|
153
|
+
path,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async erasePath(position, path) {
|
|
157
|
+
await this._doUpdate({
|
|
158
|
+
type: "erase-voxel-path",
|
|
159
|
+
position: Array.isArray(position)
|
|
160
|
+
? position
|
|
161
|
+
: Vector3Like.ToArray(position),
|
|
162
|
+
path,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function InitTasks(): void;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { WorldSimulation } from "../../WorldSimulation";
|
|
2
|
+
import { Threads } from "@amodx/threads";
|
|
3
|
+
import { Vector3Like } from "@amodx/math";
|
|
4
|
+
import { VoxelTemplateRegister } from "../../Templates/VoxelTempateRegister";
|
|
5
|
+
import { VoxelPath } from "../../Templates/Path/VoxelPath";
|
|
6
|
+
import PickVoxelWorld from "../../Voxels/Interaction/Functions/PickVoxelWorld";
|
|
7
|
+
import { WorldCursor } from "../../World";
|
|
8
|
+
import LockSectors from "../../World/Lock/Function/LockSectors";
|
|
9
|
+
import UnLockSectors from "../../World/Lock/Function/UnLockSectors";
|
|
10
|
+
import { BoundingBox } from "@amodx/math/Geomtry/Bounds/BoundingBox";
|
|
11
|
+
import { VoxelSurfaceSelection } from "../../Templates/Selection/VoxelSurfaceSelection";
|
|
12
|
+
import { VoxelBFSSelection } from "../../Templates/Selection/VoxelBFSSelection";
|
|
13
|
+
import CreateFullTemplate from "../../Templates/Full/Functions/CreateFullTemplate";
|
|
14
|
+
export function InitTasks() {
|
|
15
|
+
const dimension = WorldSimulation.getDimension(0);
|
|
16
|
+
const brush = dimension.getBrush();
|
|
17
|
+
const cursor = new WorldCursor();
|
|
18
|
+
const surfaceSelection = new VoxelSurfaceSelection();
|
|
19
|
+
const bfsSelection = new VoxelBFSSelection();
|
|
20
|
+
const updateData = {
|
|
21
|
+
includedAreas: [],
|
|
22
|
+
};
|
|
23
|
+
const buildAreaBounds = new BoundingBox();
|
|
24
|
+
Threads.registerTask("get-box-area-template", async ([min, max]) => {
|
|
25
|
+
await LockSectors(cursor.dimension, buildAreaBounds);
|
|
26
|
+
const archived = CreateFullTemplate(cursor, { min, max });
|
|
27
|
+
await UnLockSectors(cursor.dimension, buildAreaBounds);
|
|
28
|
+
return [archived];
|
|
29
|
+
});
|
|
30
|
+
Threads.registerTask("set-build-area", async ([min, max]) => {
|
|
31
|
+
buildAreaBounds.setMinMax(Vector3Like.Create(...min), Vector3Like.Create(...max));
|
|
32
|
+
updateData.includedAreas = [[min, max]];
|
|
33
|
+
});
|
|
34
|
+
Threads.registerTask("pick-voxel", async ([position, direction, length]) => {
|
|
35
|
+
const pickedVoxel = await PickVoxelWorld(cursor, position, direction, length);
|
|
36
|
+
//pick voxels error when not using shared memory if the secotrs are check out
|
|
37
|
+
return [pickedVoxel?.toJSON() || null];
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Selections
|
|
41
|
+
*/
|
|
42
|
+
Threads.registerTask("get-voxel-surface-selection", async ([position, normal, extrusion, maxSize]) => {
|
|
43
|
+
await LockSectors(cursor.dimension, buildAreaBounds);
|
|
44
|
+
surfaceSelection.reConstruct(cursor, position, normal, extrusion, maxSize);
|
|
45
|
+
await UnLockSectors(cursor.dimension, buildAreaBounds);
|
|
46
|
+
return [surfaceSelection.toJSON()];
|
|
47
|
+
});
|
|
48
|
+
Threads.registerTask("get-voxel-surface-selection-template", async ([position, normal, extrusion, maxSize, voxelDataOrExtrude]) => {
|
|
49
|
+
await LockSectors(cursor.dimension, buildAreaBounds);
|
|
50
|
+
surfaceSelection.reConstruct(cursor, position, normal, extrusion, maxSize);
|
|
51
|
+
await UnLockSectors(cursor.dimension, buildAreaBounds);
|
|
52
|
+
const template = surfaceSelection
|
|
53
|
+
.toTemplate(cursor, voxelDataOrExtrude)
|
|
54
|
+
.toJSON();
|
|
55
|
+
template.position.x = surfaceSelection.origin.x;
|
|
56
|
+
template.position.y = surfaceSelection.origin.y;
|
|
57
|
+
template.position.z = surfaceSelection.origin.z;
|
|
58
|
+
return [template];
|
|
59
|
+
});
|
|
60
|
+
Threads.registerTask("get-voxel-bfs-selection", async ([position, maxSize]) => {
|
|
61
|
+
await LockSectors(cursor.dimension, buildAreaBounds);
|
|
62
|
+
bfsSelection.reConstruct(cursor, position, maxSize);
|
|
63
|
+
await UnLockSectors(cursor.dimension, buildAreaBounds);
|
|
64
|
+
return [bfsSelection.toJSON()];
|
|
65
|
+
});
|
|
66
|
+
Threads.registerTask("get-voxel-bfs-selection-template", async ([position, maxSize]) => {
|
|
67
|
+
await LockSectors(cursor.dimension, buildAreaBounds);
|
|
68
|
+
bfsSelection.reConstruct(cursor, position, maxSize);
|
|
69
|
+
await UnLockSectors(cursor.dimension, buildAreaBounds);
|
|
70
|
+
const template = bfsSelection.toTemplate(cursor).toJSON();
|
|
71
|
+
template.position.x = bfsSelection.origin.x;
|
|
72
|
+
template.position.y = bfsSelection.origin.y;
|
|
73
|
+
template.position.z = bfsSelection.origin.z;
|
|
74
|
+
return [template];
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Painting
|
|
78
|
+
*/
|
|
79
|
+
Threads.registerTask("paint-voxel", async ([location, raw]) => {
|
|
80
|
+
await LockSectors(location[0], buildAreaBounds);
|
|
81
|
+
brush.setXYZ(location[1], location[2], location[3]);
|
|
82
|
+
brush.setRaw(raw);
|
|
83
|
+
brush.paint(updateData);
|
|
84
|
+
await UnLockSectors(location[0], buildAreaBounds);
|
|
85
|
+
});
|
|
86
|
+
Threads.registerTask("erase-voxel", async (location) => {
|
|
87
|
+
await LockSectors(location[0], buildAreaBounds);
|
|
88
|
+
brush.dimension = location[0];
|
|
89
|
+
brush.setXYZ(location[1], location[2], location[3]);
|
|
90
|
+
brush.erase(updateData);
|
|
91
|
+
await UnLockSectors(location[0], buildAreaBounds);
|
|
92
|
+
});
|
|
93
|
+
Threads.registerTask("create-voxel-template", async ([location, bounds]) => {
|
|
94
|
+
const boundingBox = new BoundingBox(bounds.min, bounds.max);
|
|
95
|
+
await LockSectors(location[0], boundingBox);
|
|
96
|
+
const template = CreateFullTemplate(cursor, bounds);
|
|
97
|
+
await UnLockSectors(location[0], boundingBox);
|
|
98
|
+
return [template];
|
|
99
|
+
});
|
|
100
|
+
Threads.registerTask("paint-voxel-template", async ([location, data]) => {
|
|
101
|
+
const template = VoxelTemplateRegister.create(data);
|
|
102
|
+
brush.dimension = location[0];
|
|
103
|
+
await LockSectors(location[0], template.bounds);
|
|
104
|
+
brush
|
|
105
|
+
.setXYZ(location[1], location[2], location[3])
|
|
106
|
+
.paintTemplate(template, updateData);
|
|
107
|
+
await UnLockSectors(location[0], template.bounds);
|
|
108
|
+
});
|
|
109
|
+
Threads.registerTask("erase-voxel-template", async ([location, data]) => {
|
|
110
|
+
brush.dimension = location[0];
|
|
111
|
+
const template = VoxelTemplateRegister.create(data);
|
|
112
|
+
await LockSectors(location[0], template.bounds);
|
|
113
|
+
brush
|
|
114
|
+
.setXYZ(location[1], location[2], location[3])
|
|
115
|
+
.eraseTemplate(template, updateData);
|
|
116
|
+
await UnLockSectors(location[0], template.bounds);
|
|
117
|
+
});
|
|
118
|
+
Threads.registerTask("paint-voxel-path", async ([location, data]) => {
|
|
119
|
+
await LockSectors(location[0], buildAreaBounds);
|
|
120
|
+
brush.dimension = location[0];
|
|
121
|
+
brush
|
|
122
|
+
.setXYZ(location[1], location[2], location[3])
|
|
123
|
+
.paintPath(new VoxelPath(data), updateData);
|
|
124
|
+
await UnLockSectors(location[0], buildAreaBounds);
|
|
125
|
+
});
|
|
126
|
+
Threads.registerTask("erase-voxel-path", async ([location, data]) => {
|
|
127
|
+
await LockSectors(location[0], buildAreaBounds);
|
|
128
|
+
brush.dimension = location[0];
|
|
129
|
+
brush
|
|
130
|
+
.setXYZ(location[1], location[2], location[3])
|
|
131
|
+
.erasePath(new VoxelPath(data), updateData);
|
|
132
|
+
await UnLockSectors(location[0], buildAreaBounds);
|
|
133
|
+
});
|
|
134
|
+
}
|