Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@luk707/engine

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@luk707/engine - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

.publish/camera.d.ts

2

.publish/camera.js

@@ -11,3 +11,3 @@ "use strict";

if (fov === void 0) { fov = 60; }
if (aspect === void 0) { aspect = 1; }
if (aspect === void 0) { aspect = 300 / 150; }
if (near === void 0) { near = 0.1; }

@@ -14,0 +14,0 @@ if (far === void 0) { far = 1000; }

@@ -93,2 +93,70 @@ "use strict";

};
Matrix.Multiply = function (a, b) {
return new Matrix([
a.data[0] * b.data[0] +
a.data[1] * b.data[4] +
a.data[2] * b.data[8] +
a.data[3] * b.data[12],
a.data[0] * b.data[1] +
a.data[1] * b.data[5] +
a.data[2] * b.data[9] +
a.data[3] * b.data[13],
a.data[0] * b.data[2] +
a.data[1] * b.data[6] +
a.data[2] * b.data[10] +
a.data[3] * b.data[14],
a.data[0] * b.data[3] +
a.data[1] * b.data[7] +
a.data[2] * b.data[11] +
a.data[3] * b.data[15],
a.data[4] * b.data[0] +
a.data[5] * b.data[4] +
a.data[6] * b.data[8] +
a.data[7] * b.data[12],
a.data[4] * b.data[1] +
a.data[5] * b.data[5] +
a.data[6] * b.data[9] +
a.data[7] * b.data[13],
a.data[4] * b.data[2] +
a.data[5] * b.data[6] +
a.data[6] * b.data[10] +
a.data[7] * b.data[14],
a.data[4] * b.data[3] +
a.data[5] * b.data[7] +
a.data[6] * b.data[11] +
a.data[7] * b.data[15],
a.data[8] * b.data[0] +
a.data[9] * b.data[4] +
a.data[10] * b.data[8] +
a.data[11] * b.data[12],
a.data[8] * b.data[1] +
a.data[9] * b.data[5] +
a.data[10] * b.data[9] +
a.data[11] * b.data[13],
a.data[8] * b.data[2] +
a.data[9] * b.data[6] +
a.data[10] * b.data[10] +
a.data[11] * b.data[14],
a.data[8] * b.data[3] +
a.data[9] * b.data[7] +
a.data[10] * b.data[11] +
a.data[11] * b.data[15],
a.data[12] * b.data[0] +
a.data[13] * b.data[4] +
a.data[14] * b.data[8] +
a.data[15] * b.data[12],
a.data[12] * b.data[1] +
a.data[13] * b.data[5] +
a.data[14] * b.data[9] +
a.data[15] * b.data[13],
a.data[12] * b.data[2] +
a.data[13] * b.data[6] +
a.data[14] * b.data[10] +
a.data[15] * b.data[14],
a.data[12] * b.data[3] +
a.data[13] * b.data[7] +
a.data[14] * b.data[11] +
a.data[15] * b.data[15]
]);
};
Matrix.prototype.Inverse = function () {

@@ -254,70 +322,2 @@ var m11 = this.data[0];

};
Matrix.Multiply = function (a, b) {
return new Matrix([
a.data[0] * b.data[0] +
a.data[1] * b.data[4] +
a.data[2] * b.data[8] +
a.data[3] * b.data[12],
a.data[0] * b.data[1] +
a.data[1] * b.data[5] +
a.data[2] * b.data[9] +
a.data[3] * b.data[13],
a.data[0] * b.data[2] +
a.data[1] * b.data[6] +
a.data[2] * b.data[10] +
a.data[3] * b.data[14],
a.data[0] * b.data[3] +
a.data[1] * b.data[7] +
a.data[2] * b.data[11] +
a.data[3] * b.data[15],
a.data[4] * b.data[0] +
a.data[5] * b.data[4] +
a.data[6] * b.data[8] +
a.data[7] * b.data[12],
a.data[4] * b.data[1] +
a.data[5] * b.data[5] +
a.data[6] * b.data[9] +
a.data[7] * b.data[13],
a.data[4] * b.data[2] +
a.data[5] * b.data[6] +
a.data[6] * b.data[10] +
a.data[7] * b.data[14],
a.data[4] * b.data[3] +
a.data[5] * b.data[7] +
a.data[6] * b.data[11] +
a.data[7] * b.data[15],
a.data[8] * b.data[0] +
a.data[9] * b.data[4] +
a.data[10] * b.data[8] +
a.data[11] * b.data[12],
a.data[8] * b.data[1] +
a.data[9] * b.data[5] +
a.data[10] * b.data[9] +
a.data[11] * b.data[13],
a.data[8] * b.data[2] +
a.data[9] * b.data[6] +
a.data[10] * b.data[10] +
a.data[11] * b.data[14],
a.data[8] * b.data[3] +
a.data[9] * b.data[7] +
a.data[10] * b.data[11] +
a.data[11] * b.data[15],
a.data[12] * b.data[0] +
a.data[13] * b.data[4] +
a.data[14] * b.data[8] +
a.data[15] * b.data[12],
a.data[12] * b.data[1] +
a.data[13] * b.data[5] +
a.data[14] * b.data[9] +
a.data[15] * b.data[13],
a.data[12] * b.data[2] +
a.data[13] * b.data[6] +
a.data[14] * b.data[10] +
a.data[15] * b.data[14],
a.data[12] * b.data[3] +
a.data[13] * b.data[7] +
a.data[14] * b.data[11] +
a.data[15] * b.data[15]
]);
};
Matrix.Identity = new Matrix([

@@ -324,0 +324,0 @@ 1,

{
"name": "@luk707/engine",
"version": "0.0.0",
"version": "0.0.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var vector_1 = require("./vector");
var Scene = /** @class */ (function () {
function Scene(canvas) {
/**
* Creates a new instance of scene
* @param canvas
* @param update
* @param options
*/
function Scene(canvas, init, update) {
this.canvas = canvas;
this.gl = null;
this.gl =
canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
if (this.gl) {
this.gl.clearColor(0.0, 0.0, 0.0, 0.0);
this.gl.enable(this.gl.DEPTH_TEST);
this.gl.depthFunc(this.gl.LEQUAL);
this.gl.enable(this.gl.CULL_FACE);
this.gl.cullFace(this.gl.FRONT);
this.init = init;
this.update = update;
// Keeps track of the current scenes running state
this.running = false;
// False when GL is not ready to run
this.isReady = false;
this.Update = this.Update.bind(this);
var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
if (!gl) {
alert('Unable to initialise WebGL Context');
return;
}
else {
alert("Unable to initialise WebGL Context");
gl.clearColor(0.0, 0.0, 0.0, 0.0);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.FRONT);
this.isReady = true;
this.gl = gl;
this.init(gl, this);
}
/**
* Starts the current scene, returns true if successful
*/
Scene.prototype.Start = function () {
if (!this.isReady) {
return false;
}
}
if (this.running) {
return false;
}
// Start the scene loop
this.running = true;
window.requestAnimationFrame(this.Update);
return true;
};
/**
* Stops the current scene returns false if unsuccessful
*/
Scene.prototype.Stop = function () {
if (!this.running) {
return false;
}
// Stop the scene loop
return true;
};
Scene.prototype.Clear = function () {
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
};
Scene.prototype.CreateProgram = function (vertexShader, fragmentShader) {

@@ -31,9 +71,7 @@ var program = this.gl.createProgram();

};
/**
* Creates a WebGL shader
* @param {string} source The GLSL source for the shader
* @param {number} type The type of shader
*/
Scene.prototype.CreateShader = function (source, type) {
var shader = this.gl.createShader(type);
if (!shader) {
throw new Error('Could not create shader');
}
this.gl.shaderSource(shader, source);

@@ -44,94 +82,21 @@ this.gl.compileShader(shader);

}
console.log("Error compiling shader of type: " +
(type == 35632 ? "fragmentShader" : "vertexShader"));
console.log('Error compiling shader of type: ' +
(type === 35632 ? 'fragmentShader' : 'vertexShader'));
throw this.gl.getShaderInfoLog(shader);
};
Scene.prototype.CreateLightingProgram = function () {
var vertexShaderSource = [
"attribute vec3 position;",
"attribute vec3 normal;",
"uniform mat4 model;",
"uniform mat4 view;",
"uniform mat4 projection;",
"uniform vec3 light1d;",
"uniform vec3 light2d;",
"varying highp float vLight1;",
"varying highp float vLight2;",
"void main() {",
" vLight1 =",
" max(dot(normal, normalize(light1d) ), 0.0);",
" vLight2 =",
" max(dot(normal, normalize(light2d) ), 0.0);",
" gl_Position = (projection * view * model) * vec4(position, 1);",
"}"
].join("\n");
var vertexShader = this.CreateShader(vertexShaderSource, this.gl.VERTEX_SHADER);
var fragmentShaderSource = [
"precision highp float;",
"uniform vec4 color;",
"uniform vec4 ambient;",
"varying highp float vLight1;",
"varying highp float vLight2;",
"uniform vec4 light1c;",
"uniform vec4 light2c;",
"void main() {",
" gl_FragColor = (ambient + color) * (",
" vec4(light1c.rgb * vLight1, 1.0) +",
" vec4(light2c.rgb * vLight2, 1.0));",
"}"
].join("\n");
var fragmentShader = this.CreateShader(fragmentShaderSource, this.gl.FRAGMENT_SHADER);
var lightingProgram = this.CreateProgram(vertexShader, fragmentShader);
this.gl.useProgram(lightingProgram);
this.gl.uniform3fv(this.gl.getUniformLocation(lightingProgram, "light1d"), new vector_1.Vector(3, 2, 1).ToArray());
this.gl.uniform3fv(this.gl.getUniformLocation(lightingProgram, "light2d"), new vector_1.Vector(-1, -3, -2).ToArray());
this.gl.uniform4fv(this.gl.getUniformLocation(lightingProgram, "ambient"), [
0.1,
0.1,
0.1,
1.0
]);
this.gl.uniform4fv(this.gl.getUniformLocation(lightingProgram, "light1c"), [
0.85,
0.85,
0.85,
1.0
]);
this.gl.uniform4fv(this.gl.getUniformLocation(lightingProgram, "light2c"), [
0.25,
0.25,
0.25,
1.0
]);
return lightingProgram;
Scene.prototype.Update = function () {
if (!this.running) {
return;
}
var currentTime = new Date();
var deltaTime = 0;
if (this.lastUpdateTime) {
deltaTime = currentTime.getTime() - this.lastUpdateTime.getTime();
}
this.update(this.gl, deltaTime);
this.lastUpdateTime = currentTime;
window.requestAnimationFrame(this.Update);
};
Scene.prototype.CreateBasicProgram = function () {
var vertexShaderSource = [
"attribute vec3 position;",
"uniform mat4 model;",
"uniform mat4 view;",
"uniform mat4 projection;",
"void main() {",
" gl_Position = (projection * view * model) * vec4(position, 1);",
"}"
].join("\n");
var vertexShader = this.CreateShader(vertexShaderSource, this.gl.VERTEX_SHADER);
var fragmentShaderSource = [
"precision highp float;",
"uniform vec4 color;",
"void main() {",
" gl_FragColor = color;",
"}"
].join("\n");
var fragmentShader = this.CreateShader(fragmentShaderSource, this.gl.FRAGMENT_SHADER);
return this.CreateProgram(vertexShader, fragmentShader);
};
Scene.prototype.DrawObject = function (object, program, view, projection) {
this.gl.useProgram(program);
this.gl.uniformMatrix4fv(this.gl.getUniformLocation(program, "view"), false, view.ToFloat32Array());
this.gl.uniformMatrix4fv(this.gl.getUniformLocation(program, "projection"), false, projection.ToFloat32Array());
object.Draw(this.gl, program);
};
return Scene;
}());
exports.Scene = Scene;

@@ -12,2 +12,5 @@ "use strict";

}
Vector.Subtract = function (a, b) {
return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
};
Vector.Dot = function (a, b) {

@@ -31,5 +34,2 @@ return a.x * b.x + a.y * b.y + a.z * b.z;

};
Vector.Subtract = function (a, b) {
return new Vector(a.x - b.x, a.y - b.y, a.z - b.z);
};
Vector.Zero = new Vector();

@@ -36,0 +36,0 @@ Vector.Unit = new Vector(1, 1, 1);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc