@iwsdk/create 1.1.0-rc.1 → 1.1.0-rc.2
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/dist/cli.js +8 -13
- package/dist/guidance/agents/.agents/skills/iwsdk-compose-scene/SKILL.md +16 -2
- package/dist/guidance/agents/.agents/skills/iwsdk-compose-scene/references/environment-recipes.md +234 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-compose-scene/references/scene-format.md +6 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-dev/references/api-reference.md +56 -33
- package/dist/guidance/agents/.agents/skills/iwsdk-dev/references/iterate.md +24 -5
- package/dist/guidance/agents/.agents/skills/iwsdk-glasses-test/SKILL.md +281 -0
- package/dist/guidance/agents/.agents/skills/iwsdk-grab/SKILL.md +24 -1
- package/dist/guidance/agents/.agents/skills/iwsdk-ray/SKILL.md +3 -1
- package/dist/guidance/agents/.agents/skills/iwsdk-ui/SKILL.md +25 -2
- package/dist/guidance/claude/.claude/agents/iwsdk-project-code-reviewer.md +73 -6
- package/dist/guidance/claude/.claude/rules/assets-and-manifest.md +2 -0
- package/dist/guidance/claude/.claude/rules/ecs-api.md +1 -1
- package/dist/guidance/claude/.claude/rules/scene-json.md +3 -1
- package/dist/guidance/claude/.claude/rules/uikitml.md +5 -0
- package/dist/guidance/claude/.claude/settings.json +1 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-compose-scene/SKILL.md +16 -2
- package/dist/guidance/claude/.claude/skills/iwsdk-compose-scene/references/environment-recipes.md +234 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-compose-scene/references/scene-format.md +6 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-dev/references/api-reference.md +56 -33
- package/dist/guidance/claude/.claude/skills/iwsdk-dev/references/iterate.md +24 -5
- package/dist/guidance/claude/.claude/skills/iwsdk-glasses-test/SKILL.md +281 -0
- package/dist/guidance/claude/.claude/skills/iwsdk-grab/SKILL.md +24 -1
- package/dist/guidance/claude/.claude/skills/iwsdk-ray/SKILL.md +3 -1
- package/dist/guidance/claude/.claude/skills/iwsdk-ui/SKILL.md +25 -2
- package/dist/guidance/common/AGENTS.md +25 -12
- package/dist/guidance/copilot/.github/instructions/assets-and-manifest.instructions.md +2 -0
- package/dist/guidance/copilot/.github/instructions/ecs-api.instructions.md +1 -1
- package/dist/guidance/copilot/.github/instructions/scene-json.instructions.md +3 -1
- package/dist/guidance/copilot/.github/instructions/uikitml.instructions.md +5 -0
- package/dist/guidance/cursor/.cursor/rules/assets-and-manifest.mdc +2 -0
- package/dist/guidance/cursor/.cursor/rules/ecs-api.mdc +1 -1
- package/dist/guidance/cursor/.cursor/rules/scene-json.mdc +3 -1
- package/dist/guidance/cursor/.cursor/rules/uikitml.mdc +5 -0
- package/dist/guidance/scoped-agents/public/scenes/AGENTS.md +3 -1
- package/dist/guidance/scoped-agents/public/ui/AGENTS.md +5 -0
- package/dist/guidance/scoped-agents/src/AGENTS.md +3 -1
- package/dist/template/common/README.md +19 -0
- package/dist/template/common/public/ui/label-grab.uikitml +57 -0
- package/dist/template/common/public/ui/label-select.uikitml +57 -0
- package/dist/template/common/public/ui/label-spin.uikitml +57 -0
- package/dist/template/common/public/ui/welcome.uikitml +33 -32
- package/dist/template/common/src/assets.ts +32 -23
- package/dist/template/common/src/scene-assets/decor.scene-asset.ts +781 -0
- package/dist/template/common/src/scene-assets/studio.scene-asset.ts +298 -0
- package/dist/template/common-js/README.md +19 -0
- package/dist/template/common-js/public/ui/label-grab.uikitml +57 -0
- package/dist/template/common-js/public/ui/label-select.uikitml +57 -0
- package/dist/template/common-js/public/ui/label-spin.uikitml +57 -0
- package/dist/template/common-js/public/ui/welcome.uikitml +33 -32
- package/dist/template/common-js/src/assets.js +20 -23
- package/dist/template/common-js/src/scene-assets/decor.scene-asset.js +554 -0
- package/dist/template/common-js/src/scene-assets/studio.scene-asset.js +236 -0
- package/dist/template/scenes/ar.iwsdk.scene.json +354 -58
- package/dist/template/scenes/immersive.iwsdk.scene.json +435 -54
- package/package.json +4 -4
- package/dist/template/common/public/gltf/webxr-banner/banner.gltf +0 -68
- package/dist/template/common/public/textures/webxr.png +0 -0
- package/dist/template/common-js/public/gltf/webxr-banner/banner.gltf +0 -68
- package/dist/template/common-js/public/textures/webxr.png +0 -0
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { createSceneMaterial, createScenePrimitiveObject, DataTexture, Group, LinearFilter, LinearMipmapLinearFilter, Mesh, MeshStandardMaterial, RGBAFormat, SRGBColorSpace, TorusGeometry, UnsignedByteType, } from '@iwsdk/core';
|
|
8
|
+
/**
|
|
9
|
+
* Background furniture for the VR and Desktop 3D starters, built in code so
|
|
10
|
+
* the starter downloads no extra models. Everything here is light on purpose:
|
|
11
|
+
* dark graphite is kept for things you can interact with. It is safe to
|
|
12
|
+
* delete this file together with the gallery-set and sideboard-set entries in
|
|
13
|
+
* src/assets.ts and their scene nodes.
|
|
14
|
+
*/
|
|
15
|
+
// Small seeded random generator (mulberry32), so the marble comes out the
|
|
16
|
+
// same on every load.
|
|
17
|
+
function seededRandom(seed) {
|
|
18
|
+
let state = seed >>> 0;
|
|
19
|
+
return () => {
|
|
20
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
21
|
+
let t = state;
|
|
22
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
23
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
24
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The marble as drawing steps: faint gray clouds, then veins that wander
|
|
29
|
+
* diagonally and now and then split off a thinner branch. Every vein run is
|
|
30
|
+
* a pair of strokes, a faint wide halo and then a thin line.
|
|
31
|
+
*/
|
|
32
|
+
function marbleDrawing(seed, size) {
|
|
33
|
+
const random = seededRandom(seed);
|
|
34
|
+
const clouds = [];
|
|
35
|
+
for (let index = 0; index < 12; index += 1) {
|
|
36
|
+
const x = random() * size;
|
|
37
|
+
const y = random() * size;
|
|
38
|
+
const radius = size * (0.15 + random() * 0.3);
|
|
39
|
+
clouds.push({ x, y, radius });
|
|
40
|
+
}
|
|
41
|
+
const strokes = [];
|
|
42
|
+
const step = size / 200;
|
|
43
|
+
const vein = (x, y, heading, length, width, alpha) => {
|
|
44
|
+
const points = [[x, y]];
|
|
45
|
+
let angle = heading;
|
|
46
|
+
for (let travelled = 0; travelled < length; travelled += step) {
|
|
47
|
+
// Wander, but keep drifting back toward the heading.
|
|
48
|
+
angle += (random() - 0.5) * 0.45 + (heading - angle) * 0.1;
|
|
49
|
+
x += Math.cos(angle) * step;
|
|
50
|
+
y += Math.sin(angle) * step;
|
|
51
|
+
points.push([x, y]);
|
|
52
|
+
if (width > 0.9 && random() < 0.025) {
|
|
53
|
+
const side = random() < 0.5 ? -1 : 1;
|
|
54
|
+
vein(x, y, angle + side * (0.35 + random() * 0.5), length * (0.12 + random() * 0.25), width * 0.6, alpha * 0.85);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Short runs of varying width, each a faint halo under a thin line.
|
|
58
|
+
for (let index = 0; index < points.length - 1; index += 6) {
|
|
59
|
+
const run = points.slice(index, index + 7);
|
|
60
|
+
const runWidth = width * (0.35 + random());
|
|
61
|
+
strokes.push({ run, width: runWidth * 6, alpha: alpha * 0.07 });
|
|
62
|
+
strokes.push({ run, width: runWidth, alpha });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// Main veins start on a line across the flow, spaced to cover the slab.
|
|
66
|
+
const heading = 0.55;
|
|
67
|
+
const [dx, dy] = [Math.cos(heading), Math.sin(heading)];
|
|
68
|
+
for (let index = 0; index < 4; index += 1) {
|
|
69
|
+
const offset = ((index + 0.2 + 0.6 * random()) / 4 - 0.5) * 1.5 * size;
|
|
70
|
+
vein(size / 2 - dx * 0.8 * size - dy * offset, size / 2 - dy * 0.8 * size + dx * offset, heading + (random() - 0.5) * 0.4, size * 1.6, 2.2, 0.45);
|
|
71
|
+
}
|
|
72
|
+
// Hairline veins.
|
|
73
|
+
for (let index = 0; index < 12; index += 1) {
|
|
74
|
+
vein((random() * 1.2 - 0.2) * size, (random() * 1.2 - 0.2) * size, heading + (random() - 0.5) * 1.2, size * (0.3 + random() * 0.6), 0.8, 0.22);
|
|
75
|
+
}
|
|
76
|
+
return { clouds, strokes };
|
|
77
|
+
}
|
|
78
|
+
/** Blend `color` over one texel at `alpha`, in sRGB as a 2D canvas does. */
|
|
79
|
+
function blend(canvas, texel, color, alpha) {
|
|
80
|
+
const { rgb } = canvas;
|
|
81
|
+
const index = texel * 3;
|
|
82
|
+
rgb[index] += (color[0] - rgb[index]) * alpha;
|
|
83
|
+
rgb[index + 1] += (color[1] - rgb[index + 1]) * alpha;
|
|
84
|
+
rgb[index + 2] += (color[2] - rgb[index + 2]) * alpha;
|
|
85
|
+
}
|
|
86
|
+
function clampTexel(canvas, value) {
|
|
87
|
+
return Math.min(canvas.size - 1, Math.max(0, Math.floor(value)));
|
|
88
|
+
}
|
|
89
|
+
/** A radial cloud that fades out linearly from `alpha` to its rim. */
|
|
90
|
+
function paintCloud(canvas, cloud, color, alpha) {
|
|
91
|
+
const { size, scale } = canvas;
|
|
92
|
+
const x = cloud.x * scale;
|
|
93
|
+
const y = cloud.y * scale;
|
|
94
|
+
const radius = cloud.radius * scale;
|
|
95
|
+
const bottom = clampTexel(canvas, y + radius + 1);
|
|
96
|
+
for (let py = clampTexel(canvas, y - radius); py <= bottom; py += 1) {
|
|
97
|
+
const dy = py + 0.5 - y;
|
|
98
|
+
if (Math.abs(dy) >= radius) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const half = Math.sqrt(radius * radius - dy * dy);
|
|
102
|
+
const right = clampTexel(canvas, x + half + 0.5);
|
|
103
|
+
for (let px = clampTexel(canvas, x - half - 0.5); px <= right; px += 1) {
|
|
104
|
+
const dx = px + 0.5 - x;
|
|
105
|
+
const t = Math.sqrt(dx * dx + dy * dy) / radius;
|
|
106
|
+
if (t < 1) {
|
|
107
|
+
blend(canvas, py * size + px, color, alpha * (1 - t));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A halo and a line stroked along the same run, with round caps and joins
|
|
114
|
+
* like a canvas path. A texel's coverage comes from its distance to the run,
|
|
115
|
+
* with a one-texel antialiased edge, and each segment only measures the
|
|
116
|
+
* texels it can reach.
|
|
117
|
+
*/
|
|
118
|
+
function paintStrokePair(canvas, halo, line, color) {
|
|
119
|
+
const { size, scale } = canvas;
|
|
120
|
+
const run = halo.run.map(([x, y]) => [x * scale, y * scale]);
|
|
121
|
+
const haloRadius = (halo.width * scale) / 2;
|
|
122
|
+
const lineRadius = (line.width * scale) / 2;
|
|
123
|
+
const reach = haloRadius + 1;
|
|
124
|
+
const xs = run.map(([x]) => x);
|
|
125
|
+
const ys = run.map(([, y]) => y);
|
|
126
|
+
const [minX, maxX] = [Math.min(...xs), Math.max(...xs)];
|
|
127
|
+
const [minY, maxY] = [Math.min(...ys), Math.max(...ys)];
|
|
128
|
+
if (maxX + reach < 0 ||
|
|
129
|
+
maxY + reach < 0 ||
|
|
130
|
+
minX - reach >= size ||
|
|
131
|
+
minY - reach >= size) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const left = clampTexel(canvas, minX - reach);
|
|
135
|
+
const top = clampTexel(canvas, minY - reach);
|
|
136
|
+
const width = clampTexel(canvas, maxX + reach) - left + 1;
|
|
137
|
+
const height = clampTexel(canvas, maxY + reach) - top + 1;
|
|
138
|
+
const nearest = new Float32Array(width * height).fill(Infinity);
|
|
139
|
+
for (let point = 0; point < run.length - 1; point += 1) {
|
|
140
|
+
const [ax, ay] = run[point];
|
|
141
|
+
const [bx, by] = run[point + 1];
|
|
142
|
+
const ex = bx - ax;
|
|
143
|
+
const ey = by - ay;
|
|
144
|
+
const lengthSq = ex * ex + ey * ey;
|
|
145
|
+
const x0 = clampTexel(canvas, Math.min(ax, bx) - reach);
|
|
146
|
+
const x1 = clampTexel(canvas, Math.max(ax, bx) + reach);
|
|
147
|
+
const y0 = clampTexel(canvas, Math.min(ay, by) - reach);
|
|
148
|
+
const y1 = clampTexel(canvas, Math.max(ay, by) + reach);
|
|
149
|
+
for (let py = y0; py <= y1; py += 1) {
|
|
150
|
+
const qy = py + 0.5;
|
|
151
|
+
for (let px = x0; px <= x1; px += 1) {
|
|
152
|
+
const qx = px + 0.5;
|
|
153
|
+
let along = lengthSq > 0 ? ((qx - ax) * ex + (qy - ay) * ey) / lengthSq : 0;
|
|
154
|
+
along = along < 0 ? 0 : along > 1 ? 1 : along;
|
|
155
|
+
const fx = ax + ex * along - qx;
|
|
156
|
+
const fy = ay + ey * along - qy;
|
|
157
|
+
const slot = (py - top) * width + (px - left);
|
|
158
|
+
nearest[slot] = Math.min(nearest[slot], fx * fx + fy * fy);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (let row = 0; row < height; row += 1) {
|
|
163
|
+
for (let column = 0; column < width; column += 1) {
|
|
164
|
+
const distance = Math.sqrt(nearest[row * width + column]);
|
|
165
|
+
const texel = (top + row) * size + left + column;
|
|
166
|
+
const haloCover = haloRadius + 0.5 - distance;
|
|
167
|
+
if (haloCover > 0) {
|
|
168
|
+
blend(canvas, texel, color, halo.alpha * Math.min(1, haloCover));
|
|
169
|
+
}
|
|
170
|
+
const lineCover = lineRadius + 0.5 - distance;
|
|
171
|
+
if (lineCover > 0) {
|
|
172
|
+
blend(canvas, texel, color, line.alpha * Math.min(1, lineCover));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** Canvas rows run top down; texture rows run bottom up. */
|
|
178
|
+
function toTexturePixels({ rgb, size }) {
|
|
179
|
+
const pixels = new Uint8Array(size * size * 4);
|
|
180
|
+
for (let y = 0; y < size; y += 1) {
|
|
181
|
+
for (let x = 0; x < size; x += 1) {
|
|
182
|
+
const source = (y * size + x) * 3;
|
|
183
|
+
const target = ((size - 1 - y) * size + x) * 4;
|
|
184
|
+
pixels[target] = Math.round(rgb[source] * 255);
|
|
185
|
+
pixels[target + 1] = Math.round(rgb[source + 1] * 255);
|
|
186
|
+
pixels[target + 2] = Math.round(rgb[source + 2] * 255);
|
|
187
|
+
pixels[target + 3] = 255;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return pixels;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* White marble painted once into a pixel buffer, blending each step over the
|
|
194
|
+
* last as a 2D canvas does, so it needs no DOM. It is drawn on a 1024 px
|
|
195
|
+
* canvas and painted at `size`: 512 px keeps the load time down and looks the
|
|
196
|
+
* same at viewing distance, where the block samples small mips.
|
|
197
|
+
*/
|
|
198
|
+
function createMarbleTexture(seed = 9, size = 512) {
|
|
199
|
+
const { clouds, strokes } = marbleDrawing(seed, 1024);
|
|
200
|
+
const canvas = {
|
|
201
|
+
rgb: new Float32Array(size * size * 3),
|
|
202
|
+
size,
|
|
203
|
+
scale: size / 1024,
|
|
204
|
+
};
|
|
205
|
+
const background = [0xf2 / 255, 0xf1 / 255, 0xee / 255];
|
|
206
|
+
for (let index = 0; index < canvas.rgb.length; index += 1) {
|
|
207
|
+
canvas.rgb[index] = background[index % 3];
|
|
208
|
+
}
|
|
209
|
+
const cloudColor = [208 / 255, 210 / 255, 217 / 255];
|
|
210
|
+
for (const cloud of clouds) {
|
|
211
|
+
paintCloud(canvas, cloud, cloudColor, 0.2);
|
|
212
|
+
}
|
|
213
|
+
const veinColor = [128 / 255, 132 / 255, 142 / 255];
|
|
214
|
+
for (let index = 0; index < strokes.length; index += 2) {
|
|
215
|
+
paintStrokePair(canvas, strokes[index], strokes[index + 1], veinColor);
|
|
216
|
+
}
|
|
217
|
+
const texture = new DataTexture(toTexturePixels(canvas), size, size, RGBAFormat, UnsignedByteType);
|
|
218
|
+
texture.colorSpace = SRGBColorSpace;
|
|
219
|
+
texture.magFilter = LinearFilter;
|
|
220
|
+
texture.minFilter = LinearMipmapLinearFilter;
|
|
221
|
+
texture.generateMipmaps = true;
|
|
222
|
+
texture.anisotropy = 8;
|
|
223
|
+
texture.needsUpdate = true;
|
|
224
|
+
return texture;
|
|
225
|
+
}
|
|
226
|
+
const marble = new MeshStandardMaterial({
|
|
227
|
+
map: createMarbleTexture(),
|
|
228
|
+
roughness: 0.3,
|
|
229
|
+
});
|
|
230
|
+
const wood = createSceneMaterial({
|
|
231
|
+
id: 'decor-wood',
|
|
232
|
+
model: 'standard',
|
|
233
|
+
roughness: 0.7,
|
|
234
|
+
textures: {
|
|
235
|
+
albedo: {
|
|
236
|
+
type: 'procedural',
|
|
237
|
+
algorithm: 'periodic-fbm-v1',
|
|
238
|
+
resolution: [128, 512],
|
|
239
|
+
seed: 5,
|
|
240
|
+
bands: [
|
|
241
|
+
{ frequency: [2, 36], amplitude: 0.7 },
|
|
242
|
+
{ frequency: [4, 90], amplitude: 0.3 },
|
|
243
|
+
],
|
|
244
|
+
ramp: [
|
|
245
|
+
{ at: 0, color: '#DCCBAF' },
|
|
246
|
+
{ at: 1, color: '#ECDFC8' },
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
const sandClay = createSceneMaterial({
|
|
252
|
+
id: 'decor-sand-clay',
|
|
253
|
+
model: 'physical',
|
|
254
|
+
roughness: 0.86,
|
|
255
|
+
sheen: 0.35,
|
|
256
|
+
sheenColor: '#FFFFFF',
|
|
257
|
+
sheenRoughness: 0.8,
|
|
258
|
+
textures: {
|
|
259
|
+
albedo: {
|
|
260
|
+
type: 'procedural',
|
|
261
|
+
algorithm: 'periodic-fbm-v1',
|
|
262
|
+
resolution: [256, 256],
|
|
263
|
+
seed: 21,
|
|
264
|
+
bands: [
|
|
265
|
+
{ frequency: [6, 6], amplitude: 0.6 },
|
|
266
|
+
{ frequency: [28, 28], amplitude: 0.4 },
|
|
267
|
+
],
|
|
268
|
+
ramp: [
|
|
269
|
+
{ at: 0, color: '#C4AD8A' },
|
|
270
|
+
{ at: 1, color: '#DCC8A8' },
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
bump: {
|
|
274
|
+
type: 'procedural',
|
|
275
|
+
algorithm: 'periodic-fbm-v1',
|
|
276
|
+
resolution: [256, 256],
|
|
277
|
+
seed: 11,
|
|
278
|
+
bands: [
|
|
279
|
+
{ frequency: [24, 24], amplitude: 0.6 },
|
|
280
|
+
{ frequency: [64, 64], amplitude: 0.4 },
|
|
281
|
+
],
|
|
282
|
+
scale: 0.3,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
const brass = createSceneMaterial({
|
|
287
|
+
id: 'decor-brass',
|
|
288
|
+
model: 'standard',
|
|
289
|
+
baseColor: '#C9A46A',
|
|
290
|
+
metalness: 0.85,
|
|
291
|
+
roughness: 0.32,
|
|
292
|
+
});
|
|
293
|
+
const porcelain = createSceneMaterial({
|
|
294
|
+
id: 'decor-porcelain',
|
|
295
|
+
model: 'physical',
|
|
296
|
+
baseColor: '#F4F2EE',
|
|
297
|
+
roughness: 0.25,
|
|
298
|
+
clearcoat: 0.5,
|
|
299
|
+
clearcoatRoughness: 0.1,
|
|
300
|
+
// Open-ended shapes show their glazed inside.
|
|
301
|
+
side: 'double',
|
|
302
|
+
});
|
|
303
|
+
const linen = createSceneMaterial({
|
|
304
|
+
id: 'decor-linen',
|
|
305
|
+
model: 'standard',
|
|
306
|
+
baseColor: '#F3EEE6',
|
|
307
|
+
roughness: 0.95,
|
|
308
|
+
emissive: '#FFF4E2',
|
|
309
|
+
emissiveIntensity: 0.12,
|
|
310
|
+
side: 'double',
|
|
311
|
+
});
|
|
312
|
+
const paper = createSceneMaterial({
|
|
313
|
+
id: 'decor-paper',
|
|
314
|
+
model: 'standard',
|
|
315
|
+
baseColor: '#F3EFE7',
|
|
316
|
+
roughness: 0.9,
|
|
317
|
+
});
|
|
318
|
+
const glaze = (id, color) => createSceneMaterial({
|
|
319
|
+
id,
|
|
320
|
+
model: 'physical',
|
|
321
|
+
baseColor: color,
|
|
322
|
+
roughness: 0.35,
|
|
323
|
+
clearcoat: 0.6,
|
|
324
|
+
clearcoatRoughness: 0.2,
|
|
325
|
+
});
|
|
326
|
+
const cover = (id, color) => createSceneMaterial({
|
|
327
|
+
id,
|
|
328
|
+
model: 'standard',
|
|
329
|
+
baseColor: color,
|
|
330
|
+
roughness: 0.8,
|
|
331
|
+
});
|
|
332
|
+
function part(geometry, material, x = 0, y = 0, z = 0) {
|
|
333
|
+
const mesh = createScenePrimitiveObject({ geometry }, material);
|
|
334
|
+
mesh.position.set(x, y, z);
|
|
335
|
+
return mesh;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Horn-like crescent for the sculpture. It rises from a thin tip at y = 0,
|
|
339
|
+
* curls over and ends in a thick, rounded end that hangs in the air.
|
|
340
|
+
*/
|
|
341
|
+
function horn(radius, tube, material) {
|
|
342
|
+
const lift = radius * 0.6;
|
|
343
|
+
// The tip dips just below y = 0; the free end hangs a little above the
|
|
344
|
+
// center of the curl.
|
|
345
|
+
const start = -Math.asin(0.6) - 0.06;
|
|
346
|
+
const end = Math.PI - 0.15;
|
|
347
|
+
const segments = 72;
|
|
348
|
+
const geometry = new TorusGeometry(radius, tube, 16, segments, end - start);
|
|
349
|
+
const position = geometry.attributes.position;
|
|
350
|
+
for (let index = 0; index < position.count; index += 1) {
|
|
351
|
+
// Vertices run along the arc in rows of segments + 1.
|
|
352
|
+
const along = (index % (segments + 1)) / segments;
|
|
353
|
+
const angle = along * (end - start);
|
|
354
|
+
const centerX = radius * Math.cos(angle);
|
|
355
|
+
const centerY = radius * Math.sin(angle);
|
|
356
|
+
const taper = 0.1 + 0.9 * along ** 0.6;
|
|
357
|
+
position.setXYZ(index, centerX + (position.getX(index) - centerX) * taper, centerY + (position.getY(index) - centerY) * taper, position.getZ(index) * taper);
|
|
358
|
+
}
|
|
359
|
+
const body = new Mesh(geometry, material);
|
|
360
|
+
body.rotation.z = start;
|
|
361
|
+
body.position.y = lift;
|
|
362
|
+
const cap = createScenePrimitiveObject({ geometry: { type: 'sphere', radius: tube, segments: 24 } }, material);
|
|
363
|
+
cap.position.set(radius * Math.cos(end), lift + radius * Math.sin(end), 0);
|
|
364
|
+
const result = new Group();
|
|
365
|
+
result.add(body, cap);
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
/** Tall glazed floor vase, about 0.55 m. */
|
|
369
|
+
function floorVase(material) {
|
|
370
|
+
return part({
|
|
371
|
+
type: 'lathe',
|
|
372
|
+
profile: [
|
|
373
|
+
[0.001, 0],
|
|
374
|
+
[0.085, 0],
|
|
375
|
+
[0.1, 0.012],
|
|
376
|
+
[0.135, 0.1],
|
|
377
|
+
[0.15, 0.2],
|
|
378
|
+
[0.14, 0.3],
|
|
379
|
+
[0.1, 0.4],
|
|
380
|
+
[0.064, 0.46],
|
|
381
|
+
[0.057, 0.5],
|
|
382
|
+
[0.066, 0.54],
|
|
383
|
+
[0.07, 0.55],
|
|
384
|
+
[0.06, 0.55],
|
|
385
|
+
[0.048, 0.5],
|
|
386
|
+
[0.001, 0.48],
|
|
387
|
+
],
|
|
388
|
+
segments: 64,
|
|
389
|
+
}, material);
|
|
390
|
+
}
|
|
391
|
+
/** One closed book lying flat, spine toward -x. */
|
|
392
|
+
function book(size, coverMaterial) {
|
|
393
|
+
const [width, thickness, depth] = size;
|
|
394
|
+
const board = 0.003;
|
|
395
|
+
const result = new Group();
|
|
396
|
+
result.add(part({
|
|
397
|
+
type: 'box',
|
|
398
|
+
size: [width - 0.008, thickness - board * 2, depth - 0.008],
|
|
399
|
+
}, paper, 0.004), part({ type: 'box', size: [width, board, depth] }, coverMaterial, 0, (thickness - board) / 2), part({ type: 'box', size: [width, board, depth] }, coverMaterial, 0, -(thickness - board) / 2), part({ type: 'box', size: [board * 1.5, thickness, depth] }, coverMaterial, -width / 2 + board * 0.75));
|
|
400
|
+
return result;
|
|
401
|
+
}
|
|
402
|
+
function bookStack() {
|
|
403
|
+
const stack = new Group();
|
|
404
|
+
const books = [
|
|
405
|
+
[[0.27, 0.034, 0.2], cover('decor-cover-sand', '#D8CBB8'), 0.06],
|
|
406
|
+
[[0.25, 0.026, 0.18], cover('decor-cover-sage', '#BFC8BC'), -0.1],
|
|
407
|
+
[[0.23, 0.03, 0.17], cover('decor-cover-bone', '#E7E2D8'), 0.14],
|
|
408
|
+
];
|
|
409
|
+
let y = 0;
|
|
410
|
+
for (const [size, material, turn] of books) {
|
|
411
|
+
const next = book(size, material);
|
|
412
|
+
next.position.y = y + size[1] / 2;
|
|
413
|
+
next.rotation.y = turn;
|
|
414
|
+
stack.add(next);
|
|
415
|
+
y += size[1];
|
|
416
|
+
}
|
|
417
|
+
return stack;
|
|
418
|
+
}
|
|
419
|
+
function floorLamp() {
|
|
420
|
+
const lamp = new Group();
|
|
421
|
+
const shadeBottom = 1.33;
|
|
422
|
+
const shadeHeight = 0.27;
|
|
423
|
+
// An open frustum: the linen is double-sided, so its inside shows too.
|
|
424
|
+
const shade = part({
|
|
425
|
+
type: 'lathe',
|
|
426
|
+
profile: [
|
|
427
|
+
[0.21, 0],
|
|
428
|
+
[0.19, shadeHeight],
|
|
429
|
+
],
|
|
430
|
+
segments: 48,
|
|
431
|
+
}, linen, 0, shadeBottom);
|
|
432
|
+
const trims = [0.19, 0.21].map((radius, index) => {
|
|
433
|
+
const trim = part({
|
|
434
|
+
type: 'torus',
|
|
435
|
+
radius,
|
|
436
|
+
tube: 0.004,
|
|
437
|
+
radialSegments: 6,
|
|
438
|
+
tubularSegments: 64,
|
|
439
|
+
}, brass, 0, shadeBottom + shadeHeight * (1 - index));
|
|
440
|
+
trim.rotation.x = Math.PI / 2;
|
|
441
|
+
return trim;
|
|
442
|
+
});
|
|
443
|
+
lamp.add(part({
|
|
444
|
+
type: 'lathe',
|
|
445
|
+
profile: [
|
|
446
|
+
[0.001, 0],
|
|
447
|
+
[0.15, 0],
|
|
448
|
+
[0.155, 0.006],
|
|
449
|
+
[0.15, 0.016],
|
|
450
|
+
[0.02, 0.024],
|
|
451
|
+
[0.001, 0.024],
|
|
452
|
+
],
|
|
453
|
+
segments: 48,
|
|
454
|
+
}, brass), part({ type: 'cylinder', radius: 0.009, height: 1.42, segments: 12 }, brass, 0, 0.734), shade, ...trims);
|
|
455
|
+
return lamp;
|
|
456
|
+
}
|
|
457
|
+
/** Marble block with a sand clay sculpture of two horns, and a floor vase. */
|
|
458
|
+
export function createGallerySet() {
|
|
459
|
+
const set = new Group();
|
|
460
|
+
const height = 0.84;
|
|
461
|
+
const block = part({
|
|
462
|
+
type: 'roundedBox',
|
|
463
|
+
size: [1.2, height, 0.56],
|
|
464
|
+
radius: 0.012,
|
|
465
|
+
segments: 3,
|
|
466
|
+
}, marble, 0, height / 2);
|
|
467
|
+
block.name = 'marble-block';
|
|
468
|
+
set.add(block);
|
|
469
|
+
// Two mirrored horns whose tips cross over the middle of the block.
|
|
470
|
+
for (const side of [-1, 1]) {
|
|
471
|
+
const next = horn(0.21, 0.05, sandClay);
|
|
472
|
+
next.name = side < 0 ? 'horn-left' : 'horn-right';
|
|
473
|
+
next.position.set(side * 0.087, height, 0);
|
|
474
|
+
next.rotation.y = side < 0 ? 0.3 : Math.PI - 0.3;
|
|
475
|
+
set.add(next);
|
|
476
|
+
}
|
|
477
|
+
const vase = floorVase(glaze('decor-glaze-rose', '#CDA893'));
|
|
478
|
+
vase.name = 'vase';
|
|
479
|
+
vase.position.set(-0.95, 0, -0.15);
|
|
480
|
+
vase.scale.setScalar(1.25);
|
|
481
|
+
set.add(vase);
|
|
482
|
+
return set;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Pale wood sideboard with brass pulls, a porcelain vase and books on top,
|
|
486
|
+
* and a floor lamp at its right.
|
|
487
|
+
*/
|
|
488
|
+
export function createSideboardSet() {
|
|
489
|
+
const set = new Group();
|
|
490
|
+
const legHeight = 0.22;
|
|
491
|
+
const width = 1.8;
|
|
492
|
+
const depth = 0.45;
|
|
493
|
+
const top = 0.84;
|
|
494
|
+
const front = depth / 2 + 0.008;
|
|
495
|
+
const cabinet = part({
|
|
496
|
+
type: 'roundedBox',
|
|
497
|
+
size: [width, top - legHeight, depth],
|
|
498
|
+
radius: 0.012,
|
|
499
|
+
segments: 3,
|
|
500
|
+
}, wood, 0, (top + legHeight) / 2);
|
|
501
|
+
cabinet.name = 'cabinet';
|
|
502
|
+
set.add(cabinet);
|
|
503
|
+
for (const side of [-1, 1]) {
|
|
504
|
+
const x = side * 0.4475;
|
|
505
|
+
set.add(
|
|
506
|
+
// Drawer, door and their pulls.
|
|
507
|
+
part({
|
|
508
|
+
type: 'roundedBox',
|
|
509
|
+
size: [0.885, 0.15, 0.016],
|
|
510
|
+
radius: 0.004,
|
|
511
|
+
segments: 2,
|
|
512
|
+
}, wood, x, top - 0.087, front), part({
|
|
513
|
+
type: 'roundedBox',
|
|
514
|
+
size: [0.885, 0.43, 0.016],
|
|
515
|
+
radius: 0.004,
|
|
516
|
+
segments: 2,
|
|
517
|
+
}, wood, x, legHeight + 0.227, front));
|
|
518
|
+
const drawerPull = part({ type: 'cylinder', radius: 0.0055, height: 0.2, segments: 10 }, brass, x, top - 0.05, front + 0.014);
|
|
519
|
+
drawerPull.rotation.z = Math.PI / 2;
|
|
520
|
+
set.add(drawerPull, part({ type: 'cylinder', radius: 0.0055, height: 0.2, segments: 10 }, brass, side * 0.045, legHeight + 0.3, front + 0.014));
|
|
521
|
+
for (const end of [-1, 1]) {
|
|
522
|
+
const leg = part({
|
|
523
|
+
type: 'cylinder',
|
|
524
|
+
radiusTop: 0.02,
|
|
525
|
+
radiusBottom: 0.011,
|
|
526
|
+
height: 0.25,
|
|
527
|
+
segments: 12,
|
|
528
|
+
}, wood, side * 0.8, legHeight - 0.115, end * 0.16);
|
|
529
|
+
// Splay each leg out from its corner.
|
|
530
|
+
leg.rotation.set(-end * 0.08, 0, side * 0.12);
|
|
531
|
+
set.add(leg);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
// A half-ring turned upside down makes a U-shaped vase.
|
|
535
|
+
const vase = part({
|
|
536
|
+
type: 'torus',
|
|
537
|
+
radius: 0.075,
|
|
538
|
+
tube: 0.04,
|
|
539
|
+
radialSegments: 20,
|
|
540
|
+
tubularSegments: 48,
|
|
541
|
+
arcDeg: 180,
|
|
542
|
+
}, porcelain);
|
|
543
|
+
vase.name = 'vase';
|
|
544
|
+
vase.rotation.z = Math.PI;
|
|
545
|
+
vase.position.set(-0.45, top + 0.11, 0);
|
|
546
|
+
const books = bookStack();
|
|
547
|
+
books.name = 'books';
|
|
548
|
+
books.position.set(0.42, top, 0.02);
|
|
549
|
+
const lamp = floorLamp();
|
|
550
|
+
lamp.name = 'floor-lamp';
|
|
551
|
+
lamp.position.set(1.1, 0, -0.08);
|
|
552
|
+
set.add(vase, books, lamp);
|
|
553
|
+
return set;
|
|
554
|
+
}
|