-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
85 lines (74 loc) · 1.7 KB
/
index.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
require('./lib/PLYLoader.js');
if (typeof AFRAME === 'undefined') {
throw new Error('Component attempted to register before AFRAME was available.');
}
/**
* Point Cloud component for A-Frame.
*/
AFRAME.registerComponent('pointcloud', {
schema: {
src: {
type: 'asset'
},
texture: {
type: 'asset'
},
size: {
type: 'number',
default: 1
},
opacity: {
type: 'number',
default: 1
},
depthWrite: {
type: 'boolean',
default: true
},
},
multiple: false,
init: function () {
if (!this.data.src) {
console.warn("HOW I'M SUPOSSED TO LOAD A POINT CLOUD WITHOUT [%s] `src` DEFINED", this.name);
return;
}
const loader = new THREE.PLYLoader();
const _this = this;
loader.load(this.data.src, function (geometry) {
var material;
if (_this.data.texture) {
const sprite = new THREE.TextureLoader().load( _this.data.texture );
material = new THREE.PointsMaterial({
size: _this.data.size,
vertexColors: THREE.VertexColors,
map: sprite,
transparent: true,
opacity: _this.data.opacity,
depthWrite: _this.data.depthWrite,
});
} else {
material = new THREE.PointsMaterial({
size: _this.data.size,
vertexColors: THREE.VertexColors,
transparent: true,
opacity: _this.data.opacity,
});
}
_this.pointcloud = new THREE.Points(geometry, material);
_this.el.setObject3D('pointcloud', _this.pointcloud);
});
},
remove: function () {},
});
AFRAME.registerPrimitive('a-pointcloud', {
defaultComponents: {
pointcloud: {}
},
mappings: {
src: 'pointcloud.src',
texture: 'pointcloud.texture',
size: 'pointcloud.size',
opacity: 'pointcloud.opacity',
depthWrite: 'pointcloud.depthWrite'
}
});