forked from github/game-off-2013
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pitobject.js
83 lines (66 loc) · 2.37 KB
/
pitobject.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
"use strict";
define(["settings", "three.min"], function( settings ) {
function LinerMesh(color) {
var linerDepth = settings.arMarkerSize;
var geometry = new THREE.CubeGeometry(
settings.arMarkerSize,
settings.arMarkerSize,
linerDepth
);
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[ 10 ].materialIndex = 1;
geometry.faces[ 11 ].materialIndex = 1;
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
mesh.position.z = linerDepth/2;
return mesh;
}
function OccluderMesh() {
var occluderDepth = settings.arMarkerSize*3;
var geometry = new THREE.CubeGeometry(
settings.arMarkerSize + 0.1,
settings.arMarkerSize + 0.1,
occluderDepth
);
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[ 10 ].materialIndex = 1;
geometry.faces[ 11 ].materialIndex = 1;
var mesh = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
mesh.position.z = occluderDepth/2;
return mesh;
}
function PitObject(params) {
var model = new THREE.Object3D();
model.matrixAutoUpdate = false;
model.add( new LinerMesh( params.color ) );
var occluder = new THREE.Object3D();
occluder.matrixAutoUpdate = false;
occluder.add( new OccluderMesh() );
function transform(matrix) {
model.matrix.fromArray(matrix);
model.matrixWorldNeedsUpdate = true;
occluder.matrix.fromArray(matrix);
occluder.matrixWorldNeedsUpdate = true;
}
return {
transform: transform,
model: model,
pickables: [],
occluder: occluder,
};
}
return {
PitObject: PitObject,
};
});