@drawcall/charta 0.0.0
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 +7 -0
- package/dist/assets/loader.d.ts +21 -0
- package/dist/assets/loader.d.ts.map +1 -0
- package/dist/assets/loader.js +113 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +27 -0
- package/dist/grammar.d.ts +29 -0
- package/dist/grammar.d.ts.map +1 -0
- package/dist/grammar.js +119 -0
- package/dist/grass/index.d.ts +25 -0
- package/dist/grass/index.d.ts.map +1 -0
- package/dist/grass/index.js +177 -0
- package/dist/grass/material.d.ts +10 -0
- package/dist/grass/material.d.ts.map +1 -0
- package/dist/grass/material.js +80 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/interpreter.d.ts +47 -0
- package/dist/interpreter.d.ts.map +1 -0
- package/dist/interpreter.js +226 -0
- package/dist/locations.d.ts +16 -0
- package/dist/locations.d.ts.map +1 -0
- package/dist/locations.js +58 -0
- package/dist/parser.d.ts +9 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +47 -0
- package/dist/pillars/index.d.ts +7 -0
- package/dist/pillars/index.d.ts.map +1 -0
- package/dist/pillars/index.js +154 -0
- package/dist/pillars/material.d.ts +3 -0
- package/dist/pillars/material.d.ts.map +1 -0
- package/dist/pillars/material.js +43 -0
- package/dist/place/index.d.ts +37 -0
- package/dist/place/index.d.ts.map +1 -0
- package/dist/place/index.js +216 -0
- package/dist/tiles/geometry.d.ts +46 -0
- package/dist/tiles/geometry.d.ts.map +1 -0
- package/dist/tiles/geometry.js +463 -0
- package/dist/tiles/index.d.ts +18 -0
- package/dist/tiles/index.d.ts.map +1 -0
- package/dist/tiles/index.js +121 -0
- package/dist/tiles/material.d.ts +6 -0
- package/dist/tiles/material.d.ts.map +1 -0
- package/dist/tiles/material.js +88 -0
- package/dist/utils/instanced-mesh-group.d.ts +17 -0
- package/dist/utils/instanced-mesh-group.d.ts.map +1 -0
- package/dist/utils/instanced-mesh-group.js +59 -0
- package/dist/utils/random.d.ts +4 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +19 -0
- package/dist/utils/texture.d.ts +3 -0
- package/dist/utils/texture.d.ts.map +1 -0
- package/dist/utils/texture.js +30 -0
- package/dist/walls/index.d.ts +87 -0
- package/dist/walls/index.d.ts.map +1 -0
- package/dist/walls/index.js +376 -0
- package/dist/walls/material.d.ts +3 -0
- package/dist/walls/material.d.ts.map +1 -0
- package/dist/walls/material.js +67 -0
- package/dist/water/index.d.ts +10 -0
- package/dist/water/index.d.ts.map +1 -0
- package/dist/water/index.js +46 -0
- package/dist/water/material.d.ts +5 -0
- package/dist/water/material.d.ts.map +1 -0
- package/dist/water/material.js +46 -0
- package/dist/water/texture.d.ts +15 -0
- package/dist/water/texture.d.ts.map +1 -0
- package/dist/water/texture.js +201 -0
- package/package.json +39 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function buildPillarMeshMaterial(material, textureArray) {
|
|
2
|
+
material.onBeforeCompile = (shader) => {
|
|
3
|
+
shader.uniforms.uTextureArray = { value: textureArray };
|
|
4
|
+
shader.vertexShader = shader.vertexShader.replace("#include <common>", `#include <common>
|
|
5
|
+
attribute float instanceTextureId;
|
|
6
|
+
varying float vTextureId;
|
|
7
|
+
varying vec2 vUvMeters;`);
|
|
8
|
+
shader.vertexShader = shader.vertexShader.replace("#include <uv_vertex>", `
|
|
9
|
+
#include <uv_vertex>
|
|
10
|
+
vTextureId = instanceTextureId;
|
|
11
|
+
// Derive per-instance scale (robust even if rotation were introduced)
|
|
12
|
+
vec3 col0 = vec3(instanceMatrix[0][0], instanceMatrix[0][1], instanceMatrix[0][2]);
|
|
13
|
+
vec3 col1 = vec3(instanceMatrix[1][0], instanceMatrix[1][1], instanceMatrix[1][2]);
|
|
14
|
+
vec3 col2 = vec3(instanceMatrix[2][0], instanceMatrix[2][1], instanceMatrix[2][2]);
|
|
15
|
+
float sx = length(col0);
|
|
16
|
+
float sy = length(col1);
|
|
17
|
+
float sz = length(col2);
|
|
18
|
+
float bottomY = instanceMatrix[3][1];
|
|
19
|
+
vec3 n = normal;
|
|
20
|
+
vec3 p = position;
|
|
21
|
+
// Map UVs in meters depending on face
|
|
22
|
+
if (abs(n.y) > 0.5) {
|
|
23
|
+
// top/bottom caps: tile by footprint in meters
|
|
24
|
+
vUvMeters = vec2( (p.x + 0.5) * sx, (p.z + 0.5) * sz );
|
|
25
|
+
} else if (abs(n.x) > 0.5) {
|
|
26
|
+
// faces perpendicular to X: use Z for U, world Y for V
|
|
27
|
+
vUvMeters = vec2( (p.z + 0.5) * sz, bottomY + p.y * sy );
|
|
28
|
+
} else {
|
|
29
|
+
// faces perpendicular to Z: use X for U, world Y for V
|
|
30
|
+
vUvMeters = vec2( (p.x + 0.5) * sx, bottomY + p.y * sy );
|
|
31
|
+
}
|
|
32
|
+
`);
|
|
33
|
+
shader.fragmentShader =
|
|
34
|
+
`
|
|
35
|
+
varying float vTextureId;
|
|
36
|
+
uniform sampler2DArray uTextureArray;
|
|
37
|
+
varying vec2 vUvMeters;
|
|
38
|
+
` + shader.fragmentShader;
|
|
39
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <map_fragment>", `#include <map_fragment>
|
|
40
|
+
vec4 texelColor = texture(uTextureArray, vec3(vUvMeters, vTextureId));
|
|
41
|
+
diffuseColor *= texelColor;`);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Group, Material, Object3D, Quaternion, Vector3 } from 'three';
|
|
2
|
+
import { Interpreter } from '../interpreter.js';
|
|
3
|
+
export type MeasureFunction = (target: Vector3) => void;
|
|
4
|
+
export type InstantiateFunction = (args: {
|
|
5
|
+
position: Vector3;
|
|
6
|
+
rotation: Quaternion;
|
|
7
|
+
scale: Vector3;
|
|
8
|
+
interpreter: Interpreter;
|
|
9
|
+
cell: {
|
|
10
|
+
row: number;
|
|
11
|
+
col: number;
|
|
12
|
+
center: [number, number];
|
|
13
|
+
};
|
|
14
|
+
name: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
export declare class ObjectFactory {
|
|
17
|
+
private readonly _measure;
|
|
18
|
+
private readonly _instantiate;
|
|
19
|
+
constructor(_measure: MeasureFunction | Object3D, _instantiate: InstantiateFunction);
|
|
20
|
+
measure(target: Vector3): void;
|
|
21
|
+
instantiate(args: {
|
|
22
|
+
position: Vector3;
|
|
23
|
+
rotation: Quaternion;
|
|
24
|
+
scale: Vector3;
|
|
25
|
+
interpreter: Interpreter;
|
|
26
|
+
cell: {
|
|
27
|
+
row: number;
|
|
28
|
+
col: number;
|
|
29
|
+
center: [number, number];
|
|
30
|
+
};
|
|
31
|
+
name: string;
|
|
32
|
+
}): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class PlaceGroup extends Group {
|
|
35
|
+
constructor(interpreter: Interpreter, _materialFallback?: Material);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/place/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAW,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAQ,MAAM,OAAO,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAmC/C,MAAM,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAEvD,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE;IACvC,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,UAAU,CAAA;IACpB,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,WAAW,CAAA;IACxB,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAA;IAC5D,IAAI,EAAE,MAAM,CAAA;CACb,KAAK,IAAI,CAAA;AAIV,qBAAa,aAAa;IAEtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,QAAQ,EAAE,eAAe,GAAG,QAAQ,EACpC,YAAY,EAAE,mBAAmB;IAGpD,OAAO,CAAC,MAAM,EAAE,OAAO;IAWvB,WAAW,CAAC,IAAI,EAAE;QAChB,QAAQ,EAAE,OAAO,CAAA;QACjB,QAAQ,EAAE,UAAU,CAAA;QACpB,KAAK,EAAE,OAAO,CAAA;QACd,WAAW,EAAE,WAAW,CAAA;QACxB,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SAAE,CAAA;QAC5D,IAAI,EAAE,MAAM,CAAA;KACb;CAGF;AAED,qBAAa,UAAW,SAAQ,KAAK;gBACvB,WAAW,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,QAAQ;CA0NnE"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Group, Matrix4, Object3D, Quaternion, Vector3, Box3 } from 'three';
|
|
2
|
+
import { TilesGeometry } from '../tiles/geometry.js';
|
|
3
|
+
import { coerce, object, string, enum as zodEnum } from 'zod';
|
|
4
|
+
import { createRng, hashNumbersToUint32, hashStringToUint32 } from '../utils/random.js';
|
|
5
|
+
import { degToRad } from 'three/src/math/MathUtils.js';
|
|
6
|
+
const alignEnum = zodEnum(['up', 'normal']);
|
|
7
|
+
const scatterSchema = object({
|
|
8
|
+
model: string(),
|
|
9
|
+
density: coerce.number().optional(),
|
|
10
|
+
bottomY: coerce.number().optional(),
|
|
11
|
+
yaw: coerce.number().optional(),
|
|
12
|
+
yawMin: coerce.number().optional(),
|
|
13
|
+
yawMax: coerce.number().optional(),
|
|
14
|
+
align: alignEnum.optional(),
|
|
15
|
+
sizeX: coerce.number().optional(),
|
|
16
|
+
minSizeX: coerce.number().optional(),
|
|
17
|
+
maxSizeX: coerce.number().optional(),
|
|
18
|
+
sizeZ: coerce.number().optional(),
|
|
19
|
+
minSizeZ: coerce.number().optional(),
|
|
20
|
+
maxSizeZ: coerce.number().optional(),
|
|
21
|
+
});
|
|
22
|
+
const placeSchema = object({
|
|
23
|
+
model: string(),
|
|
24
|
+
offsetX: coerce.number().optional(),
|
|
25
|
+
offsetZ: coerce.number().optional(),
|
|
26
|
+
bottomY: coerce.number().optional(),
|
|
27
|
+
yaw: coerce.number().optional(),
|
|
28
|
+
align: alignEnum.optional(),
|
|
29
|
+
sizeX: coerce.number().optional(),
|
|
30
|
+
sizeZ: coerce.number().optional(),
|
|
31
|
+
});
|
|
32
|
+
const boxHelper = new Box3();
|
|
33
|
+
export class ObjectFactory {
|
|
34
|
+
_measure;
|
|
35
|
+
_instantiate;
|
|
36
|
+
constructor(_measure, _instantiate) {
|
|
37
|
+
this._measure = _measure;
|
|
38
|
+
this._instantiate = _instantiate;
|
|
39
|
+
}
|
|
40
|
+
measure(target) {
|
|
41
|
+
if (this._measure instanceof Object3D) {
|
|
42
|
+
const parent = this._measure.parent;
|
|
43
|
+
this._measure.parent = null;
|
|
44
|
+
boxHelper.setFromObject(this._measure).getSize(target);
|
|
45
|
+
this._measure.parent = parent;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this._measure(target);
|
|
49
|
+
}
|
|
50
|
+
instantiate(args) {
|
|
51
|
+
this._instantiate(args);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export class PlaceGroup extends Group {
|
|
55
|
+
constructor(interpreter, _materialFallback) {
|
|
56
|
+
super();
|
|
57
|
+
const rows = interpreter.getRows();
|
|
58
|
+
const cols = interpreter.getCols();
|
|
59
|
+
const cellSize = interpreter.getCellSize();
|
|
60
|
+
const tilesGeometry = interpreter.getAsset(TilesGeometry, 'tilesGeometry');
|
|
61
|
+
if (!tilesGeometry) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const computeTransform = (px, pz, cell, opts) => {
|
|
65
|
+
const normal = new Vector3();
|
|
66
|
+
const offsetX = px - cell.center[0];
|
|
67
|
+
const offsetZ = pz - cell.center[1];
|
|
68
|
+
let py = 0;
|
|
69
|
+
if (opts.useFixedY) {
|
|
70
|
+
py = opts.fixedY;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
py = tilesGeometry.getHeight(cell.col, cell.row, opts.layerIndex, offsetX, offsetZ, normal);
|
|
74
|
+
}
|
|
75
|
+
const pos = new Vector3(px, py, pz);
|
|
76
|
+
const quat = new Quaternion();
|
|
77
|
+
if (opts.alignMode === 'normal' && !opts.useFixedY) {
|
|
78
|
+
const qAlign = new Quaternion().setFromUnitVectors(new Vector3(0, 1, 0), normal);
|
|
79
|
+
const qYaw = new Quaternion().setFromAxisAngle(normal, degToRad(opts.yaw));
|
|
80
|
+
quat.multiplyQuaternions(qYaw, qAlign);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
quat.setFromAxisAngle(new Vector3(0, 1, 0), degToRad(opts.yaw));
|
|
84
|
+
}
|
|
85
|
+
// Scale is handled by the factory via size
|
|
86
|
+
const scl = new Vector3(1, 1, 1);
|
|
87
|
+
const matrix = new Matrix4().compose(pos, quat, scl);
|
|
88
|
+
return { pos, quat, scl, matrix };
|
|
89
|
+
};
|
|
90
|
+
const computeScale = (usualSize, sizeX, sizeZ) => {
|
|
91
|
+
if (sizeX === undefined && sizeZ === undefined)
|
|
92
|
+
return new Vector3(1, 1, 1);
|
|
93
|
+
// Avoid division by zero
|
|
94
|
+
const safeUsualX = Math.max(usualSize.x, 0.001);
|
|
95
|
+
const safeUsualZ = Math.max(usualSize.z, 0.001);
|
|
96
|
+
let sFactorX;
|
|
97
|
+
let sFactorZ;
|
|
98
|
+
if (sizeX !== undefined) {
|
|
99
|
+
sFactorX = sizeX / safeUsualX;
|
|
100
|
+
}
|
|
101
|
+
if (sizeZ !== undefined) {
|
|
102
|
+
sFactorZ = sizeZ / safeUsualZ;
|
|
103
|
+
}
|
|
104
|
+
const scale = Math.min(sFactorX ?? sFactorZ ?? 1, sFactorZ ?? sFactorX ?? 1);
|
|
105
|
+
return new Vector3(scale, scale, scale);
|
|
106
|
+
};
|
|
107
|
+
for (let z = 0; z < rows; z++) {
|
|
108
|
+
for (let x = 0; x < cols; x++) {
|
|
109
|
+
const scatterEntries = interpreter.getCalls([z, x], {
|
|
110
|
+
scatter: scatterSchema,
|
|
111
|
+
});
|
|
112
|
+
const placeEntries = interpreter.getCalls([z, x], {
|
|
113
|
+
place: placeSchema,
|
|
114
|
+
});
|
|
115
|
+
if (scatterEntries.length === 0 && placeEntries.length === 0)
|
|
116
|
+
continue;
|
|
117
|
+
const cx = (x - cols / 2 + 0.5) * cellSize;
|
|
118
|
+
const cz = (z - rows / 2 + 0.5) * cellSize;
|
|
119
|
+
const half = cellSize * 0.5;
|
|
120
|
+
// scatter: randomized distribution, density is count for now
|
|
121
|
+
for (const [, parsed, callIdx, loc] of scatterEntries) {
|
|
122
|
+
const layerIndex = interpreter.countCalls([z, x], (c) => c.name === 'ground' || c.name === 'ceiling', 0, callIdx) - 1;
|
|
123
|
+
const factoryName = `${parsed.model}Factory`;
|
|
124
|
+
const factory = interpreter.getAsset(ObjectFactory, factoryName, loc);
|
|
125
|
+
if (!factory)
|
|
126
|
+
continue;
|
|
127
|
+
const usualSize = new Vector3();
|
|
128
|
+
factory.measure(usualSize);
|
|
129
|
+
const base = hashStringToUint32(parsed.model);
|
|
130
|
+
const seed = hashNumbersToUint32(base, z, x);
|
|
131
|
+
const rng = createRng(seed);
|
|
132
|
+
// area-based density: items per m^2
|
|
133
|
+
// expected = density * area; stochastic rounding using seeded rng
|
|
134
|
+
const densityPerSqm = Math.max(0, parsed.density ?? 1 / (usualSize.x * usualSize.z * 2));
|
|
135
|
+
const area = cellSize * cellSize;
|
|
136
|
+
const expected = densityPerSqm * area;
|
|
137
|
+
const baseCount = Math.floor(expected);
|
|
138
|
+
const fractional = expected - baseCount;
|
|
139
|
+
const count = baseCount + (rng() < fractional ? 1 : 0);
|
|
140
|
+
if (count <= 0)
|
|
141
|
+
continue;
|
|
142
|
+
const useFixedY = parsed.bottomY != null;
|
|
143
|
+
const yawMin = parsed.yawMin ?? 0;
|
|
144
|
+
const yawMax = parsed.yawMax ?? (parsed.yaw != null ? parsed.yaw : Math.PI * 2);
|
|
145
|
+
const minSizeX = parsed.minSizeX ?? parsed.sizeX ?? usualSize.x * 0.8;
|
|
146
|
+
const maxSizeX = parsed.maxSizeX ?? parsed.sizeX ?? usualSize.x * 1.2;
|
|
147
|
+
const minSizeZ = parsed.minSizeZ ?? parsed.sizeZ ?? usualSize.z * 0.8;
|
|
148
|
+
const maxSizeZ = parsed.maxSizeZ ?? parsed.sizeZ ?? usualSize.z * 1.2;
|
|
149
|
+
const alignMode = (parsed.align ?? 'up').toLowerCase();
|
|
150
|
+
for (let i = 0; i < count; i++) {
|
|
151
|
+
const ox = (rng() * 2 - 1) * half;
|
|
152
|
+
const oz = (rng() * 2 - 1) * half;
|
|
153
|
+
const px = cx + ox;
|
|
154
|
+
const pz = cz + oz;
|
|
155
|
+
const yaw = yawMin === yawMax ? yawMin : yawMin + (yawMax - yawMin) * rng();
|
|
156
|
+
const { pos, quat, scl } = computeTransform(px, pz, { row: z, col: x, center: [cx, cz] }, {
|
|
157
|
+
alignMode,
|
|
158
|
+
yaw,
|
|
159
|
+
useFixedY: useFixedY,
|
|
160
|
+
fixedY: parsed.bottomY,
|
|
161
|
+
layerIndex,
|
|
162
|
+
});
|
|
163
|
+
const sX = minSizeX !== undefined && maxSizeX !== undefined
|
|
164
|
+
? minSizeX + (maxSizeX - minSizeX) * rng()
|
|
165
|
+
: minSizeX ?? maxSizeX;
|
|
166
|
+
const sZ = minSizeZ !== undefined && maxSizeZ !== undefined
|
|
167
|
+
? minSizeZ + (maxSizeZ - minSizeZ) * rng()
|
|
168
|
+
: minSizeZ ?? maxSizeZ;
|
|
169
|
+
const scale = computeScale(usualSize, sX, sZ);
|
|
170
|
+
scl.multiply(scale);
|
|
171
|
+
factory.instantiate({
|
|
172
|
+
position: pos,
|
|
173
|
+
rotation: quat,
|
|
174
|
+
scale: scl,
|
|
175
|
+
interpreter,
|
|
176
|
+
cell: { row: z, col: x, center: [cx, cz] },
|
|
177
|
+
name: parsed.model,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// place: exact in-cell placement
|
|
182
|
+
for (const [, parsed, callIdx, loc] of placeEntries) {
|
|
183
|
+
const layerIndex = interpreter.countCalls([z, x], (c) => c.name === 'ground' || c.name === 'ceiling', 0, callIdx) - 1;
|
|
184
|
+
const px = cx + (parsed.offsetX ?? 0);
|
|
185
|
+
const pz = cz + (parsed.offsetZ ?? 0);
|
|
186
|
+
// In place command, yaw is exact, no min/max range
|
|
187
|
+
const yaw = parsed.yaw ?? 0;
|
|
188
|
+
const alignMode = (parsed.align ?? 'up').toLowerCase();
|
|
189
|
+
const { pos, quat, scl } = computeTransform(px, pz, { row: z, col: x, center: [cx, cz] }, {
|
|
190
|
+
alignMode,
|
|
191
|
+
yaw,
|
|
192
|
+
useFixedY: parsed.bottomY != null,
|
|
193
|
+
fixedY: parsed.bottomY,
|
|
194
|
+
layerIndex,
|
|
195
|
+
});
|
|
196
|
+
const factoryName = `${parsed.model}Factory`;
|
|
197
|
+
const factory = interpreter.getAsset(ObjectFactory, factoryName, loc);
|
|
198
|
+
if (!factory)
|
|
199
|
+
continue;
|
|
200
|
+
const usualSize = new Vector3();
|
|
201
|
+
factory.measure(usualSize);
|
|
202
|
+
const scale = computeScale(usualSize, parsed.sizeX, parsed.sizeZ);
|
|
203
|
+
scl.multiply(scale);
|
|
204
|
+
factory.instantiate({
|
|
205
|
+
position: pos,
|
|
206
|
+
rotation: quat,
|
|
207
|
+
scale: scl,
|
|
208
|
+
interpreter,
|
|
209
|
+
cell: { row: z, col: x, center: [cx, cz] },
|
|
210
|
+
name: parsed.model,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BufferGeometry, Vector3 } from 'three';
|
|
2
|
+
export type Tile = {
|
|
3
|
+
type: string;
|
|
4
|
+
y: number;
|
|
5
|
+
textureId: number;
|
|
6
|
+
cellIndexX: number;
|
|
7
|
+
cellIndexZ: number;
|
|
8
|
+
};
|
|
9
|
+
export type WallData = {
|
|
10
|
+
topY: number;
|
|
11
|
+
bottomY: number;
|
|
12
|
+
};
|
|
13
|
+
export declare class TilesGeometry extends BufferGeometry {
|
|
14
|
+
private readonly tiles;
|
|
15
|
+
private readonly walls;
|
|
16
|
+
readonly mapSizeX: number;
|
|
17
|
+
readonly mapSizeZ: number;
|
|
18
|
+
readonly cellSizeX: number;
|
|
19
|
+
readonly cellSizeZ: number;
|
|
20
|
+
private readonly vertices;
|
|
21
|
+
private readonly positions;
|
|
22
|
+
private readonly uvs;
|
|
23
|
+
private readonly textureStrengths;
|
|
24
|
+
private idCounter;
|
|
25
|
+
private readonly xConnections;
|
|
26
|
+
private readonly zConnections;
|
|
27
|
+
constructor(tiles: Array<Array<Array<Tile>>>, walls: Array<Array<{
|
|
28
|
+
top: Array<WallData>;
|
|
29
|
+
right: Array<WallData>;
|
|
30
|
+
bottom: Array<WallData>;
|
|
31
|
+
left: Array<WallData>;
|
|
32
|
+
}>>, mapSizeX: number, mapSizeZ: number);
|
|
33
|
+
/**
|
|
34
|
+
* @param xIndex tile grid x index
|
|
35
|
+
* @param zIndex tile grid z index
|
|
36
|
+
* @param stackIndex index in the tile stack
|
|
37
|
+
* @param offsetX world unit offset from tile center X
|
|
38
|
+
* @param offsetZ world unit offset from tile center Z
|
|
39
|
+
* @param normalTarget optional target vector that will receive the interpolated face normal at the queried point
|
|
40
|
+
*/
|
|
41
|
+
getHeight(xIndex: number, zIndex: number, stackIndex: number, offsetX: number, offsetZ: number, normalTarget?: Vector3): number;
|
|
42
|
+
private addVertex;
|
|
43
|
+
private getVertices;
|
|
44
|
+
private getConnectionVertexId;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/tiles/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAMd,OAAO,EACR,MAAM,OAAO,CAAA;AAGd,MAAM,MAAM,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAA;AAoBzG,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAkQxD,qBAAa,aAAc,SAAQ,cAAc;IAe7C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;aAQN,QAAQ,EAAE,MAAM;aAChB,QAAQ,EAAE,MAAM;IAxBlC,SAAgB,SAAS,EAAE,MAAM,CAAA;IACjC,SAAgB,SAAS,EAAE,MAAM,CAAA;IAEjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAErD,OAAO,CAAC,SAAS,CAAI;IAErB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;IAChE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;gBAG7C,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAChC,KAAK,EAAE,KAAK,CAC3B,KAAK,CAAC;QACJ,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;QACpB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;QACtB,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;QACvB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;KACtB,CAAC,CACH,EACe,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;IA0ElC;;;;;;;OAOG;IACI,SAAS,CACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,OAAO;IAmFxB,OAAO,CAAC,SAAS;IAoGjB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,qBAAqB;CAsB9B"}
|