Comparing version 0.0.9 to 0.0.11
@@ -1,5 +0,5 @@ | ||
import { Game } from './src/core/game.js'; | ||
import { Entity } from './src/core/entity.js'; | ||
import { math } from './src/core/math.js'; | ||
export { Game } from './src/core/game.js'; | ||
export { Entity } from './src/core/entity.js'; | ||
export { math } from './src/core/math.js'; | ||
export { Entity , Game, math }; | ||
// export { Entity , Game, math }; |
@@ -1,31 +0,152 @@ | ||
var B="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this,H="function"==typeof Object.create?Object.create:function(e){function k(){}k.prototype=e;return new k},I;if("function"==typeof Object.setPrototypeOf)I=Object.setPrototypeOf;else{var J;a:{var P={ga:!0},Q={};try{Q.__proto__=P;J=Q.ga;break a}catch(e){}J=!1}I=J?function(e,k){e.__proto__=k;if(e.__proto__!==k)throw new TypeError(e+" is not extensible");return e}:null}var R=I; | ||
function S(e,k){e.prototype=H(k.prototype);e.prototype.constructor=e;if(R)R(e,k);else for(var g in k)if("prototype"!=g)if(Object.defineProperties){var n=Object.getOwnPropertyDescriptor(k,g);n&&Object.defineProperty(e,g,n)}else e[g]=k[g];e.Oa=k.prototype}var V="function"==typeof Object.defineProperties?Object.defineProperty:function(e,k,g){e!=Array.prototype&&e!=Object.prototype&&(e[k]=g.value)};function W(){W=function(){};B.Symbol||(B.Symbol=X)} | ||
var X=function(){var e=0;return function(k){return"jscomp_symbol_"+(k||"")+e++}}();function Y(){W();var e=B.Symbol.iterator;e||(e=B.Symbol.iterator=B.Symbol("iterator"));"function"!=typeof Array.prototype[e]&&V(Array.prototype,e,{configurable:!0,writable:!0,value:function(){return Z(this)}});Y=function(){}}function Z(e){var k=0;return aa(function(){return k<e.length?{done:!1,value:e[k++]}:{done:!0}})}function aa(e){Y();e={next:e};e[B.Symbol.iterator]=function(){return this};return e} | ||
function ba(e){if(!(e instanceof Array)){Y();var k=e[Symbol.iterator];e=k?k.call(e):Z(e);for(var g=[];!(k=e.next()).done;)g.push(k.value);e=g}return e} | ||
(function(){function e(a){a=void 0===a?{}:a;a.l=ca;a.g=da;a.j=ea;return n.call(this,a)||this}function k(){var a=T(c.VERTEX_SHADER,"\n precision mediump float;\n uniform mat4 p;\n uniform mat4 v;\n uniform mat4 w;\n attribute vec3 P;\n attribute vec3 N;\n varying vec3 fp;\n varying vec3 fn;\n\n void main()\n {\n fp = (w * vec4(P, 1.0)).xyz;\n fn = (w * vec4(N, 0.0)).xyz;\n gl_Position = p * v * vec4(fp, 1.0);\n }\n"),b=T(c.FRAGMENT_SHADER,"\n precision mediump float;\n uniform vec3 lp;\n uniform vec4 c;\n uniform vec2 li;\n varying vec3 fp;\n varying vec3 fn;\n\n void main()\n {\n gl_FragColor = vec4(c.rgb * li.x + li.y * max(dot(fn, normalize(lp - fp)), 0.0), c.a);\n }\n"), | ||
d=c.createProgram();c.attachShader(d,a);c.attachShader(d,b);c.linkProgram(d);if(!c.getProgramParameter(d,c.LINK_STATUS))throw c.getProgramInfoLog(d);this.c=d;this.c.error?console.log(this.c.error):(this.u={p:c.getUniformLocation(this.c,"p"),Ia:c.getUniformLocation(this.c,"v"),Ja:c.getUniformLocation(this.c,"w"),xa:c.getUniformLocation(this.c,"lp"),ia:c.getUniformLocation(this.c,"c"),wa:c.getUniformLocation(this.c,"li")},this.B={R:c.getAttribLocation(this.c,"P"),P:c.getAttribLocation(this.c,"N")})} | ||
function g(a){var b=this;this.entities=[];this.ca=!0;this.options=fa;this.m=new n;this.m.w=this;this.$=h.b.create();this.fa=h.b.create();h.b.perspective(this.$,h.Ga(90),q.width/q.height,.35,85);a=a||{};Object.keys(a).forEach(function(d){b.options[d]=a[d]});this.L=this.options.L;this.F=this.options.F;this.m.U=this.options.V;this.D=this.options.D;this.i=A(this.D);q.width=this.options.width;q.height=this.options.height;this.options.ma.appendChild(q);this.o=performance.now();this.I=1E3/this.options.pa; | ||
this.keys={};window.addEventListener("keydown",this.ta.bind(this));window.addEventListener("keyup",this.ua.bind(this));this.actions={};this.da("undefined"!==typeof performance&&performance.now()||0);c.enable(c.CULL_FACE);c.enable(c.DEPTH_TEST);c.clearColor(this.i[0],this.i[1],this.i[2],1);c.clear(c.DEPTH_BUFFER_BIT|c.COLOR_BUFFER_BIT)}function n(a){a=void 0===a?{}:a;this.a=h.b.create();this.J=h.b.create();this.position=a.position||x.slice();this.scale=a.scale||ha.slice();this.origin=a.origin||x.slice(); | ||
if(this.h=a.h)this.T=[],this.ja=1,this.color=a.color||"#ffffff";this.entities=[];this.U=!1;this.s=3.5;this.H=1.5;this.g=this.g||a.g;this.l=this.l||a.l;this.j=this.j||a.j;this.c=this.h&&this.h.c;this.O=!1;this.dir={};this.K={87:"f",65:"l",68:"r",83:"b",81:"u",69:"d",38:"r_u",40:"r_d",39:"r_r",37:"r_l"};this.l&&this.g&&this.j&&this.ka()}function A(a){"#"===a.charAt(0)&&(a=a.substr(1));3===a.length&&(a=a.split("").map(function(a){return a+""+a}));return a.match(/.{1,2}/g).map(function(a){return parseFloat((parseInt(a, | ||
16)/255).toFixed(1))})}function U(a){var b=c.createBuffer();c.bindBuffer(c.ARRAY_BUFFER,b);c.bufferData(c.ARRAY_BUFFER,new Float32Array(a),c.STATIC_DRAW);return b}function T(a,b){a=c.createShader(a);c.shaderSource(a,b);c.compileShader(a);if(!c.getShaderParameter(a,c.COMPILE_STATUS))throw c.getShaderInfoLog(a);return a}function ia(){var a=new K(3);a[0]=0;a[1]=0;a[2]=0;return a}function L(a,b,d){var f=new K(3);f[0]=a;f[1]=b;f[2]=d;return f}function M(a,b){var d=b[0],f=b[1],c=b[2];d=d*d+f*f+c*c;0<d&& | ||
(d=1/Math.sqrt(d),a[0]=b[0]*d,a[1]=b[1]*d,a[2]=b[2]*d);return a}var q=document.createElement("canvas"),c=q.getContext("webgl"),x=[0,0,0],ha=[1,1,1],K="undefined"!==typeof Float32Array?Float32Array:Array;(function(){var a=ia();return function(b,d,f,c,l,m){d||(d=3);f||(f=0);for(c=c?Math.min(c*d+f,b.length):b.length;f<c;f+=d)a[0]=b[f],a[1]=b[f+1],a[2]=b[f+2],l(a,a,m),b[f]=a[0],b[f+1]=a[1],b[f+2]=a[2];return b}})();var h={f:{v:L,normalize:M,Ma:function(a,b){var d=b[0]-a[0],f=b[1]-a[1];a=b[2]-a[2];return Math.sqrt(d* | ||
d+f*f+a*a)},angle:function(a,b){a=L(a[0],a[1],a[2]);b=L(b[0],b[1],b[2]);M(a,a);M(b,b);b=a[0]*b[0]+a[1]*b[1]+a[2]*b[2];return 1<b?0:-1>b?Math.PI:Math.acos(b)},Ea:function(a,b,d){a[0]=b[0]-d[0];a[1]=b[1]-d[1];a[2]=b[2]-d[2];return a},add:function(a,b,d){a[0]=b[0]+d[0];a[1]=b[1]+d[1];a[2]=b[2]+d[2];return a},scale:function(a,b,d){a[0]=b[0]*d;a[1]=b[1]*d;a[2]=b[2]*d;return a},Pa:function(a,b,d){var f=b[0],c=b[1];b=b[2];var l=d[3]*f+d[7]*c+d[11]*b+d[15];l=l||1;a[0]=(d[0]*f+d[4]*c+d[8]*b+d[12])/l;a[1]= | ||
(d[1]*f+d[5]*c+d[9]*b+d[13])/l;a[2]=(d[2]*f+d[6]*c+d[10]*b+d[14])/l;return a},La:function(a,b,d){var f=b[0],c=b[1];b=b[2];var l=d[0],m=d[1];d=d[2];a[0]=c*d-b*m;a[1]=b*l-f*d;a[2]=f*m-c*l;return a}},b:{create:function(){var a=new K(16);a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},perspective:function(a,b,d,f,c){b=1/Math.tan(b/2);var l=1/(f-c);a[0]=b/d;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=b;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]= | ||
(c+f)*l;a[11]=-1;a[12]=0;a[13]=0;a[14]=2*c*f*l;a[15]=0;return a},multiply:function(a,b,d){var f=b[0],c=b[1],l=b[2],m=b[3],e=b[4],C=b[5],p=b[6],u=b[7],h=b[8],k=b[9],g=b[10],n=b[11],y=b[12],z=b[13],q=b[14];b=b[15];var v=d[0],w=d[1],r=d[2],t=d[3];a[0]=v*f+w*e+r*h+t*y;a[1]=v*c+w*C+r*k+t*z;a[2]=v*l+w*p+r*g+t*q;a[3]=v*m+w*u+r*n+t*b;v=d[4];w=d[5];r=d[6];t=d[7];a[4]=v*f+w*e+r*h+t*y;a[5]=v*c+w*C+r*k+t*z;a[6]=v*l+w*p+r*g+t*q;a[7]=v*m+w*u+r*n+t*b;v=d[8];w=d[9];r=d[10];t=d[11];a[8]=v*f+w*e+r*h+t*y;a[9]=v*c+w* | ||
C+r*k+t*z;a[10]=v*l+w*p+r*g+t*q;a[11]=v*m+w*u+r*n+t*b;v=d[12];w=d[13];r=d[14];t=d[15];a[12]=v*f+w*e+r*h+t*y;a[13]=v*c+w*C+r*k+t*z;a[14]=v*l+w*p+r*g+t*q;a[15]=v*m+w*u+r*n+t*b;return a},rotate:function(a,b,d,f){var c=f[0],l=f[1];f=f[2];var m=Math.sqrt(c*c+l*l+f*f);if(1E-6>Math.abs(m))return null;m=1/m;c*=m;l*=m;f*=m;var e=Math.sin(d);var h=Math.cos(d);var p=1-h;d=b[0];m=b[1];var u=b[2];var k=b[3];var g=b[4];var n=b[5];var q=b[6];var y=b[7];var z=b[8];var A=b[9];var v=b[10];var w=b[11];var r=c*c*p+h; | ||
var t=l*c*p+f*e;var x=f*c*p-l*e;var D=c*l*p-f*e;var E=l*l*p+h;var F=f*l*p+c*e;var G=c*f*p+l*e;c=l*f*p-c*e;l=f*f*p+h;a[0]=d*r+g*t+z*x;a[1]=m*r+n*t+A*x;a[2]=u*r+q*t+v*x;a[3]=k*r+y*t+w*x;a[4]=d*D+g*E+z*F;a[5]=m*D+n*E+A*F;a[6]=u*D+q*E+v*F;a[7]=k*D+y*E+w*F;a[8]=d*G+g*c+z*l;a[9]=m*G+n*c+A*l;a[10]=u*G+q*c+v*l;a[11]=k*G+y*c+w*l;b!==a&&(a[12]=b[12],a[13]=b[13],a[14]=b[14],a[15]=b[15]);return a},translate:function(a,b,d){var c=d[0],e=d[1];d=d[2];if(b===a)a[12]=b[0]*c+b[4]*e+b[8]*d+b[12],a[13]=b[1]*c+b[5]*e+ | ||
b[9]*d+b[13],a[14]=b[2]*c+b[6]*e+b[10]*d+b[14],a[15]=b[3]*c+b[7]*e+b[11]*d+b[15];else{var l=b[0];var m=b[1];var h=b[2];var k=b[3];var p=b[4];var u=b[5];var g=b[6];var n=b[7];var q=b[8];var x=b[9];var y=b[10];var z=b[11];a[0]=l;a[1]=m;a[2]=h;a[3]=k;a[4]=p;a[5]=u;a[6]=g;a[7]=n;a[8]=q;a[9]=x;a[10]=y;a[11]=z;a[12]=l*c+p*e+q*d+b[12];a[13]=m*c+u*e+x*d+b[13];a[14]=h*c+g*e+y*d+b[14];a[15]=k*c+n*e+z*d+b[15]}return a},scale:function(a,b,d){var c=d[0],e=d[1];d=d[2];a[0]=b[0]*c;a[1]=b[1]*c;a[2]=b[2]*c;a[3]=b[3]* | ||
c;a[4]=b[4]*e;a[5]=b[5]*e;a[6]=b[6]*e;a[7]=b[7]*e;a[8]=b[8]*d;a[9]=b[9]*d;a[10]=b[10]*d;a[11]=b[11]*d;a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15];return a},sa:function(a){a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},qa:function(a,b,d){var c=d[0],e=d[1];d=d[2];var l=Math.sqrt(c*c+e*e+d*d);if(1E-6>Math.abs(l))return null;l=1/l;c*=l;e*=l;d*=l;l=Math.sin(b);b=Math.cos(b);var m=1-b;a[0]=c*c*m+b;a[1]=e*c*m+d*l;a[2]=d* | ||
c*m-e*l;a[3]=0;a[4]=c*e*m-d*l;a[5]=e*e*m+b;a[6]=d*e*m+c*l;a[7]=0;a[8]=c*d*m+e*l;a[9]=e*d*m-c*l;a[10]=d*d*m+b;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a},W:function(a,b,d,c){var e=b[0],f=b[1];b=b[2];var m=c[0];var h=c[1];var k=c[2];var p=d[0];c=d[1];var u=d[2];if(1E-6>Math.abs(e-p)&&1E-6>Math.abs(f-c)&&1E-6>Math.abs(b-u))return mat4.sa(a);d=e-p;c=f-c;p=b-u;var g=1/Math.sqrt(d*d+c*c+p*p);d*=g;c*=g;p*=g;u=h*p-k*c;k=k*d-m*p;m=m*c-h*d;(g=Math.sqrt(u*u+k*k+m*m))?(g=1/g,u*=g,k*=g,m*=g):m=k=u=0;h=c* | ||
m-p*k;var n=p*u-d*m;var q=d*k-c*u;(g=Math.sqrt(h*h+n*n+q*q))?(g=1/g,h*=g,n*=g,q*=g):q=n=h=0;a[0]=u;a[1]=h;a[2]=d;a[3]=0;a[4]=k;a[5]=n;a[6]=c;a[7]=0;a[8]=m;a[9]=q;a[10]=p;a[11]=0;a[12]=-(u*e+k*f+m*b);a[13]=-(h*e+n*f+q*b);a[14]=-(d*e+c*f+p*b);a[15]=1;return a},Fa:function(a,b,d,c){var e=b[0],f=b[1];b=b[2];var m=c[0],k=c[1],h=c[2];c=e-d[0];var g=f-d[1];d=b-d[2];var n=c*c+g*g+d*d;0<n&&(n=1/Math.sqrt(n),c*=n,g*=n,d*=n);n=k*d-h*g;h=h*c-m*d;m=m*g-k*c;a[0]=n;a[1]=h;a[2]=m;a[3]=0;a[4]=g*m-d*h;a[5]=d*n-c*m; | ||
a[6]=c*h-g*n;a[7]=0;a[8]=c;a[9]=g;a[10]=d;a[11]=0;a[12]=e;a[13]=f;a[14]=b;a[15]=1;return a}},Ga:function(a){return a*Math.PI/180},Na:A};n.prototype.W=function(a,b){b=void 0===b?this.ea:b;h.b.Fa(this.a,this.position,a,b)};n.prototype.ka=function(){var a=U(this.l),b=this.g,d=c.createBuffer();c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,d);c.bufferData(c.ELEMENT_ARRAY_BUFFER,new Uint16Array(b),c.STATIC_DRAW);this.C={l:a,g:d,za:this.g.length,j:U(this.j)}};n.prototype.add=function(a){a.parent=this;this.entities.push(a)}; | ||
n.prototype.ra=function(a){var b=[];h.f.add(b,this.position,this.forward);h.b.W(a,this.position,b,this.ea)};n.prototype.aa=function(a,b){var d=this.origin.map(function(a){return-a}),c=h.b.create();h.b.qa(c,b,a);h.b.translate(this.a,this.a,this.origin);h.b.multiply(this.a,this.a,c);h.b.translate(this.a,this.a,d)};n.prototype.N=function(a){this.aa(h.f.v(0,1,0),a)};n.prototype.ba=function(a){this.aa(h.f.v(1,0,0),a)};n.prototype.M=function(a,b){var d=x.slice();h.f.scale(d,a,b);h.b.translate(this.a,this.a, | ||
d)};n.prototype.Y=function(a){this.M(h.f.v(1,0,0),a)};n.prototype.Z=function(a){this.M(h.f.v(0,1,0),a)};n.prototype.X=function(a){this.M(h.f.v(0,0,1),a)};n.prototype.la=function(a){this.dir.oa&&!this.dir.ha&&this.X(a/1E3*this.s);this.dir.ha&&!this.dir.oa&&this.X(-a/1E3*this.s);this.dir.r&&!this.dir.va&&this.Y(-a/1E3*this.s);this.dir.va&&!this.dir.r&&this.Y(a/1E3*this.s);this.dir.Ha&&!this.dir.d&&this.Z(a/1E3*this.s);this.dir.d&&!this.dir.Ha&&this.Z(-a/1E3*this.s);this.dir.Ca&&!this.dir.Ba&&this.N(-a/ | ||
1E3*this.H);this.dir.Ba&&!this.dir.Ca&&this.N(a/1E3*this.H);this.dir.Da&&!this.dir.Aa&&this.ba(-a/1E3*this.H);this.dir.Aa&&!this.dir.Da&&this.ba(a/1E3*this.H)};n.prototype.update=function(a){var b=this;!this.O&&(this.U&&this.w&&(Object.keys(this.K).forEach(function(a){b.K[a]&&(b.dir[b.K[a]]=b.w.keys[a]||!1)}),this.la(a)),this.h||this.entities.length)&&(this.parent?h.b.multiply(this.J,this.parent.J,this.a):this.J=this.a.slice(),this.entities.forEach(function(a){return a.update()}))};n.prototype.G= | ||
function(a){!this.O&&this.h&&this.h.G(this);!this.O&&this.entities.forEach(function(b){b.G(a)})};B.Object.defineProperties(n.prototype,{left:{configurable:!0,enumerable:!0,get:function(){var a=this.a.slice(0,3);return h.f.normalize(a,a)}},ea:{configurable:!0,enumerable:!0,get:function(){var a=this.a.slice(4,7);return h.f.normalize(a,a)}},forward:{configurable:!0,enumerable:!0,get:function(){var a=this.a.slice(8,11);return h.f.normalize(a,a)}},position:{configurable:!0,enumerable:!0,set:function(a){var b= | ||
[];h.f.Ea(b,a,this.position);h.b.translate(this.a,this.a,b)},get:function(){return this.a.slice(12,15)}},scale:{configurable:!0,enumerable:!0,set:function(a){h.b.scale(this.a,this.a,a)}},color:{configurable:!0,enumerable:!0,set:function(a){this.S=a||"#ffffff";this.T=[].concat(ba(A(this.S)),[this.ja])},get:function(){return this.S}}});var fa={width:800,height:600,ma:document.body,pa:60,Ka:!0,V:!1,D:"#FFFFFF",L:x.slice(),F:.4};g.prototype.stop=function(){};g.prototype.start=function(){};g.prototype.da= | ||
function(a){var b=this;window.requestAnimationFrame(function(a){return b.da(a)});a>this.o+this.I&&(this.ya(Math.floor((a-this.o)/this.I)),this.na(this.o))};g.prototype.ta=function(a){this.keys[a.keyCode]=!0};g.prototype.ua=function(a){this.keys[a.keyCode]=!1};g.prototype.ya=function(a){if(this.ca)for(var b=0;b<a;b++)this.o+=this.I,this.update(this.o)};g.prototype.update=function(a){var b=this;Object.keys(this.actions).forEach(function(c){if(b.actions[c])b.actions[c](a)});this.entities.forEach(function(a){return a.update()}); | ||
this.m.update(this.I,this);this.m.ra(this.fa)};g.prototype.na=function(a){this.ca&&(this.i=A(this.D),c.clearColor(this.i[0],this.i[1],this.i[2],1),c.clear(c.COLOR_BUFFER_BIT|c.DEPTH_BUFFER_BIT),c.viewport(0,0,q.width,q.height),this.entities.forEach(function(b){return b.G(a)}))};g.prototype.add=function(a){a.w=this;this.entities.push(a)};k.prototype.G=function(a){for(var b=a,d=b.w;b.parent&&!d;)b=b.parent,d=b.w;c.useProgram(this.c);c.uniformMatrix4fv(this.u.p,c.A,d.$);c.uniformMatrix4fv(this.u.Ia, | ||
c.A,d.fa);c.uniformMatrix4fv(this.u.Ja,c.A,a.J);c.uniform4fv(this.u.ia,a.T);c.bindBuffer(c.ARRAY_BUFFER,a.C.l);c.vertexAttribPointer(this.B.R,3,c.FLOAT,c.A,0,0);c.enableVertexAttribArray(this.B.R);c.bindBuffer(c.ARRAY_BUFFER,a.C.j);c.vertexAttribPointer(this.B.P,3,c.FLOAT,c.A,0,0);c.enableVertexAttribArray(this.B.P);c.bindBuffer(c.ARRAY_BUFFER,null);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,a.C.g);c.drawElements(c.TRIANGLES,a.C.za,c.UNSIGNED_SHORT,0);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,null);c.uniform3fv(this.u.xa, | ||
d.L);c.uniform2fv(this.u.wa,[1-d.F,d.F])};var ca=[.5,.5,.5,.5,.5,-.5,.5,-.5,.5,.5,-.5,-.5,-.5,.5,-.5,-.5,.5,.5,-.5,-.5,-.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,-.5,.5,.5,.5,.5,.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,-.5,.5,-.5,-.5,-.5,.5,.5,.5,.5,.5,-.5,-.5,.5,.5,-.5,.5,.5,.5,-.5,-.5,.5,-.5,.5,-.5,-.5,-.5,-.5,-.5],da=[0,2,1,2,3,1,4,6,5,6,7,5,8,10,9,10,11,9,12,14,13,14,15,13,16,18,17,18,19,17,20,22,21,22,23,21],ea=[1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0, | ||
0,-1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1];S(e,n);var N=new g({width:window.innerWidth,height:window.innerHeight,V:!0});N.m.position=[0,1,2];N.m.N(Math.PI);var O=new e({h:new k});O.position=[5,3,-10];O.color="#FF00FF";N.add(O)})(); | ||
/* global Cervus */ | ||
const material = new Cervus.materials.Phong(); | ||
const game = new Cervus.Game({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
keyboard_controlled_camera: true, | ||
// fps: 1 | ||
}); | ||
// By default all entities face the user. | ||
// Rotate the camera to see the scene. | ||
game.camera.position = [0, 1, 2]; | ||
game.camera.rotate_rl(Math.PI); | ||
const cube2 = new Cervus.shapes.Box({ | ||
material: material | ||
}); | ||
cube2.position = [ 5, 3, -10 ]; | ||
cube2.color = "#FF00FF"; | ||
game.add(cube2); | ||
const cube8 = new Cervus.shapes.Box({ | ||
material: material | ||
}); | ||
cube8.position = [0, 0, -5]; | ||
cube8.color = "#ffffff"; | ||
game.add(cube8); | ||
const cube = new Cervus.shapes.Box({ | ||
material: material | ||
}); | ||
cube.position = [-3, 0, -12]; | ||
cube.color = "#BADA55"; | ||
cube.scale = [2, 1, 2]; | ||
game.add(cube); | ||
const sphere = new Cervus.shapes.Sphere({ | ||
material: material, | ||
color: '#ff0000', | ||
// rotation: [ Math.PI/4, 0, Math.PI/4 ] | ||
}); | ||
sphere.position = [3, 0, -10]; | ||
sphere.scale = [ 0.5, 0.5, 0.5 ]; | ||
game.add(sphere); | ||
let dir = 1; | ||
// | ||
// const plane = new Cervus.shapes.Plane({ | ||
// material: material, | ||
// color: Cervus.math.hex_to_vec('#CCCCCC') | ||
// }); | ||
// | ||
// plane.position[2] = -50; | ||
// plane.position[1] = -2; | ||
// // plane.rotation[0] = -Math.PI/2 + 0.03; | ||
// plane.scale = [ 100, 1, 100 ]; | ||
// game.add(plane); | ||
const plane3 = new Cervus.shapes.Plane({ | ||
material: material, | ||
color: '#CCCCCC' | ||
}); | ||
plane3.position = [0, -1.5, 0]; | ||
plane3.scale = [ 150, 1, 150 ]; | ||
game.add(plane3); | ||
// | ||
// const plane4 = new Cervus.shapes.Plane({ | ||
// material: material, | ||
// color: Cervus.math.hex_to_vec('#00FF00') | ||
// }); | ||
// | ||
// plane4.position[1] = -15; | ||
// plane4.position[2] = 0; | ||
// // plane4.rotation[0] = Math.PI/2; | ||
// plane4.scale = [ 10, 10, 1 ]; | ||
// game.add(plane4); | ||
const plane2 = new Cervus.shapes.Plane({ | ||
material: material, | ||
color: '#cc00cc', | ||
}); | ||
plane2.position = [ 3, -1, -13]; | ||
// plane2.rotation[0] = -Math.PI/2; | ||
plane2.scale = [ 2, 1, 2 ]; | ||
game.add(plane2); | ||
const parent_group = new Cervus.Entity({}); | ||
const group = new Cervus.Entity({}); | ||
const vox1 = new Cervus.shapes.Box({ | ||
scale: [0.5, 0.5, 0.5], | ||
color: '#0000ff', | ||
material: material, | ||
position: [1, 1, -1] | ||
}); | ||
const vox2 = new Cervus.shapes.Box({ | ||
color: '#00ff00', | ||
material: new Cervus.materials.Basic, | ||
position: [3, 2, -3] | ||
}); | ||
group.origin = [ -1, 2, 2 ]; | ||
// group.position[2] = -15; | ||
// group.position[1] = -10; | ||
// game.add(group); | ||
// game.add(vox1); | ||
// game.add(vox2); | ||
group.add(vox1); | ||
group.add(vox2); | ||
parent_group.add(group); | ||
game.add(parent_group); | ||
game.add_frame_listener('cube_rotation', (delta) => { | ||
// cube.rotation[0] = sphere.rotation[0] = group.rotation[2] = delta / 1000; | ||
cube.rotate_ud(16/1000); | ||
if (cube2.position[0] > 5) { | ||
dir = -1; | ||
} else if (cube2.position[0] < -5) { | ||
dir = 1; | ||
} | ||
// if (~~delta%30 === 0) { | ||
// game.light_intensity = Math.random(); | ||
// } | ||
game.light_position = game.camera.position; | ||
sphere.position = [ | ||
sphere.position[0] + 0.06 * dir * -1, | ||
...sphere.position.slice(1) | ||
]; | ||
cube2.position = [ | ||
cube2.position[0] + 0.06 * dir, | ||
...cube2.position.slice(1) | ||
]; | ||
group.position = [ | ||
...group.position.slice(0, 2), | ||
group.position[2] - 0.06 * dir | ||
]; | ||
parent_group.position = [ | ||
parent_group.position[0] - 0.06 * dir, | ||
...parent_group.position.slice(1) | ||
]; | ||
}); |
@@ -17,3 +17,3 @@ /* global Cervus */ | ||
const cube = new Cervus.shapes.Box({ | ||
material: 'phong', | ||
material: new Cervus.materials.Phong | ||
}); | ||
@@ -20,0 +20,0 @@ |
/* global Cervus */ | ||
const material = 'basic'; | ||
const meshes = []; | ||
const colors = ['#00ff00', '#A52A2A', '#006400']; | ||
const get_scaling = (out, mat) => { | ||
let m11 = mat[0]; | ||
let m12 = mat[1]; | ||
let m13 = mat[2]; | ||
let m21 = mat[4]; | ||
let m22 = mat[5]; | ||
let m23 = mat[6]; | ||
let m31 = mat[8]; | ||
let m32 = mat[9]; | ||
let m33 = mat[10]; | ||
out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13); | ||
out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23); | ||
out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33); | ||
return out; | ||
}; | ||
const get_rotation = (out, mat) => { | ||
// Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm | ||
let trace = mat[0] + mat[5] + mat[10]; | ||
let S = 0; | ||
if (trace > 0) { | ||
S = Math.sqrt(trace + 1.0) * 2; | ||
out[3] = 0.25 * S; | ||
out[0] = (mat[6] - mat[9]) / S; | ||
out[1] = (mat[8] - mat[2]) / S; | ||
out[2] = (mat[1] - mat[4]) / S; | ||
} else if ((mat[0] > mat[5])&(mat[0] > mat[10])) { | ||
S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2; | ||
out[3] = (mat[6] - mat[9]) / S; | ||
out[0] = 0.25 * S; | ||
out[1] = (mat[1] + mat[4]) / S; | ||
out[2] = (mat[8] + mat[2]) / S; | ||
} else if (mat[5] > mat[10]) { | ||
S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2; | ||
out[3] = (mat[8] - mat[2]) / S; | ||
out[0] = (mat[1] + mat[4]) / S; | ||
out[1] = 0.25 * S; | ||
out[2] = (mat[6] + mat[9]) / S; | ||
} else { | ||
S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2; | ||
out[3] = (mat[1] - mat[4]) / S; | ||
out[0] = (mat[8] + mat[2]) / S; | ||
out[1] = (mat[6] + mat[9]) / S; | ||
out[2] = 0.25 * S; | ||
} | ||
return out; | ||
}; | ||
const game = new Cervus.Game({ | ||
@@ -12,3 +57,2 @@ width: window.innerWidth, | ||
light_intensity: 0.4 | ||
// dom: document.body, | ||
// fps: 1 | ||
@@ -18,11 +62,2 @@ }); | ||
// const light = new Cervus.shapes.Sphere({ | ||
// material: 'phong', | ||
// color: '#32cd32' | ||
// }); | ||
// | ||
// light.position.z = -50; | ||
// // light.scale = {x: 0.1, y: 0.1, z: 0.1}; | ||
// game.add(light); | ||
fetch('models/scene.json') | ||
@@ -34,23 +69,2 @@ .then((data) => { | ||
console.log(json); | ||
// json.meshes.forEach((mesh, i) => { | ||
// let col = ~~(Math.random() * 100); | ||
// if (col < 10) { | ||
// col = '0' + col; | ||
// } | ||
// // meshes.push(new Cervus.Entity({ | ||
// // vertices: mesh.vertices, | ||
// // indices: mesh.faces, | ||
// // normals: mesh.normals | ||
// // })); | ||
// let mesh_in = new Cervus.Entity({ | ||
// vertices: mesh.vertices, | ||
// indices: [].concat.apply([], mesh.faces), | ||
// normals: mesh.normals, | ||
// material: 'phong', | ||
// color: '#' + col + col + col//colors[i] | ||
// }); | ||
// // mesh_in.scale = {x: 0.1, y: 0.1, z: 0.1}; | ||
// game.add(mesh_in); | ||
// meshes.push(mesh_in); | ||
// }); | ||
@@ -72,32 +86,19 @@ json.rootnode.children.forEach((child) => { | ||
normals: json.meshes[mesh_i].normals, | ||
material: 'phong', //'basic', | ||
color: '#000000', //'#' + col + col + col//'#FFFFFF' //+ col + 'ff' + col//colors[i] | ||
material: new Cervus.materials.Phong, | ||
color: '#000000', | ||
}); | ||
let transform = Cervus.math.mat4.getTranslation([], child.transformation); | ||
let scale = Cervus.math.mat4.getScaling([], child.transformation); | ||
let rotation = Cervus.math.mat4.getRotation([], child.transformation); | ||
// mesh_in.local_matrix = child.transformation; | ||
let scale = get_scaling([], child.transformation); | ||
let rotation = get_rotation([], child.transformation); | ||
mesh_in.position = { | ||
x: child.transformation[3], | ||
y: child.transformation[7], | ||
z: child.transformation[11] | ||
}; | ||
// mesh_in.position = { | ||
// x: transform[0], | ||
// y: transform[1], | ||
// z: transform[2] | ||
// }; | ||
mesh_in.position = [ | ||
child.transformation[3], | ||
child.transformation[7], | ||
child.transformation[11] | ||
]; | ||
mesh_in.scale = { | ||
x: scale[0], | ||
y: scale[1], | ||
z: scale[2] | ||
}; | ||
mesh_in.scale = scale; | ||
mesh_in.rotation = { | ||
x: rotation[0], | ||
y: rotation[1], | ||
z: rotation[2] | ||
}; | ||
mesh_in.rotate_ud(-Math.PI/2); | ||
@@ -107,14 +108,6 @@ game.add(mesh_in); | ||
}); | ||
// meshes.forEach((Mesh) => { | ||
// var mesh_instance = new Mesh({ | ||
// material: 'phong', | ||
// color: '#00ffff' | ||
// }); | ||
// | ||
// game.add(mesh_instance); | ||
// }); | ||
}); | ||
game.add_frame_listener('elo', () => { | ||
game.light_position = { x: game.camera.position[0], y: game.camera.position[1], z: game.camera.position[2] }; | ||
// game.light_position = game.camera.position; | ||
@@ -121,0 +114,0 @@ // meshes.forEach((mesh, i) => { |
@@ -1,3 +0,3 @@ | ||
import { Basic } from './src/materials/basic.js'; | ||
import { Phong } from './src/materials/phong.js'; | ||
export { Basic, Phong }; | ||
export { Basic } from './src/materials/basic.js'; | ||
export { Phong } from './src/materials/phong.js'; | ||
// export { Basic, Phong }; |
@@ -1,3 +0,3 @@ | ||
import * as defaults from './src/misc/defaults.js'; | ||
import * as utils from './src/misc/utils.js'; | ||
export { defaults, utils }; | ||
export * as defaults from './src/misc/defaults.js'; | ||
export * as utils from './src/misc/utils.js'; | ||
// export { defaults, utils }; |
{ | ||
"name": "cervus", | ||
"version": "0.0.9", | ||
"version": "0.0.11", | ||
"author": "Michał Budzyński <michal@virtualdesign.pl>", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:michalbe/cervus.git", |
@@ -1,4 +0,4 @@ | ||
import { Box } from './src/shapes/box.js'; | ||
import { Plane } from './src/shapes/plane.js'; | ||
import { Sphere } from './src/shapes/sphere.js'; | ||
export { Box, Plane, Sphere }; | ||
export { Box } from './src/shapes/box.js'; | ||
export { Plane } from './src/shapes/plane.js'; | ||
export { Sphere } from './src/shapes/sphere.js'; | ||
// export { Box, Plane, Sphere }; |
@@ -6,7 +6,6 @@ import { Basic } from './basic.js' | ||
const materials = { | ||
basic: Basic, | ||
phong: Phong, | ||
// shadow_phong: ShadowPhong | ||
Basic, | ||
Phong | ||
}; | ||
export { materials }; |
Sorry, the diff of this file is not supported yet
9719
128864