-
Notifications
You must be signed in to change notification settings - Fork 1
/
arframe-portal-door.js
104 lines (95 loc) · 3.24 KB
/
arframe-portal-door.js
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
/* global AFRAME, THREE */
AFRAME.registerComponent('arjs-portal-door', {
schema: {
url : { // Url of the content - may be video or image
type: 'string',
default: "https://sep.github.io/XR-portal-game/assets/images/jwst_mapped_edited.jpg"
},
doorMesh : { // door gltf
type: 'string',
default: "https://sep.github.io/XR-portal-game/assets/gltf/portal.gltf"
},
doorMask : { // door gltf
type: 'string',
default: "https://sep.github.io/XR-portal-game/assets/gltf/portal_mask.gltf"
},
doorInsideMask : { // door gltf
type: 'string',
default: "https://sep.github.io/XR-portal-game/assets/gltf/portal_inside_mask.gltf"
},
doorWidth : { // width of the door
type: 'number',
default: 1,
},
doorHeight : { // height of the door
type: 'number',
default: 1,
},
},
init: function () {
var _this = this
var doorWidth = this.data.doorWidth
var doorHeight = this.data.doorHeight
var imageURL = this.data.url
var meshUrl = this.data.doorMesh
var maskUrl = this.data.doorMask
var doorInsideMask = this.data.doorInsideMask
var portalDoor = new THREEx.Portal360(imageURL, doorWidth, doorHeight, meshUrl, maskUrl, doorInsideMask)
this._portalDoor = portalDoor
this.el.object3D.add(portalDoor.object3d)
var doorGltf = this.buildDoorGltf(meshUrl)
this.doorGltf = doorGltf;
this.el.appendChild(doorGltf)
parentThis = this;
var portalParticles = this.buildParticles();
this.el.appendChild(portalParticles)
},
tick: function(){
this._portalDoor.update()
},
buildDoorGltf: function(meshUrl)
{
const doorGltf = document.createElement('a-entity');
doorGltf.setAttribute('response-type', "arraybuffer");
doorGltf.setAttribute('gltf-model', meshUrl);
doorGltf.setAttribute('animation-mixer', 'clip: Idle;');
return doorGltf;
},
buildParticles: function() {
var particles = this.particles = document.createElement('a-entity');
particles.setAttribute("particle-system",
{
color: "#DD15FF,#6E0B7F",
particleCount: "200",
randomise: true,
texture: "https://sep.github.io/XR-portal-game/assets/images/smoke.png",
opacity: "0.2 0",
dragValue: "500",
dragSpread: "1",
type: 3,
size: "5",
velocityValue: "0 -0.5 -0.35",
velocitySpread: "0.2 0.2 0.2",
accelerationValue: "0 0.05 0",
accelerationSpread: "0 .005 0",
positionSpread: "1, 2, 0.2",
maxAge: 2,
rotationAxis: "y",
rotationAngle: "3.14",
});
return particles;
}
});
AFRAME.registerPrimitive('a-portal-door', AFRAME.utils.extendDeep({}, AFRAME.primitives.getMeshMixin(), {
defaultComponents: {
'arjs-portal-door': {},
},
mappings: {
'url': 'arjs-portal-door.url',
'doorWidth': 'arjs-portal-door.doorWidth',
'doorHeight': 'arjs-portal-door.doorHeight',
'doorMesh': 'arjs-portal-door.doorMesh',
'doorMask': 'arjs-portal-door.doorMask',
'doorInsideMask': 'arjs-portal-door.doorInsideMask',
}
}));