Debian Codegraph @

web/filament-js/test.ts

raw
1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18 * This file exists only to test the buildability of our TypeScript annotations, To run the test,
19 * invoke Filament's easy build script with "./build.sh -up webgl release", or do:
20 *
21 * npx tsc --noEmit \
22 * ../../third_party/gl-matrix/gl-matrix.d.ts \
23 * ./filament.d.ts \
24 * test.ts
25 *
26 * Note that it suffices to simply build the test, it is not meant to be executed.
27 */
28
29 import * as Filament from "./filament";
30 import * as glm from "gl-matrix";
31
32 const v2 = glm.vec2.create();
33 const v3 = glm.vec3.create();
34 const v4 = glm.vec4.create();
35 const m3 = glm.mat3.create();
36 const m4 = glm.mat4.create();
37 const qt = glm.quat.create();
38
39 const canvas = new HTMLCanvasElement();
40 const engine = Filament.Engine.create(canvas);
41
42 function smoke_camera_frustum() {
43 const camera: Filament.Camera = engine.createCamera();
44 camera.setProjection(Filament.Camera$Projection.ORTHO, 0, 1, 0, 1, 0, 1);
45 camera.setProjectionFov(45, 1.0, 0.0, 1.0, Filament.Camera$Fov.HORIZONTAL);
46 camera.setLensProjection(0, 0.33, 1, 2);
47 camera.setCustomProjection(m4, 0, 1);
48 const m5 = camera.getProjectionMatrix() as glm.mat4;
49 const m6 = camera.getCullingProjectionMatrix() as glm.mat4;
50 camera.lookAt([0, 0, 0], [0, 0, 0], [0, 0, 0]);
51 camera.lookAt(v3, v3, v3);
52 const frustum: Filament.Frustum = camera.getFrustum();
53 frustum.setProjection(m4);
54 const v5 = frustum.getNormalizedPlane(Filament.Frustum$Plane.BOTTOM) as glm.vec4;
55 const b: boolean = frustum.intersectsSphere([0, 1, 2, 3]);
56 const c: boolean = frustum.intersectsSphere(glm.vec4.fromValues(0, 1, 2, 3));
57 console.log(m5, m6, v5, b, c);
58 }
59
60 function smoke_transforms() {
61 const tcm = engine.getTransformManager();
62 const entity = Filament.EntityManager.get().create();
63 const inst: Filament.TransformManager$Instance = tcm.getInstance(entity);
64 tcm.setTransform(inst, m4);
65 const m5 = tcm.getTransform(inst) as glm.mat4;
66 const m6 = tcm.getWorldTransform(inst) as glm.mat4;
67 tcm.openLocalTransformTransaction();
68 tcm.commitLocalTransformTransaction();
69 console.log(m5, m6);
70 inst.delete();
71 }
72
73 function smoke_renderables() {
74 const rm = engine.getRenderableManager();
75 const entity = Filament.EntityManager.get().create();
76 const inst: Filament.RenderableManager$Instance = rm.getInstance(entity);
77 const bone: Filament.RenderableManager$Bone = {
78 unitQuaternion: qt,
79 translation: v3
80 };
81 rm.setCastShadows(inst, true);
82 rm.setBones(inst, [bone], 0);
83 Filament.RenderableManager.Builder(1).skinningBones([bone]).build(engine, entity);
84 inst.delete();
85 }
86
87 smoke_camera_frustum();
88 smoke_transforms();
89 smoke_renderables();