/
aframe-tests.ts
129 lines (110 loc) · 2.83 KB
/
aframe-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import {
Component,
Entity,
Geometry,
MultiPropertySchema,
registerComponent,
Scene,
System,
SystemDefinition,
THREE,
} from "aframe";
import * as threeDeprecated from "three/examples/jsm/deprecated/Geometry";
// Global
const threeCamera = new AFRAME.THREE.OrthographicCamera();
// Entity
const entity = document.createElement("a-entity");
entity.emit("rotate");
entity.emit("collide", { target: entity });
entity.emit("sink", null, false);
const position = entity.getAttribute("position");
position.x;
position.y;
position.z;
entity.setAttribute("material", "color", "red");
entity.components["geometry"].data;
type MyEntity = Entity<{
camera: THREE.Camera;
material: THREE.Material;
sound: { pause(): void };
}>;
const camera = (document.querySelector("a-entity[camera]") as MyEntity).components.camera;
const material = (document.querySelector("a-entity[material]") as MyEntity).components.material;
(document.querySelector("a-entity[sound]") as MyEntity).components.sound.pause();
entity.getDOMAttribute("geometry").primitive;
entity.setAttribute("light", {
type: "spot",
distance: 30,
intensity: 2.0,
});
entity.addEventListener("child-detached", event => {
event.detail;
});
// Components
// interface TestComponent extends Component {
// multiply: (f: number) => number;
//
// data: {
// myProperty: any[],
// string: string,
// num: number
// };
//
// system: TestSystem;
// }
const Component = registerComponent("test-component", {
schema: {
myProperty: {
default: [],
parse() {
return [true];
},
},
string: { type: "string" },
num: 0,
},
init() {
this.data.num = 0;
if (this.initialized && this.el.hasLoaded) {
this.el.setAttribute("custom-attribute", "custom-value");
}
},
update() {},
tick() {},
tock() {},
remove() {
this.el.remove();
this.el.destroy();
},
pause() {},
play() {},
multiply(f: number) {
// Reference to system because both were registered with the same name.
return f * this.data.num * this.system!.data.counter;
},
});
// Scene
const scene = document.querySelector("a-scene");
scene.hasLoaded;
// System
const testSystem: SystemDefinition = {
schema: {
counter: 0,
},
init() {
this.data.counter = 1;
((this.el as Entity).sceneEl as Scene).addEventListener("enter-vr", (e) => {});
},
};
AFRAME.registerSystem("test-component", testSystem);
// Register Custom Geometry
AFRAME.registerGeometry("a-test-geometry", {
schema: {
groupIndex: { default: 0 },
},
init(data) {
this.geometry = new threeDeprecated.Geometry();
const temp = data.groupIndex;
temp;
},
});