Skip to content

Commit 13e99aa

Browse files
committed
Building out the Kinectron class methods and clean up
1 parent a532bb4 commit 13e99aa

File tree

6 files changed

+207
-143
lines changed

6 files changed

+207
-143
lines changed

assets/test.jpg

39.9 KB
Loading

dist/three.kinectron.js

Lines changed: 122 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ module.exports = function(strings) {
1111
}
1212

1313
},{}],2:[function(require,module,exports){
14+
'use strict';
15+
16+
var _kinectronForThree = require('./kinectronForThree');
17+
18+
var _kinectronForThree2 = _interopRequireDefault(_kinectronForThree);
19+
20+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21+
22+
//If three.js is in the global scope attach it
23+
if (THREE) {
24+
THREE.KinectGeometry = _kinectronForThree2.default;
25+
} else {
26+
console.log('Three.js was not found, perhaps you forgot to include it?');
27+
} //Import the class
28+
29+
},{"./kinectronForThree":4}],3:[function(require,module,exports){
1430
"use strict";
1531

1632
Object.defineProperty(exports, "__esModule", {
@@ -32,54 +48,37 @@ var KinectParams = {
3248

3349
exports.default = KinectParams;
3450

35-
},{}],3:[function(require,module,exports){
36-
'use strict';
37-
38-
var _kinectron_for_three = require('./kinectron_for_three');
39-
40-
var _kinectron_for_three2 = _interopRequireDefault(_kinectron_for_three);
41-
42-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43-
44-
//If three.js is in the global scope attach it
45-
if (THREE) {
46-
THREE.KinectGeometry = _kinectron_for_three2.default;
47-
} else {
48-
console.log('Three.js was not found, perhaps you forgot to include it?');
49-
} //Import the class
50-
51-
},{"./kinectron_for_three":4}],4:[function(require,module,exports){
51+
},{}],4:[function(require,module,exports){
5252
'use strict';
5353

5454
//Only for debugging, make sure to comment out for production
5555
// import * as THREE from 'three'
5656

57-
// Static camera parameters
58-
5957
Object.defineProperty(exports, "__esModule", {
6058
value: true
6159
});
6260

6361
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6462

65-
var _KinectParams = require('./KinectParams');
63+
var _shaderParams = require('./shaderParams');
6664

67-
var _KinectParams2 = _interopRequireDefault(_KinectParams);
65+
var _shaderParams2 = _interopRequireDefault(_shaderParams);
6866

6967
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7068

7169
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7270

7371
var glsl = require('glslify');
7472

75-
//Precision params for the geometry
76-
var VERTS_WIDE = 512;
77-
var VERTS_TALL = 424;
78-
7973
var KinectGeometry = function () {
8074
function KinectGeometry() {
8175
var _type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'mesh';
8276

77+
var _this = this;
78+
79+
var vertsWide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 512;
80+
var vertsTall = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 424;
81+
8382
_classCallCheck(this, KinectGeometry);
8483

8584
//Load the shaders
@@ -88,41 +87,12 @@ var KinectGeometry = function () {
8887

8988
//Build the geometry but only once! even for multipule instances
9089
if (!KinectGeometry.geo) {
91-
KinectGeometry.buildGeomtery();
90+
KinectGeometry.buildGeomtery(vertsWide, vertsTall);
9291
}
93-
console.log(_KinectParams2.default.v2.fx, _KinectParams2.default.v2.fy);
92+
9493
//Create the material
9594
this.material = new THREE.ShaderMaterial({
96-
uniforms: {
97-
isPoints: {
98-
type: "b",
99-
value: false
100-
},
101-
depthMap: {
102-
type: "t",
103-
value: null
104-
},
105-
texSize: {
106-
type: "vec2",
107-
value: new THREE.Vector2(0, 0)
108-
},
109-
fx: {
110-
type: "f",
111-
value: _KinectParams2.default.v2.fx
112-
},
113-
fy: {
114-
type: "f",
115-
value: _KinectParams2.default.v2.fy
116-
},
117-
cx: {
118-
type: "f",
119-
value: _KinectParams2.default.v2.cx
120-
},
121-
cy: {
122-
type: "f",
123-
value: _KinectParams2.default.v2.cy
124-
}
125-
},
95+
uniforms: _shaderParams2.default,
12696
vertexShader: kinectronVert,
12797
fragmentShader: kinectronFrag,
12898
transparent: true
@@ -132,43 +102,68 @@ var KinectGeometry = function () {
132102
this.material.side = THREE.DoubleSide;
133103

134104
//Switch a few things based on selected rendering type and create the mesh
135-
switch (_type) {
136-
case 'wire':
137-
this.material.wireframe = true;
138-
this.mesh = new THREE.Mesh(KinectGeometry.geo, this.material);
139-
break;
140-
141-
case 'points':
142-
this.material.uniforms.isPoints.value = true;
143-
this.mesh = new THREE.Points(KinectGeometry.geo, this.material);
144-
break;
145-
146-
default:
147-
this.mesh = new THREE.Mesh(KinectGeometry.geo, this.material);
148-
break;
149-
}
105+
this.buildMesh(_type);
150106

151107
var loader = new THREE.TextureLoader();
152-
//Hack around scope issue
153-
var me = this;
154-
loader.load('../assets/depth.jpg', function (texture) {
155-
me.material.uniforms.depthMap.value = texture;
156-
me.material.uniforms.texSize.value = new THREE.Vector2(texture.width, texture.height);
108+
109+
loader.load('../assets/test.jpg', function (texture) {
110+
111+
//Filter the texture
112+
texture.minFilter = THREE.LinearFilter;
113+
texture.magFilter = THREE.LinearFilter;
114+
115+
_this.material.uniforms.depthMap.value = texture;
116+
_this.material.uniforms.texSize.value = new THREE.Vector2(texture.width, texture.height);
157117
});
158118

119+
//Setup a three clock in case we need time in our shaders - get's updated only if update() is called recursively
120+
this.clock = new THREE.Clock();
121+
159122
//Expose the class as an object inside the THREE Object3D
160123
this.mesh.kinectron = this;
161124

162125
//Return the THREE Object3D instance for the mesh so you can just 'scene.add()' it
163126
return this.mesh;
164127
}
165128

166-
//A utility method to build a fully tesselated plane geometry
129+
/***************
130+
* Class methods
131+
***************/
132+
133+
//Change rendering type
167134

168135

169-
_createClass(KinectGeometry, null, [{
136+
_createClass(KinectGeometry, [{
137+
key: 'buildMesh',
138+
value: function buildMesh(type) {
139+
//Switch a few things based on selected rendering type and create the mesh
140+
switch (type) {
141+
case 'wire':
142+
this.material.wireframe = true;
143+
this.mesh = new THREE.Mesh(KinectGeometry.geo, this.material);
144+
break;
145+
146+
case 'points':
147+
this.material.uniforms.isPoints.value = true;
148+
this.mesh = new THREE.Points(KinectGeometry.geo, this.material);
149+
break;
150+
151+
default:
152+
this.mesh = new THREE.Mesh(KinectGeometry.geo, this.material);
153+
break;
154+
}
155+
}
156+
157+
//A utility method to build a fully tesselated plane geometry
158+
159+
}, {
160+
key: 'update',
161+
value: function update() {
162+
this.mesh.material.uniforms.time.value = this.clock.getElapsedTime();
163+
}
164+
}], [{
170165
key: 'buildGeomtery',
171-
value: function buildGeomtery() {
166+
value: function buildGeomtery(VERTS_WIDE, VERTS_TALL) {
172167
KinectGeometry.geo = new THREE.PlaneBufferGeometry(5, 4, VERTS_WIDE, VERTS_TALL);
173168
}
174169
}]);
@@ -178,4 +173,50 @@ var KinectGeometry = function () {
178173

179174
exports.default = KinectGeometry;
180175

181-
},{"./KinectParams":2,"glslify":1}]},{},[3]);
176+
},{"./shaderParams":5,"glslify":1}],5:[function(require,module,exports){
177+
"use strict";
178+
179+
Object.defineProperty(exports, "__esModule", {
180+
value: true
181+
});
182+
183+
var _kinectParams = require("./kinectParams");
184+
185+
var _kinectParams2 = _interopRequireDefault(_kinectParams);
186+
187+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
188+
189+
var ShaderParams = {
190+
isPoints: {
191+
type: "b",
192+
value: false
193+
},
194+
depthMap: {
195+
type: "t",
196+
value: null
197+
},
198+
texSize: {
199+
type: "vec2",
200+
value: new THREE.Vector2(0, 0)
201+
},
202+
fx: {
203+
type: "f",
204+
value: _kinectParams2.default.v2.fx
205+
},
206+
fy: {
207+
type: "f",
208+
value: _kinectParams2.default.v2.fy
209+
},
210+
cx: {
211+
type: "f",
212+
value: _kinectParams2.default.v2.cx
213+
},
214+
cy: {
215+
type: "f",
216+
value: _kinectParams2.default.v2.cy
217+
}
218+
};
219+
220+
exports.default = ShaderParams;
221+
222+
},{"./kinectParams":3}]},{},[2]);

examples/simple.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33

44
<head>
5-
<title>DepthKit - Simple example using Three.js</title>
5+
<title>Kinectron For Three.js - Simple Example</title>
66
<meta charset="utf-8">
77
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
88
<!-- Origin Trial Token, feature = WebVR (For Chrome M59+), origin = https://juniorxsound.github.io, expires = 2017-08-16 -->
@@ -52,10 +52,10 @@
5252

5353
// Setup camera
5454
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 500);
55-
camera.position.set(0, 1, 10);
55+
camera.position.set(-8, 1, 10);
5656
camera.lookAt(new THREE.Vector3(0,0,0));
5757

58-
//Create a kinectron geometry instance
58+
//Create a kinectron geometry instance - First argument takes the rendering type ("wire" / "points" / "mesh")
5959
var kinectronGeo = new THREE.KinectGeometry('wire');
6060

6161
//Add it to the scene

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//Import the class
2-
import KinectGeometry from './kinectron_for_three';
2+
import KinectGeometry from './kinectronForThree';
33

44
//If three.js is in the global scope attach it
55
if (THREE){

0 commit comments

Comments
 (0)