|
1 |
| -import { icosahedron } from "../../../lib/geometry/primitives/Polyhedrons"; |
2 |
| -import { fetchImage } from "../../../lib/io/loaders/Image"; |
| 1 | +import { Float32Attribute } from "../../../lib/geometry/Attribute"; |
| 2 | +import { Geometry } from "../../../lib/geometry/Geometry"; |
| 3 | +import { convertToInterleavedGeometry } from "../../../lib/geometry/Geometry.Functions"; |
3 | 4 | import { ShaderMaterial } from "../../../lib/materials/ShaderMaterial";
|
4 |
| -import { Euler } from "../../../lib/math/Euler"; |
5 |
| -import { Matrix4 } from "../../../lib/math/Matrix4"; |
6 |
| -import { |
7 |
| - makeMatrix4Perspective, |
8 |
| - makeMatrix4RotationFromEuler, |
9 |
| - makeMatrix4Translation, |
10 |
| -} from "../../../lib/math/Matrix4.Functions"; |
11 |
| -import { Vector3 } from "../../../lib/math/Vector3"; |
12 | 5 | import { BufferGeometry } from "../../../lib/renderers/webgl2/buffers/BufferGeometry";
|
13 |
| -import { DepthTestFunc, DepthTestState } from "../../../lib/renderers/webgl2/DepthTestState"; |
14 | 6 | import { Program } from "../../../lib/renderers/webgl2/programs/Program";
|
15 | 7 | import { RenderingContext } from "../../../lib/renderers/webgl2/RenderingContext";
|
16 |
| -import { TexImage2D } from "../../../lib/renderers/webgl2/textures/TexImage2D"; |
17 |
| -import { CubeTexture } from "../../../lib/textures/CubeTexture"; |
18 | 8 | import fragmentSourceCode from "./fragment.glsl";
|
19 | 9 | import vertexSourceCode from "./vertex.glsl";
|
20 | 10 |
|
21 |
| -async function init(): Promise<null> { |
22 |
| - const geometry = icosahedron(0.75, 3); |
23 |
| - const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode); |
24 |
| - const cubeTexture = new CubeTexture([ |
25 |
| - await fetchImage("/assets/textures/cube/pisa/px.png"), |
26 |
| - await fetchImage("/assets/textures/cube/pisa/nx.png"), |
27 |
| - await fetchImage("/assets/textures/cube/pisa/py.png"), |
28 |
| - await fetchImage("/assets/textures/cube/pisa/ny.png"), |
29 |
| - await fetchImage("/assets/textures/cube/pisa/pz.png"), |
30 |
| - await fetchImage("/assets/textures/cube/pisa/nz.png"), |
31 |
| - ]); |
| 11 | +let geometry = new Geometry(); |
| 12 | +geometry.attributes["position"] = new Float32Attribute([0, 0.5, 0.5, -0.5, -0.5, -0.5], 2); |
| 13 | +geometry.attributes["color"] = new Float32Attribute([1, 0, 0, 0, 1, 0, 0, 0, 1], 3); |
32 | 14 |
|
33 |
| - const context = new RenderingContext(); |
34 |
| - const canvasFramebuffer = context.canvasFramebuffer; |
35 |
| - document.body.appendChild(canvasFramebuffer.canvas); |
| 15 | +console.log("geometry", geometry); |
| 16 | +geometry = convertToInterleavedGeometry(geometry); |
| 17 | +console.log("interleaved", geometry); |
36 | 18 |
|
37 |
| - const program = new Program(context, material); |
38 |
| - const uniforms = { |
39 |
| - localToWorld: new Matrix4(), |
40 |
| - worldToView: makeMatrix4Translation(new Matrix4(), new Vector3(0, 0, -1)), |
41 |
| - viewToScreen: makeMatrix4Perspective(new Matrix4(), -0.25, 0.25, 0.25, -0.25, 0.1, 4.0), |
42 |
| - cubeMap: new TexImage2D(context, cubeTexture), |
43 |
| - }; |
44 |
| - const bufferGeometry = new BufferGeometry(context, geometry); |
45 |
| - const depthTestState = new DepthTestState(true, DepthTestFunc.Less); |
| 19 | +const material = new ShaderMaterial(vertexSourceCode, fragmentSourceCode); |
46 | 20 |
|
47 |
| - function animate(): void { |
48 |
| - requestAnimationFrame(animate); |
| 21 | +const context = new RenderingContext(); |
| 22 | +const canvasFramebuffer = context.canvasFramebuffer; |
| 23 | +document.body.appendChild(canvasFramebuffer.canvas); |
49 | 24 |
|
50 |
| - const now = Date.now(); |
51 |
| - uniforms.localToWorld = makeMatrix4RotationFromEuler( |
52 |
| - uniforms.localToWorld, |
53 |
| - new Euler(now * 0.0001, now * 0.00033, now * 0.000077), |
54 |
| - ); |
55 |
| - canvasFramebuffer.renderBufferGeometry(program, uniforms, bufferGeometry, depthTestState); |
56 |
| - } |
| 25 | +const bufferGeometry = new BufferGeometry(context, geometry); |
| 26 | +const program = new Program(context, material); |
| 27 | +const uniforms = {}; |
57 | 28 |
|
58 |
| - animate(); |
59 |
| - |
60 |
| - return null; |
61 |
| -} |
62 |
| - |
63 |
| -init(); |
| 29 | +canvasFramebuffer.renderBufferGeometry(program, uniforms, bufferGeometry); |
0 commit comments