-
Notifications
You must be signed in to change notification settings - Fork 1
/
arobject.js
126 lines (100 loc) · 3.58 KB
/
arobject.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"use strict";
define(["lib/three.min"], function() {
THREE.Matrix4.prototype.setFromArray = function(m) {
return this.set(
m[0], m[4], m[8], m[12],
m[1], m[5], m[9], m[13],
m[2], m[6], m[10], m[14],
m[3], m[7], m[11], m[15]
);
}
THREE.Object3D.prototype.transformFromArray = function(m) {
this.matrix.setFromArray(m);
this.matrixWorldNeedsUpdate = true;
}
function createContainer() {
var model = new THREE.Object3D();
model.matrixAutoUpdate = false;
return model;
}
function createMarkerMesh(color) {
var geometry = new THREE.CubeGeometry( 100,100,100 );
var materials = [
new THREE.MeshPhongMaterial( {color:color, side:THREE.DoubleSide } ),
new THREE.MeshBasicMaterial( {visible:false} ),
];
for( var i = 0; i < geometry.faces.length; i++ ) {
geometry.faces[ i ].materialIndex = 0;
}
geometry.faces[ 5 ].materialIndex = 1;
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
mesh.position.z = 50;
return mesh;
}
function createMarkerHitboxMesh() {
var geometry = new THREE.PlaneGeometry( 100, 100 );
var material = new THREE.MeshBasicMaterial({
visible:false,
side:THREE.DoubleSide
});
var mesh = new THREE.Mesh( geometry, material );
return mesh;
}
function createMarkerOccluderMesh() {
var geometry = new THREE.CubeGeometry( 100.1, 100.1, 100.1 );
var materials = [
new THREE.MeshBasicMaterial( {color:0x0000FF, side:THREE.DoubleSide } ),
new THREE.MeshBasicMaterial( {visible:false} ),
];
for( var i = 0; i < geometry.faces.length; i++ ) {
geometry.faces[ i ].materialIndex = 0;
}
geometry.faces[ 5 ].materialIndex = 1;
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
mesh.position.z = 50;
return mesh;
}
function createMarkerObject(params) {
var modelContainer = createContainer();
var modelMesh = createMarkerMesh(params.color);
modelContainer.add( modelMesh );
var hitboxMesh = createMarkerHitboxMesh();
modelContainer.add( hitboxMesh );
var occluderContainer = createContainer();
var occluderMesh = createMarkerOccluderMesh();
occluderContainer.add( occluderMesh );
function transform(matrix) {
modelContainer.transformFromArray( matrix );
occluderContainer.transformFromArray( matrix );
}
return {
transform: transform,
model: modelContainer,
occluder: occluderContainer,
hitbox: hitboxMesh,
}
}
function createBallMesh() {
var geometry = new THREE.SphereGeometry( 1, 64, 64 );
var material = new THREE.MeshPhongMaterial( { color: 0xFFFFFF } );
var mesh = new THREE.Mesh( geometry, material );
return mesh;
}
function createBallObject() {
var modelContainer = createContainer();
var modelMesh = createBallMesh();
modelContainer.add( modelMesh );
function setPosition(x,y,z) {
modelContainer.position.set(x,y,z);
modelContainer.updateMatrix();
}
return {
model:modelContainer,
setPosition:setPosition,
}
}
return {
createMarkerObject:createMarkerObject,
createBallObject:createBallObject
}
});