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

gsv-injection

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gsv-injection - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

dist/mathUtils.d.ts

14

dist/index.d.ts
/// <reference path="../typings/main.d.ts" />
export import drawUtils = require("gm-draw-utils");
export declare class Mesh {

@@ -11,2 +12,8 @@ textureURI: string;

uvMapBuffer: any;
rotation: number;
translation: {
x: number;
y: number;
z: number;
};
private initialized;

@@ -16,2 +23,3 @@ init(gl: any, oldWebGl: any): void;

private initBuffers(gl, oldWebGl, bindAttributes?);
private applyTransformation(initialMatrix);
draw(gl: any, oldWebGl: any, uniforms: Uniforms): void;

@@ -28,4 +36,10 @@ }

};
uniformMatrix4fv: {
location: any;
transpose: boolean;
value: number[];
};
}
export declare function init(canvasContainer: any): void;
export declare function addMesh(mesh: Mesh): void;
export declare function removeMesh(mesh: Mesh): void;

52

dist/index.js
"use strict";
/// <reference path="../typings/main.d.ts" />
var utils = require("./utils");
var mathUtils = require("./mathUtils");
exports.drawUtils = require("gm-draw-utils");
var Mesh = (function () {
function Mesh() {
this.rotation = 0;
this.translation = {
x: 0,
y: 0,
z: 0
};
this.initialized = false;

@@ -48,2 +56,9 @@ }

};
Mesh.prototype.applyTransformation = function (initialMatrix) {
var rotationMatrix = mathUtils.zRotation(this.rotation);
var translationMatrix = mathUtils.translation(this.translation.x, this.translation.y, this.translation.z);
var resultMatrix = mathUtils.multiply(translationMatrix, rotationMatrix);
resultMatrix = mathUtils.multiply(initialMatrix, resultMatrix);
return new Float32Array(resultMatrix);
};
Mesh.prototype.draw = function (gl, oldWebGl, uniforms) {

@@ -56,4 +71,7 @@ oldWebGl.disableVertexAttribArray(0);

oldWebGl.bindTexture(gl.TEXTURE_2D, this.texture);
oldWebGl.uniform4fv(uniforms.uniform4fv.location, uniforms.uniform4fv.value);
oldWebGl.uniform4fv(uniforms.uniform4fv.location, [1, 1, 0, 0]);
oldWebGl.uniform1f(uniforms.uniform1f.location, 1);
if (uniforms.uniformMatrix4fv) {
oldWebGl.uniformMatrix4fv(uniforms.uniformMatrix4fv.location, uniforms.uniformMatrix4fv.transpose, this.applyTransformation(uniforms.uniformMatrix4fv.value));
}
oldWebGl.drawElements(gl.TRIANGLES, this.indices.length, gl.UNSIGNED_SHORT, 0);

@@ -80,5 +98,32 @@ };

}
function init() {
utils.setup(null, drawScene);
function init(canvasContainer) {
utils.setup(drawScene, function (gl) {
if (gl.canvasContainer === false) {
return false;
}
if (gl.canvasContainer === canvasContainer) {
return true;
}
if (isContainerOf(canvasContainer, gl.canvas)) {
gl.canvasContainer = canvasContainer;
return true;
}
if (gl.canvas && !gl.canvas.parentElement) {
return false;
}
gl.canvasContainer = false;
return false;
});
}
exports.init = init;
function isContainerOf(container, element) {
var current = element;
while (current) {
if (container === current) {
return true;
}
current = current.parentElement;
}
return false;
}
function addMesh(mesh) {

@@ -99,3 +144,2 @@ activeMeshes.push(mesh);

exports.removeMesh = removeMesh;
init();
//# sourceMappingURL=index.js.map

2

dist/utils.d.ts
/// <reference path="../typings/main.d.ts" />
export declare function setup(canvas: any, callback: (webGl, oldWebGl, uniforms) => void): void;
export declare function setup(callback: (webGl, oldWebGl, uniforms) => void, isGlEnabled: (gl) => boolean): void;
"use strict";
/// <reference path="../typings/main.d.ts" />
var webGl;
var oldWebGl = {};

@@ -34,2 +33,7 @@ var lastCalls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

}
function getOldWebgl(glInstance) {
var result = new Object(oldWebGl);
result.glInstance = glInstance;
return result;
}
function isDesiredCase() {

@@ -51,8 +55,10 @@ for (var i = 0; i < desiredCases.length; i++) {

}
function webGlInject(methodName, injectionBody) {
function webGlInject(methodName, injectionBody, isGlEnabled) {
var oldMethod = WebGLRenderingContext.prototype[methodName];
register(methodName);
WebGLRenderingContext.prototype[methodName] = function () {
webGl = this;
var newArgumens = [oldMethod, webGl, []];
if (!isGlEnabled(this)) {
return oldMethod.apply(this, arguments);
}
var newArgumens = [oldMethod, this, []];
for (var i = 0; i < arguments.length; i++) {

@@ -78,3 +84,3 @@ newArgumens[2].push(arguments[i]);

}
return field.apply(webGl, filteredArgs);
return field.apply(this.glInstance, filteredArgs);
};

@@ -102,6 +108,40 @@ }

var preLastUniform1f;
function setup(canvas, callback) {
var lastProgram;
var lastMatrices = [];
function findLastMatrix4fv() {
for (var i = 0; i < lastMatrices.length; i++) {
if (lastMatrices[i].program === lastProgram) {
return lastMatrices[i].matrix;
}
}
return null;
}
function setup(callback, isGlEnabled) {
var methods = glMethodsList();
methods.forEach(function (methodName) {
webGlInject(methodName + "", function (oldMethod, gl, args) {
if (!gl.oldWebGl) {
gl.oldWebGl = getOldWebgl(gl);
}
if (methodName === "useProgram") {
lastProgram = args[0];
}
if (methodName === 'uniformMatrix4fv') {
var lastUniformMatrix4fv = [args[0], args[1], args[2]];
var container;
for (var i = 0; i < lastMatrices.length; i++) {
var currentContainer = lastMatrices[i];
if (currentContainer.program === lastProgram) {
container = currentContainer;
break;
}
}
if (!container) {
container = {
program: lastProgram
};
lastMatrices.push(container);
}
container.matrix = lastUniformMatrix4fv;
}
if (methodName === 'bindTexture') {

@@ -118,3 +158,4 @@ lastTexture = args[1];

if (methodName === 'disableVertexAttribArray' && isDesiredCase()) {
callback(gl, oldWebGl, {
var uniformMatrix4fv = findLastMatrix4fv();
callback(gl, gl.oldWebGl, {
uniform4fv: {

@@ -127,6 +168,14 @@ location: lastUniform4fv[0],

value: preLastUniform1f[1]
}
},
uniformMatrix4fv: uniformMatrix4fv ? {
location: uniformMatrix4fv[0],
transpose: uniformMatrix4fv[1],
value: uniformMatrix4fv[2]
} : null
});
oldWebGl.uniform1f(lastUniform1f[0], lastUniform1f[1]);
oldWebGl.bindTexture(gl.TEXTURE_2D, lastTexture);
gl.oldWebGl.uniform1f(lastUniform1f[0], lastUniform1f[1]);
if (uniformMatrix4fv) {
gl.oldWebGl.uniformMatrix4fv(uniformMatrix4fv[0], uniformMatrix4fv[1], uniformMatrix4fv[2]);
}
gl.oldWebGl.bindTexture(gl.TEXTURE_2D, lastTexture);
}

@@ -136,3 +185,3 @@ var result = oldMethod.apply(gl, args);

return result;
});
}, isGlEnabled);
});

@@ -139,0 +188,0 @@ }

{
"name": "gsv-injection",
"version": "0.0.1",
"version": "0.0.2",
"main": "dist/index.js",
"scripts": {
"compile": "rimraf dist && tsc",
"generate": "node build.js",
"build": "npm install && npm run compile && npm run generate"
"build": "npm install && typings install && npm run compile"
},
"dependencies": {
"typescript-compiler": "1.4.1-2",
"underscore": "^1.8.3"
"underscore": "^1.8.3",
"gm-draw-utils": "*"
},

@@ -14,0 +14,0 @@ "typings": "./dist/index.d.ts",

# gsv-injection
A simple API that allows to inject and render your 3d models into Google Street Views's webgl canvas. It uses same shaders that used in GSV. So your model have the same perspective distortions as objects in panorama and it looks very natural.
##Demo
https://dreamflyer.github.io/gsv-injection/site/index.html
(curently tested only in Chrome under Mac OS X)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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