|
| 1 | +import * as RedGPU from "../../../../dist/index.js"; |
| 2 | + |
| 3 | +const canvas = document.createElement('canvas'); |
| 4 | +document.body.appendChild(canvas); |
| 5 | + |
| 6 | +RedGPU.init( |
| 7 | + canvas, |
| 8 | + (redGPUContext) => { |
| 9 | + const controller = new RedGPU.Camera.OrbitController(redGPUContext); |
| 10 | + |
| 11 | + controller.tilt = 0 |
| 12 | + |
| 13 | + const scene = new RedGPU.Display.Scene(); |
| 14 | + const view = new RedGPU.Display.View3D(redGPUContext, scene, controller); |
| 15 | + redGPUContext.addView(view); |
| 16 | + loadGLTF(view, 'https://threejs.org/examples/models/gltf/Soldier.glb'); |
| 17 | + const renderer = new RedGPU.Renderer(redGPUContext); |
| 18 | + const render = () => { |
| 19 | + }; |
| 20 | + renderer.start(redGPUContext, render); |
| 21 | + |
| 22 | + renderTestPane(redGPUContext, view); |
| 23 | + }, |
| 24 | + (failReason) => { |
| 25 | + console.error('RedGPU initialization failed:', failReason); |
| 26 | + const errorDiv = document.createElement('div'); |
| 27 | + errorDiv.innerHTML = failReason; |
| 28 | + document.body.appendChild(errorDiv); |
| 29 | + } |
| 30 | +); |
| 31 | + |
| 32 | +function loadGLTF(view, url) { |
| 33 | + const {redGPUContext, scene} = view; |
| 34 | + new RedGPU.GLTFLoader(redGPUContext, url, (result) => { |
| 35 | + const mesh = result.resultMesh |
| 36 | + view.camera.fitMeshToScreenCenter(mesh, view) |
| 37 | + scene.addChild(mesh) |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +const renderTestPane = async (redGPUContext, targetView) => { |
| 42 | + const {Pane } = await import('https://cdn.jsdelivr.net/npm/[email protected]/dist/tweakpane.min.js'); |
| 43 | + const {createIblHelper, setDebugButtons} = await import('../../../exampleHelper/createExample/panes/index.js'); |
| 44 | + setDebugButtons(redGPUContext); |
| 45 | + const pane = new Pane(); |
| 46 | + createIblHelper(pane, targetView, RedGPU); |
| 47 | +}; |
0 commit comments