Use files generated from CoffeeScript
This commit is contained in:
@@ -1,149 +0,0 @@
|
||||
/*!
|
||||
* @class bkcore.ImageData
|
||||
*
|
||||
* Loads an image and gives access to pixel data.
|
||||
*
|
||||
* @author Thibaut 'BKcore' Despoulain <http://bkcore.com>
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @package bkcore
|
||||
*/
|
||||
var bkcore = bkcore || {};
|
||||
|
||||
/*!
|
||||
* Creates a new ImageData object
|
||||
*
|
||||
* @param path String The path of the image
|
||||
* @param callback Function A callback function to be called once th eimage is loaded
|
||||
*/
|
||||
bkcore.ImageData = function(path, callback)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.image = new Image();
|
||||
this.pixels = null;
|
||||
this.canvas = null;
|
||||
this.loaded = false;
|
||||
|
||||
this.image.onload = function() {
|
||||
self.canvas = document.createElement('canvas');
|
||||
self.canvas.width = self.image.width;
|
||||
self.canvas.height = self.image.height;
|
||||
|
||||
var context = self.canvas.getContext('2d');
|
||||
context.drawImage(self.image, 0, 0);
|
||||
|
||||
self.pixels = context.getImageData(0, 0, self.canvas.width, self.canvas.height);
|
||||
|
||||
self.loaded = true;
|
||||
|
||||
context = null;
|
||||
self.canvas = null;
|
||||
self.image = null;
|
||||
|
||||
if(callback) callback.call(self);
|
||||
};
|
||||
this.image.crossOrigin = "anonymous";
|
||||
this.image.src = path;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Gets pixel RGBA data at given index
|
||||
*
|
||||
* @param x int In pixels
|
||||
* @param y int In pixels
|
||||
* @return Object{r,g,b,a}
|
||||
*/
|
||||
bkcore.ImageData.prototype.getPixel = function(x, y)
|
||||
{
|
||||
if(this.pixels == null
|
||||
|| x < 0
|
||||
|| y < 0
|
||||
|| x >= this.pixels.width
|
||||
|| y >= this.pixels.height)
|
||||
return {r: 0, g: 0, b: 0, a:0};
|
||||
|
||||
var index = (y*this.pixels.width + x) * 4;
|
||||
|
||||
return {
|
||||
r: this.pixels.data[index],
|
||||
g: this.pixels.data[index + 1],
|
||||
b: this.pixels.data[index + 2],
|
||||
a: this.pixels.data[index + 3]
|
||||
};
|
||||
};
|
||||
|
||||
/*!
|
||||
* Gets pixel RGBA data at given float index using bilinear interpolation
|
||||
*
|
||||
* @param x float In subpixels
|
||||
* @param y float In subpixels
|
||||
* @return Object{r,g,b,a}
|
||||
*/
|
||||
bkcore.ImageData.prototype.getPixelBilinear = function(fx, fy)
|
||||
{
|
||||
var x = Math.floor(fx);
|
||||
var y = Math.floor(fy);
|
||||
var rx = fx - x - .5;
|
||||
var ry = fy - y - .5;
|
||||
var ax = Math.abs(rx);
|
||||
var ay = Math.abs(ry);
|
||||
var c, cxy, cx, cy, cf1, cf2;
|
||||
var dx = rx < 0 ? -1 : 1;
|
||||
var dy = ry < 0 ? -1 : 1;
|
||||
|
||||
c = this.getPixel(x, y);
|
||||
cx = this.getPixel(x+dx, y);
|
||||
cy = this.getPixel(x, y+dy);
|
||||
cxy = this.getPixel(x+dx, y+dy);
|
||||
|
||||
cf1 = [
|
||||
(1-ax) * c.r + ax * cx.r,
|
||||
(1-ax) * c.g + ax * cx.g,
|
||||
(1-ax) * c.b + ax * cx.b,
|
||||
(1-ax) * c.a + ax * cx.a
|
||||
];
|
||||
|
||||
cf2 = [
|
||||
(1-ax) * cy.r + ax * cxy.r,
|
||||
(1-ax) * cy.g + ax * cxy.g,
|
||||
(1-ax) * cy.b + ax * cxy.b,
|
||||
(1-ax) * cy.a + ax * cxy.a
|
||||
];
|
||||
|
||||
return {
|
||||
r: (1-ay) * cf1[0] + ay * cf2[0],
|
||||
g: (1-ay) * cf1[1] + ay * cf2[1],
|
||||
b: (1-ay) * cf1[2] + ay * cf2[2],
|
||||
a: (1-ay) * cf1[3] + ay * cf2[3]
|
||||
};
|
||||
}
|
||||
|
||||
/*!
|
||||
* Gets pixel data at given index
|
||||
* as 3-bytes integer (for floating-point textures erzats, from RGB values)
|
||||
*
|
||||
* @param x int In pixels
|
||||
* @param y int In pixels
|
||||
* @return int (R + G*255 + B*255*255)
|
||||
*/
|
||||
bkcore.ImageData.prototype.getPixelF = function(x, y)
|
||||
{
|
||||
var color = this.getPixel(x, y);
|
||||
return color.r + color.g * 255 + color.b * 255 * 255;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Gets pixel data at given float index using bilinear interpolationas
|
||||
* as 3-bytes integer (for floating-point textures erzats, from RGB values)
|
||||
*
|
||||
* @param x float In subpixels
|
||||
* @param y float In subpixels
|
||||
* @return Object{r,g,b,a}
|
||||
*/
|
||||
bkcore.ImageData.prototype.getPixelFBilinear = function(fx, fy)
|
||||
{
|
||||
var color = this.getPixelBilinear(fx, fy);
|
||||
return color.r + color.g * 255.0 + color.b * 255.0 * 255.0;
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
/*!
|
||||
* @class bkcore.Timer
|
||||
*
|
||||
* new Date().getTime() wrapper to use as timers.
|
||||
*
|
||||
* @author Thibaut 'BKcore' Despoulain <http://bkcore.com>
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @package bkcore
|
||||
*/
|
||||
var bkcore = bkcore || {};
|
||||
|
||||
/*!
|
||||
* Creates a new timer, inactive by default.
|
||||
* Call Timer.start() to activate.
|
||||
*/
|
||||
bkcore.Timer = function()
|
||||
{
|
||||
this.time = {
|
||||
start: 0,
|
||||
current: 0,
|
||||
previous: 0,
|
||||
elapsed: 0,
|
||||
delta: 0
|
||||
}
|
||||
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Starts/restarts the timer.
|
||||
*/
|
||||
bkcore.Timer.prototype.start = function()
|
||||
{
|
||||
var now = new Date().getTime();
|
||||
|
||||
this.time.start = now;
|
||||
this.time.current = now;
|
||||
this.time.previous = now;
|
||||
this.time.elapsed = 0;
|
||||
this.time.delta = 0;
|
||||
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Pauses(true)/Unpauses(false) the timer.
|
||||
*
|
||||
* @param bool Do pause
|
||||
*/
|
||||
bkcore.Timer.prototype.pause = function(bool)
|
||||
{
|
||||
this.active = !bool;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Update method to be called inside a RAF loop
|
||||
*/
|
||||
bkcore.Timer.prototype.update = function()
|
||||
{
|
||||
if(!this.active) return;
|
||||
|
||||
var now = new Date().getTime();
|
||||
|
||||
this.time.current = now;
|
||||
this.time.elapsed = this.time.current - this.time.start;
|
||||
this.time.delta = now - this.time.previous;
|
||||
this.time.previous = now;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns a formatted version of the current elapsed time using msToTime().
|
||||
*/
|
||||
bkcore.Timer.prototype.getElapsedTime = function()
|
||||
{
|
||||
return bkcore.Timer.msToTime(this.time.elapsed);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Formats a millisecond integer into a h/m/s/ms object
|
||||
*
|
||||
* @param x int In milliseconds
|
||||
* @return Object{h,m,s,ms}
|
||||
*/
|
||||
bkcore.Timer.msToTime = function(t)
|
||||
{
|
||||
var ms, s, m, h;
|
||||
|
||||
ms = t%1000;
|
||||
|
||||
s = Math.floor((t/1000)%60);
|
||||
|
||||
m = Math.floor((t/60000)%60);
|
||||
h = Math.floor((t/3600000));
|
||||
|
||||
return {h:h, m:m, s:s, ms:ms};
|
||||
}
|
||||
|
||||
/*!
|
||||
* Formats a millisecond integer into a h/m/s/ms object with prefix zeros
|
||||
*
|
||||
* @param x int In milliseconds
|
||||
* @return Object<string>{h,m,s,ms}
|
||||
*/
|
||||
bkcore.Timer.msToTimeString = function(t)
|
||||
{
|
||||
var ms, s, m, h;
|
||||
|
||||
ms = t%1000;
|
||||
if(ms < 10) ms = "00"+ms;
|
||||
else if(ms < 100) ms = "0"+ms;
|
||||
|
||||
s = Math.floor((t/1000)%60);
|
||||
if(s < 10) s = "0"+s;
|
||||
|
||||
m = Math.floor((t/60000)%60);
|
||||
h = Math.floor((t/3600000));
|
||||
|
||||
return {h:h, m:m, s:s, ms:ms};
|
||||
}
|
||||
-197
@@ -1,197 +0,0 @@
|
||||
/*!
|
||||
* @class bkcore.Utils
|
||||
*
|
||||
* Various useful methods
|
||||
*
|
||||
* @author Thibaut 'BKcore' Despoulain <http://bkcore.com>
|
||||
*/
|
||||
|
||||
/*!
|
||||
* @package bkcore
|
||||
*/
|
||||
var bkcore = bkcore || {};
|
||||
|
||||
bkcore.Utils = {};
|
||||
|
||||
/**
|
||||
* Creates a bkcore.threejs.Shaders[ "normalV" | "normal" ] material with given parameters
|
||||
*/
|
||||
bkcore.Utils.createNormalMaterial = function(opts)
|
||||
{
|
||||
var shader = bkcore.threejs.Shaders[ opts.perPixel==false ? "normalV" : "normal" ];
|
||||
|
||||
var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
|
||||
|
||||
uniforms[ "enableDiffuse" ].value = true;
|
||||
uniforms[ "enableSpecular" ].value = true;
|
||||
uniforms[ "enableReflection" ].value = (opts.cube != undefined);
|
||||
|
||||
uniforms[ "tNormal" ].texture = opts.normal;
|
||||
uniforms[ "tDiffuse" ].texture = opts.diffuse;
|
||||
uniforms[ "tSpecular" ].texture = opts.specular;
|
||||
|
||||
uniforms[ "uAmbientColor" ].value.setHex(opts.ambient == undefined ? 0x444444 : opts.ambient);
|
||||
uniforms[ "uAmbientColor" ].value.convertGammaToLinear();
|
||||
|
||||
uniforms[ "uNormalScale" ].value = opts.normalScale == undefined ? 1.0 : opts.normalScale;
|
||||
|
||||
if(opts.cube != undefined)
|
||||
{
|
||||
uniforms[ "tCube" ].texture = opts.cube;
|
||||
uniforms[ "uReflectivity" ].value = opts.reflectivity == undefined ? 0.9 : opts.reflectivity;
|
||||
}
|
||||
|
||||
uniforms[ "uShininess" ].value = opts.shininess == undefined ? 42 : opts.shininess;
|
||||
|
||||
|
||||
var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: false };
|
||||
|
||||
var material = new THREE.ShaderMaterial( parameters );
|
||||
material.perPixel = true;
|
||||
material.metal = opts.metal == undefined ? false : opts.metal;
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
/**
|
||||
* Projects an object origin vector to screen using given camera
|
||||
* @param THREE.Object3D object The object which origin you want to project
|
||||
* @param THREE.Camera camera The camera of the projection
|
||||
* @return THEE.Vector3 Projected verctor
|
||||
*/
|
||||
bkcore.Utils.projectOnScreen = function(object, camera)
|
||||
{
|
||||
var mat = new THREE.Matrix4();
|
||||
mat.multiply( camera.matrixWorldInverse, object.matrixWorld);
|
||||
mat.multiply( camera.projectionMatrix , mat);
|
||||
|
||||
var c = mat.n44;
|
||||
var lPos = new THREE.Vector3(mat.n14/c, mat.n24/c, mat.n34/c);
|
||||
lPos.multiplyScalar(0.5);
|
||||
lPos.addScalar(0.5);
|
||||
return lPos;
|
||||
}
|
||||
|
||||
bkcore.Utils.URLParameters = null;
|
||||
|
||||
/**
|
||||
* Get an url parameter
|
||||
* @param String name Parameter slug
|
||||
* @return Mixed
|
||||
*/
|
||||
bkcore.Utils.getURLParameter = function(name)
|
||||
{
|
||||
if(bkcore.Utils.URLParameters == null)
|
||||
{
|
||||
var vars = {};
|
||||
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
|
||||
function(m,key,value) {
|
||||
vars[key] = value;
|
||||
}
|
||||
);
|
||||
bkcore.Utils.URLParameters = vars;
|
||||
}
|
||||
|
||||
return bkcore.Utils.URLParameters[name];
|
||||
}
|
||||
|
||||
bkcore.Utils.getOffsetTop = function(obj)
|
||||
{
|
||||
var curtop = 0;
|
||||
if (obj.offsetParent) {
|
||||
do {
|
||||
curtop += obj.offsetTop;
|
||||
} while (obj = obj.offsetParent);
|
||||
}
|
||||
else
|
||||
{
|
||||
curtop = obj.offsetTop;
|
||||
}
|
||||
return [curtop];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls page to given element id
|
||||
* @param string id The ID of the element
|
||||
*/
|
||||
bkcore.Utils.scrollTo = function(id)
|
||||
{
|
||||
window.scroll(
|
||||
0,
|
||||
bkcore.Utils.getOffsetTop(
|
||||
document.getElementById(id)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or remove a class from an element
|
||||
* @param string id [description]
|
||||
* @param string cssclass [description]
|
||||
* @param bool active [description]
|
||||
*/
|
||||
bkcore.Utils.updateClass = function(id, cssclass, active)
|
||||
{
|
||||
var element = document.getElementById(id);
|
||||
if(active)
|
||||
element.classList.add(cssclass);
|
||||
else
|
||||
element.classList.remove(cssclass);
|
||||
}
|
||||
|
||||
/**
|
||||
* PErforms an XMLHttpRequest
|
||||
* @param string url [description]
|
||||
* @param bool postData true = POST, false = GET
|
||||
* @param {Function} callback [description]
|
||||
* @param {Object} data [description]
|
||||
*/
|
||||
bkcore.Utils.request = function(url, postData, callback, data)
|
||||
{
|
||||
var XMLHttpFactories = [
|
||||
function () {return new XMLHttpRequest()},
|
||||
function () {return new ActiveXObject("Msxml2.XMLHTTP")},
|
||||
function () {return new ActiveXObject("Msxml3.XMLHTTP")},
|
||||
function () {return new ActiveXObject("Microsoft.XMLHTTP")}
|
||||
];
|
||||
|
||||
function createXMLHTTPObject() {
|
||||
var xmlhttp = false;
|
||||
for (var i=0;i<XMLHttpFactories.length;i++) {
|
||||
try {
|
||||
xmlhttp = XMLHttpFactories[i]();
|
||||
}
|
||||
catch (e) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
var req = createXMLHTTPObject();
|
||||
if (!req) return;
|
||||
var method = (postData) ? "POST" : "GET";
|
||||
|
||||
var qdata = "o=bk";
|
||||
if(data != undefined) for(var i in data)
|
||||
{
|
||||
qdata += "&"+i+"="+data[i];
|
||||
if(!postData) url += "?"+qdata;
|
||||
}
|
||||
|
||||
req.open(method,url,true);
|
||||
|
||||
if(postData)
|
||||
req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
||||
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState != 4) return;
|
||||
if (req.status != 200 && req.status != 304) {
|
||||
return;
|
||||
}
|
||||
callback(req);
|
||||
}
|
||||
|
||||
req.send(qdata);
|
||||
}
|
||||
+3
-3
@@ -101,9 +101,9 @@
|
||||
<script src="bkcore.coffee/controllers/OrientationController.js"></script>
|
||||
<script src="bkcore.coffee/controllers/GamepadController.js"></script>
|
||||
|
||||
<script src="bkcore/Timer.js"></script>
|
||||
<script src="bkcore/ImageData.js"></script>
|
||||
<script src="bkcore/Utils.js"></script>
|
||||
<script src="bkcore.coffee/Timer.js"></script>
|
||||
<script src="bkcore.coffee/ImageData.js"></script>
|
||||
<script src="bkcore.coffee/Utils.js"></script>
|
||||
|
||||
<script src="bkcore/threejs/RenderManager.js"></script>
|
||||
<script src="bkcore/threejs/Shaders.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user