nova64 0.2.4 → 0.2.6
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/README.md +25 -8
- package/bin/nova64.js +165 -0
- package/dist/assets/console-CY_kygm3.js +14 -0
- package/dist/assets/console-CY_kygm3.js.map +1 -0
- package/dist/assets/main-l0sNRNKZ.js.map +1 -0
- package/dist/assets/sky/studio/nx.png +0 -0
- package/dist/assets/sky/studio/ny.png +0 -0
- package/dist/assets/sky/studio/nz.png +0 -0
- package/dist/assets/sky/studio/px.png +0 -0
- package/dist/assets/sky/studio/py.png +0 -0
- package/dist/assets/sky/studio/pz.png +0 -0
- package/dist/assets/vanilla-Dcuy32gi.js +2 -0
- package/dist/assets/vanilla-Dcuy32gi.js.map +1 -0
- package/dist/console.html +899 -0
- package/dist/docs/BENCHMARK.md +77 -0
- package/dist/docs/CHEATSHEET.md +255 -0
- package/dist/docs/EFFECTS_API_GUIDE.md +577 -0
- package/dist/docs/EFFECTS_QUICK_REFERENCE.md +331 -0
- package/dist/docs/FONT_CHARACTER_REFERENCE.md +219 -0
- package/dist/docs/FREE_GLB_ASSETS.md +330 -0
- package/dist/docs/FULLSCREEN_BUTTON_FEATURE.md +296 -0
- package/dist/docs/GAMEPAD_SUPPORT.md +348 -0
- package/dist/docs/GAME_IMPROVEMENTS.md +278 -0
- package/dist/docs/GAME_QUALITY_STATUS.md +300 -0
- package/dist/docs/MIGRATION_GUIDE.md +553 -0
- package/dist/docs/NOVA64_3D_API.md +356 -0
- package/dist/docs/NOVA64_API_REFERENCE.md +1406 -0
- package/dist/docs/NOVA64_UI_API.md +503 -0
- package/dist/docs/UI_SYSTEM_SUMMARY.md +445 -0
- package/dist/docs/VOXEL_ENGINE_GUIDE.md +662 -0
- package/dist/docs/VOXEL_QUICK_REFERENCE.md +386 -0
- package/dist/docs/api-3d.html +750 -0
- package/dist/docs/api-effects.html +385 -0
- package/dist/docs/api-improvements.md +121 -0
- package/dist/docs/api-skybox.html +407 -0
- package/dist/docs/api-sprites.html +321 -0
- package/dist/docs/api-voxel.html +337 -0
- package/dist/docs/api.html +543 -0
- package/dist/docs/assets.html +306 -0
- package/dist/docs/audio.html +340 -0
- package/dist/docs/blogs.html +286 -0
- package/dist/docs/collision.html +316 -0
- package/dist/docs/console.html +247 -0
- package/dist/docs/editor.html +297 -0
- package/dist/docs/font.html +247 -0
- package/dist/docs/framebuffer.html +247 -0
- package/dist/docs/fullscreen-button.html +297 -0
- package/dist/docs/gpu-systems.html +247 -0
- package/dist/docs/index.html +580 -0
- package/dist/docs/input.html +491 -0
- package/dist/docs/physics.html +311 -0
- package/dist/docs/screens.html +311 -0
- package/dist/docs/storage.html +311 -0
- package/dist/docs/textinput.html +332 -0
- package/dist/docs/ui.html +488 -0
- package/dist/examples/3d-advanced/code.js +695 -0
- package/dist/examples/adventure-comic-3d/code.js +342 -0
- package/dist/examples/audio-lab/code.js +150 -0
- package/dist/examples/boids-flocking/code.js +270 -0
- package/dist/examples/crystal-cathedral-3d/code.js +706 -0
- package/dist/examples/cyberpunk-city-3d/code.js +1383 -0
- package/dist/examples/demoscene/README.md +192 -0
- package/dist/examples/demoscene/code.js +1081 -0
- package/dist/examples/demoscene/meta.json +21 -0
- package/dist/examples/dungeon-crawler-3d/code.js +1117 -0
- package/dist/examples/f-zero-nova-3d/code.js +865 -0
- package/dist/examples/f-zero-nova-3d/code_old.js +1555 -0
- package/dist/examples/fps-demo-3d/code.js +744 -0
- package/dist/examples/game-of-life-3d/code.js +338 -0
- package/dist/examples/generative-art/code.js +632 -0
- package/dist/examples/hello-3d/code.js +325 -0
- package/dist/examples/hello-skybox/code.js +183 -0
- package/dist/examples/hello-world/code.js +19 -0
- package/dist/examples/input-showcase/code.js +109 -0
- package/dist/examples/instancing-demo/code.js +315 -0
- package/dist/examples/minecraft-demo/code.js +387 -0
- package/dist/examples/model-viewer-3d/code.js +114 -0
- package/dist/examples/mystical-realm-3d/code.js +1203 -0
- package/dist/examples/nature-explorer-3d/code.js +1318 -0
- package/dist/examples/particles-demo/code.js +522 -0
- package/dist/examples/pbr-showcase/code.js +140 -0
- package/dist/examples/physics-demo-3d/code.js +948 -0
- package/dist/examples/screen-demo/code.js +267 -0
- package/dist/examples/shooter-demo-3d/code.js +1286 -0
- package/dist/examples/space-combat-3d/IMPLEMENTATION_SUMMARY.md +109 -0
- package/dist/examples/space-combat-3d/README.md +135 -0
- package/dist/examples/space-combat-3d/code.js +1332 -0
- package/dist/examples/space-harrier-3d/code.js +923 -0
- package/dist/examples/star-fox-nova-3d/code.js +1116 -0
- package/dist/examples/star-fox-nova-3d/code_backup.js +410 -0
- package/dist/examples/star-fox-nova-3d/code_broken.js +1821 -0
- package/dist/examples/storage-quest/code.js +209 -0
- package/dist/examples/strider-demo-3d/IMPROVEMENT_OPTIONS.md +285 -0
- package/dist/examples/strider-demo-3d/cache-test.html +132 -0
- package/dist/examples/strider-demo-3d/code-fixed.js +582 -0
- package/dist/examples/strider-demo-3d/code-old.js +1537 -0
- package/dist/examples/strider-demo-3d/code.js +1462 -0
- package/dist/examples/strider-demo-3d/code.js.bak2 +1169 -0
- package/dist/examples/strider-demo-3d/fix-game.sh +53 -0
- package/dist/examples/super-plumber-64/README.md +128 -0
- package/dist/examples/super-plumber-64/code.js +1185 -0
- package/dist/examples/super-plumber-64/index.html +88 -0
- package/dist/examples/test-2d-overlay/code.js +32 -0
- package/dist/examples/test-font/code.js +51 -0
- package/dist/examples/test-minimal/code.js +21 -0
- package/dist/examples/ui-demo/code.js +306 -0
- package/dist/examples/wing-commander-space/README.md +180 -0
- package/dist/examples/wing-commander-space/code.js +1285 -0
- package/dist/examples/wizardry-3d/CHANGELOG.md +366 -0
- package/dist/examples/wizardry-3d/code.js +3928 -0
- package/dist/index.html +666 -0
- package/dist/os9-shell/assets/index-DIHfrTaW.css +1 -0
- package/dist/os9-shell/assets/index-KchE_ngx.js +483 -0
- package/dist/os9-shell/assets/index-KchE_ngx.js.map +1 -0
- package/dist/os9-shell/index.html +23 -0
- package/dist/os9-shell/nova-icon.svg +12 -0
- package/index.html +6 -1
- package/package.json +37 -32
- package/public/assets/sky/studio/nx.png +0 -0
- package/public/assets/sky/studio/ny.png +0 -0
- package/public/assets/sky/studio/nz.png +0 -0
- package/public/assets/sky/studio/px.png +0 -0
- package/public/assets/sky/studio/py.png +0 -0
- package/public/assets/sky/studio/pz.png +0 -0
- package/public/os9-shell/assets/index-KchE_ngx.js +483 -0
- package/public/os9-shell/assets/index-KchE_ngx.js.map +1 -0
- package/public/os9-shell/index.html +10 -1
- package/runtime/api-2d.js +301 -21
- package/runtime/api-3d/pbr.js +45 -1
- package/runtime/api-3d.js +1 -0
- package/runtime/api-effects.js +90 -3
- package/runtime/api-gameutils.js +476 -0
- package/runtime/api-generative.js +610 -0
- package/runtime/api-skybox.js +54 -0
- package/runtime/api-voxel.js +139 -28
- package/runtime/gpu-threejs.js +13 -9
- package/runtime/ui.js +2 -2
- package/src/main.js +24 -1
- package/public/os9-shell/assets/index-B1Uvacma.js +0 -32825
- package/public/os9-shell/assets/index-B1Uvacma.js.map +0 -1
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# 🎮 Nova64 Ultimate 3D Fantasy Console API
|
|
2
|
+
|
|
3
|
+
## 🌟 **Revolutionary 3D Graphics System**
|
|
4
|
+
|
|
5
|
+
Nova64 delivers **spectacular Nintendo 64/PlayStation-style 3D graphics** with modern performance, featuring advanced materials, cinematic lighting, and 100% test coverage (35/35 tests passing).
|
|
6
|
+
|
|
7
|
+
### 🚀 **What's New in v0.2.5**
|
|
8
|
+
|
|
9
|
+
- **New Primitives**: `createCone`, `createCapsule`, `createTorus` — expands the primitive library to 7 shapes
|
|
10
|
+
- **PBR Material Control**: `setPBRProperties(meshId, {metalness, roughness, envMapIntensity})` — tune materials at runtime
|
|
11
|
+
- **Image Skybox + IBL**: `createImageSkybox([6 urls])` — cube-map backgrounds with image-based lighting
|
|
12
|
+
- **Gradient & Solid Skyboxes**: `createGradientSkybox(top, bottom)`, `createSolidSkybox(color)`
|
|
13
|
+
- **Skybox Animation API**: `setSkyboxSpeed()`, `enableSkyboxAutoAnimate()`, `disableSkyboxAutoAnimate()`
|
|
14
|
+
- **`removeMesh` Alias**: `removeMesh()` is now identical to `destroyMesh()` — both work
|
|
15
|
+
- **Cylinder Fixed**: `createCylinder()` now correctly produces a cylinder, not a box
|
|
16
|
+
|
|
17
|
+
### ✨ **Key Features**
|
|
18
|
+
|
|
19
|
+
- **🚀 Three.js Integration**: Hardware-accelerated 3D rendering with WebGL2
|
|
20
|
+
- **🎨 Advanced Materials**: Holographic, metallic, emissive, and animated surfaces
|
|
21
|
+
- **💡 Cinematic Lighting**: Multi-layered ambient, directional, and point lighting
|
|
22
|
+
- **🌫️ Atmospheric Effects**: Dynamic fog, volumetric lighting, particle systems
|
|
23
|
+
- **📐 High-Quality Shadows**: 4K shadow maps with soft shadow filtering
|
|
24
|
+
- **🎪 Post-Processing**: ACES tone mapping, bloom effects, motion blur
|
|
25
|
+
|
|
26
|
+
## 🏗️ **Progressive Enhancement Architecture**
|
|
27
|
+
|
|
28
|
+
Nova64's intelligent renderer system ensures maximum compatibility:
|
|
29
|
+
|
|
30
|
+
1. **🎯 Three.js** (Ultimate) - Complete 3D fantasy console with advanced effects
|
|
31
|
+
2. **⚡ WebGL2** (Enhanced) - High-performance 2D with shader effects and tone mapping
|
|
32
|
+
3. **🖼️ Canvas2D** (Compatible) - Universal 2D fallback for any device
|
|
33
|
+
|
|
34
|
+
**🔧 Renderer Control**: Use control panel dropdown or `localStorage.setItem('nova64-render-mode', 'threejs')`
|
|
35
|
+
|
|
36
|
+
## 🎯 **Complete 3D API Reference** (35+ Functions)
|
|
37
|
+
|
|
38
|
+
### 🎨 **Advanced Object Creation**
|
|
39
|
+
|
|
40
|
+
#### `createCube(size, color, position, options?)` ⭐
|
|
41
|
+
|
|
42
|
+
Creates a cube mesh.
|
|
43
|
+
|
|
44
|
+
- `size` (number): Cube side length (default: 1)
|
|
45
|
+
- `color` (hex): Colour, e.g. `0xff4488`
|
|
46
|
+
- `position` (array): `[x, y, z]` world position (default: `[0, 0, 0]`)
|
|
47
|
+
- `options` (object): Material options — see Material Options table
|
|
48
|
+
- **Returns**: mesh ID (number)
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// Basic cube
|
|
52
|
+
const box = createCube(2, 0xff4488, [0, 1, 0]);
|
|
53
|
+
|
|
54
|
+
// Holographic cube
|
|
55
|
+
const holoCube = createCube(1.5, 0x00ff88, [3, 1, -3], {
|
|
56
|
+
material: 'holographic',
|
|
57
|
+
emissive: 0x004400,
|
|
58
|
+
metalness: 0.8,
|
|
59
|
+
roughness: 0.2,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### `createSphere(radius, color, position, options?)` ⭐
|
|
64
|
+
|
|
65
|
+
Creates a sphere mesh.
|
|
66
|
+
|
|
67
|
+
- `radius` (number): Sphere radius (default: 1)
|
|
68
|
+
- `color` (hex): Colour
|
|
69
|
+
- `position` (array): `[x, y, z]`
|
|
70
|
+
- `options` (object): Material options; also accepts `segments` (default: 8)
|
|
71
|
+
- **Returns**: mesh ID (number)
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// Metallic planet
|
|
75
|
+
const planet = createSphere(2, 0x4488ff, [0, 2, -8], {
|
|
76
|
+
material: 'metallic',
|
|
77
|
+
metalness: 0.9,
|
|
78
|
+
roughness: 0.1,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Low-poly N64 orb
|
|
82
|
+
const orb = createSphere(0.8, 0xffff00, [-4, 1, -5], {
|
|
83
|
+
material: 'emissive',
|
|
84
|
+
segments: 8,
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### `createPlane(width, height, color, position, options?)` ⭐
|
|
89
|
+
|
|
90
|
+
Creates a flat plane — ground, walls, ceilings.
|
|
91
|
+
|
|
92
|
+
- `width, height` (numbers): Plane dimensions
|
|
93
|
+
- `color` (hex): Colour
|
|
94
|
+
- `position` (array): `[x, y, z]`
|
|
95
|
+
- `options` (object): Material options
|
|
96
|
+
- **Returns**: mesh ID (number)
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
// Ground plane
|
|
100
|
+
const ground = createPlane(100, 100, 0x228b22, [0, 0, 0]);
|
|
101
|
+
|
|
102
|
+
// Holographic wall
|
|
103
|
+
const wall = createPlane(8, 6, 0x00ffff, [5, 3, -10], {
|
|
104
|
+
material: 'holographic',
|
|
105
|
+
transparent: true,
|
|
106
|
+
opacity: 0.7,
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### `loadModel(url, position, scale)` (async)
|
|
111
|
+
|
|
112
|
+
Loads GLTF/GLB 3D models with automatic N64-style material conversion.
|
|
113
|
+
|
|
114
|
+
- `url` (string): Path to .gltf or .glb file
|
|
115
|
+
- `position` (array): [x, y, z] position (default: [0, 0, 0])
|
|
116
|
+
- `scale` (number): Uniform scale factor (default: 1)
|
|
117
|
+
- Returns: Promise resolving to mesh ID
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const spaceship = await loadModel('/assets/ship.glb', [0, 0, 0], 0.5);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Object Manipulation
|
|
124
|
+
|
|
125
|
+
#### `setPosition(meshId, x, y, z)`
|
|
126
|
+
|
|
127
|
+
Sets absolute position of a 3D object.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
setPosition(cube, 5, 2, -3);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `setRotation(meshId, x, y, z)`
|
|
134
|
+
|
|
135
|
+
Sets absolute rotation in radians.
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
setRotation(cube, 0, Math.PI / 4, 0); // 45° Y rotation
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### `setScale(meshId, x, y, z)` or `setScale(meshId, uniform)`
|
|
142
|
+
|
|
143
|
+
Sets object scale. Use single number for uniform scaling.
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
setScale(cube, 2); // Double size uniformly
|
|
147
|
+
setScale(cube, 1, 2, 1); // Stretch vertically only
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `rotateMesh(meshId, x, y, z)`
|
|
151
|
+
|
|
152
|
+
Rotates by the specified amounts (additive).
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
// Spin cube each frame
|
|
156
|
+
rotateMesh(cube, 0, dt, 0);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### `moveMesh(meshId, x, y, z)`
|
|
160
|
+
|
|
161
|
+
Moves by the specified offset (additive).
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
moveMesh(cube, 0, Math.sin(time) * dt, 0); // Bob up and down
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
#### `destroyMesh(meshId)`
|
|
168
|
+
|
|
169
|
+
Removes object from scene and frees memory.
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
destroyMesh(cube);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Camera Controls
|
|
176
|
+
|
|
177
|
+
#### `setCameraPosition(x, y, z)`
|
|
178
|
+
|
|
179
|
+
Sets camera position in world space.
|
|
180
|
+
|
|
181
|
+
```js
|
|
182
|
+
setCameraPosition(0, 5, 10); // Behind and above origin
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### `setCameraTarget(x, y, z)`
|
|
186
|
+
|
|
187
|
+
Sets what the camera looks at.
|
|
188
|
+
|
|
189
|
+
```js
|
|
190
|
+
setCameraTarget(0, 0, 0); // Look at origin
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### `setCameraFOV(degrees)`
|
|
194
|
+
|
|
195
|
+
Sets field of view angle.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
setCameraFOV(75); // Wide angle view
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Scene Effects
|
|
202
|
+
|
|
203
|
+
#### `setFog(color, near, far)`
|
|
204
|
+
|
|
205
|
+
Adds atmospheric fog for depth perception.
|
|
206
|
+
|
|
207
|
+
- `color` (hex): Fog color as 0xRRGGBB
|
|
208
|
+
- `near` (number): Distance where fog starts
|
|
209
|
+
- `far` (number): Distance where fog is fully opaque
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
setFog(0x003366, 10, 50); // Blue distance fog
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
#### `setLightDirection(x, y, z)`
|
|
216
|
+
|
|
217
|
+
Sets the main directional light direction.
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
setLightDirection(1, 1, 0.5); // Light from upper-right
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### `enablePixelation(factor)`
|
|
224
|
+
|
|
225
|
+
Applies N64-style pixelation effect.
|
|
226
|
+
|
|
227
|
+
- `factor` (number): Pixelation intensity (1 = none, 2+ = pixelated)
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
enablePixelation(2); // Double-pixel rendering
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### `enableDithering(enabled)`
|
|
234
|
+
|
|
235
|
+
Toggles color dithering for authentic retro look.
|
|
236
|
+
|
|
237
|
+
```js
|
|
238
|
+
enableDithering(true);
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Advanced Features
|
|
242
|
+
|
|
243
|
+
#### `raycastFromCamera(x, y)`
|
|
244
|
+
|
|
245
|
+
Cast a ray from camera through screen coordinates for object picking.
|
|
246
|
+
|
|
247
|
+
- Returns: `{ meshId, point, distance }` or `null`
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
const hit = raycastFromCamera(mouseX, mouseY);
|
|
251
|
+
if (hit) {
|
|
252
|
+
console.log(`Clicked object ${hit.meshId} at distance ${hit.distance}`);
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
#### `get3DStats()`
|
|
257
|
+
|
|
258
|
+
Returns rendering performance statistics.
|
|
259
|
+
|
|
260
|
+
```js
|
|
261
|
+
const stats = get3DStats();
|
|
262
|
+
console.log(`Triangles: ${stats.render.triangles}, Calls: ${stats.render.calls}`);
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
#### Direct Three.js Access
|
|
266
|
+
|
|
267
|
+
For advanced users who need full Three.js control:
|
|
268
|
+
|
|
269
|
+
```js
|
|
270
|
+
const scene = getScene();
|
|
271
|
+
const camera = getCamera();
|
|
272
|
+
const renderer = getRenderer();
|
|
273
|
+
const mesh = getMesh(meshId);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## N64-Style Best Practices
|
|
277
|
+
|
|
278
|
+
### Geometry
|
|
279
|
+
|
|
280
|
+
- Keep polygon counts low (< 1000 tri per object)
|
|
281
|
+
- Use `segments` parameter on spheres (6-12 recommended)
|
|
282
|
+
- Prefer simple, angular shapes over smooth curves
|
|
283
|
+
|
|
284
|
+
### Materials
|
|
285
|
+
|
|
286
|
+
- Use flat, saturated colors
|
|
287
|
+
- Avoid complex textures
|
|
288
|
+
- Embrace vertex lighting over per-pixel
|
|
289
|
+
|
|
290
|
+
### Performance
|
|
291
|
+
|
|
292
|
+
- Batch similar objects when possible
|
|
293
|
+
- Use fog to hide distant detail
|
|
294
|
+
- Keep scene complexity moderate (< 50 active objects)
|
|
295
|
+
|
|
296
|
+
### Aesthetic
|
|
297
|
+
|
|
298
|
+
- Use pixelation factor 1.5-2.0 for authentic feel
|
|
299
|
+
- Enable dithering for color banding
|
|
300
|
+
- Limit color palette for true retro look
|
|
301
|
+
|
|
302
|
+
## Example Cart Structure
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
let objects = [];
|
|
306
|
+
let time = 0;
|
|
307
|
+
|
|
308
|
+
export async function init() {
|
|
309
|
+
// Setup scene
|
|
310
|
+
setCameraPosition(0, 5, 10);
|
|
311
|
+
setFog(0x001122, 10, 30);
|
|
312
|
+
enablePixelation(1.5);
|
|
313
|
+
|
|
314
|
+
// Create objects
|
|
315
|
+
objects.push(createCube(1, 0xff0000, [0, 0, 0]));
|
|
316
|
+
|
|
317
|
+
// Load models if needed
|
|
318
|
+
const model = await loadModel('/assets/ship.glb');
|
|
319
|
+
objects.push(model);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function update(dt) {
|
|
323
|
+
time += dt;
|
|
324
|
+
|
|
325
|
+
// Animate objects
|
|
326
|
+
objects.forEach((obj, i) => {
|
|
327
|
+
rotateMesh(obj, 0, dt, 0);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// Move camera
|
|
331
|
+
const camX = Math.cos(time * 0.5) * 10;
|
|
332
|
+
const camZ = Math.sin(time * 0.5) * 10;
|
|
333
|
+
setCameraPosition(camX, 5, camZ);
|
|
334
|
+
setCameraTarget(0, 0, 0);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export function draw() {
|
|
338
|
+
cls(); // Clear 2D overlay
|
|
339
|
+
// 3D renders automatically
|
|
340
|
+
|
|
341
|
+
// Add 2D HUD elements
|
|
342
|
+
print('3D Scene Active', 8, 8, rgba8(255, 255, 255, 255));
|
|
343
|
+
print(`Objects: ${objects.length}`, 8, 24, rgba8(200, 200, 200, 255));
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## Migration from 2D
|
|
348
|
+
|
|
349
|
+
Existing 2D carts continue to work unchanged. To add 3D elements:
|
|
350
|
+
|
|
351
|
+
1. Initialize 3D scene in `init()`
|
|
352
|
+
2. Create/animate 3D objects in `update()`
|
|
353
|
+
3. Use `draw()` for 2D overlay elements
|
|
354
|
+
4. 3D rendering happens automatically between `update()` and `draw()`
|
|
355
|
+
|
|
356
|
+
The 2D framebuffer becomes a transparent overlay rendered on top of the 3D scene, perfect for HUD elements, text, and UI.
|