Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

fix SyntaxError: Unexpected token static when building #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/threebox.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

313 changes: 147 additions & 166 deletions src/objects/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,187 +3,168 @@ var material = require("../utils/material.js");

const AnimationManager = require("../animation/AnimationManager.js");


function Objects(){

}
function Objects() {}

Objects.prototype = {
// standard 1px line with gl
line: function(obj) {
obj = utils._validate(obj, this._defaults.line);

// standard 1px line with gl
line: function(obj){

obj = utils._validate(obj, this._defaults.line);

//project to world and normalize
var straightProject = utils.lnglatsToWorld(obj.geometry);
var normalized = utils.normalizeVertices(straightProject);

//flatten array for buffergeometry
var flattenedArray = utils.flattenVectors(normalized.vertices);

var positions = new Float32Array(flattenedArray); // 3 vertices per point
var geometry = new THREE.BufferGeometry();
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );

// material
var material = new THREE.LineBasicMaterial( { color: 0xff0000, linewidth: 21 } );
var line = new THREE.Line( geometry, material );

line.options = options || {};
line.position.copy(normalized.position)

return line
},

//project to world and normalize
var straightProject = utils.lnglatsToWorld(obj.geometry);
var normalized = utils.normalizeVertices(straightProject);

extrusion: function(options){
//flatten array for buffergeometry
var flattenedArray = utils.flattenVectors(normalized.vertices);

},
var positions = new Float32Array(flattenedArray); // 3 vertices per point
var geometry = new THREE.BufferGeometry();
geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));

_addMethods: function(obj, static){
// material
var material = new THREE.LineBasicMaterial({
color: 0xff0000,
linewidth: 21
});
var line = new THREE.Line(geometry, material);

var root = this;
line.options = options || {};
line.position.copy(normalized.position);

if (static) {
return line;
},

}
extrusion: function(options) {},

else {
_addMethods: function(obj, staticVal) {
var root = this;

if (!obj.coordinates) obj.coordinates = [0,0,0];
if (staticVal) {
} else {
if (!obj.coordinates) obj.coordinates = [0, 0, 0];

// Bestow this mesh with animation superpowers and keeps track of its movements in the global animation queue
root.animationManager.enroll(obj);
obj.setCoords = function(lnglat){

/** Place the given object on the map, centered around the provided longitude and latitude
// Bestow this mesh with animation superpowers and keeps track of its movements in the global animation queue
root.animationManager.enroll(obj);
obj.setCoords = function(lnglat) {
/** Place the given object on the map, centered around the provided longitude and latitude
The object's internal coordinates are assumed to be in meter-offset format, meaning
1 unit represents 1 meter distance away from the provided coordinate.
*/

// If object already added, scale the model so that its units are interpreted as meters at the given latitude
if (obj.userData.units === 'meters'){
var s = utils.projectedUnitsPerMeter(lnglat[1]);
obj.scale.set(s,s,s);
}

obj.coordinates = lnglat;
obj.set({position:lnglat})


return obj;

}

obj.setRotation = function(xyz) {

if (typeof xyz === 'number') xyz = {z: xyz}

var r = {
x: utils.radify(xyz.x) || obj.rotation.x,
y: utils.radify(xyz.y) || obj.rotation.y,
z: utils.radify(xyz.z) || obj.rotation.z
}

obj._setObject({rotation: [r.x, r.y, r.z]})
}

}

obj.add = function(){
root.world.add(obj);
if (!static) obj.set({position:obj.coordinates});
return obj;
}


obj.remove = function(){
root.world.remove(obj);
root.map.repaint = true;
}

obj.duplicate = function(a) {
var dupe = obj.clone();
dupe.userData = obj.userData;
root._addMethods(dupe);
return dupe
}

return obj
},

_makeGroup: function(obj, options){
var geoGroup = new THREE.Group();
geoGroup.userData = options || {};
geoGroup.userData.isGeoGroup = true;

var isArrayOfObjects = obj.length;

if (isArrayOfObjects) for (o of obj) geoGroup.add(o)


else geoGroup.add(obj);

utils._flipMaterialSides(obj);

return geoGroup
},

animationManager: new AnimationManager,

_defaults: {

line: {
geometry: null,
color: 'black',
width:1,
opacity:1
},

sphere: {
position: [0,0,0],
radius: 1,
sides: 20,
units: 'scene',
material: 'MeshBasicMaterial'
},

tube: {
geometry: null,
radius: 1,
sides:6,
material: 'MeshBasicMaterial'
},

extrusion:{
footprint: null,
base: 0,
top: 100,
color:'black',
material: 'MeshBasicMaterial',
scaleToLatitude: false
},

loadObj:{
obj: null,
mtl: null,
rotation: 0,
scale: 1,
units: 'scene'
},

Object3D: {
obj: null,
units: 'scene'
// If object already added, scale the model so that its units are interpreted as meters at the given latitude
if (obj.userData.units === "meters") {
var s = utils.projectedUnitsPerMeter(lnglat[1]);
obj.scale.set(s, s, s);
}
},

geometries:{
line: ['LineString'],
tube: ['LineString'],
sphere: ['Point'],
}
}

module.exports = exports = Objects;
obj.coordinates = lnglat;
obj.set({ position: lnglat });

return obj;
};

obj.setRotation = function(xyz) {
if (typeof xyz === "number") xyz = { z: xyz };

var r = {
x: utils.radify(xyz.x) || obj.rotation.x,
y: utils.radify(xyz.y) || obj.rotation.y,
z: utils.radify(xyz.z) || obj.rotation.z
};

obj._setObject({ rotation: [r.x, r.y, r.z] });
};
}

obj.add = function() {
root.world.add(obj);
if (!staticVal) obj.set({ position: obj.coordinates });
return obj;
};

obj.remove = function() {
root.world.remove(obj);
root.map.repaint = true;
};

obj.duplicate = function(a) {
var dupe = obj.clone();
dupe.userData = obj.userData;
root._addMethods(dupe);
return dupe;
};

return obj;
},

_makeGroup: function(obj, options) {
var geoGroup = new THREE.Group();
geoGroup.userData = options || {};
geoGroup.userData.isGeoGroup = true;

var isArrayOfObjects = obj.length;

if (isArrayOfObjects) for (o of obj) geoGroup.add(o);
else geoGroup.add(obj);

utils._flipMaterialSides(obj);

return geoGroup;
},

animationManager: new AnimationManager(),

_defaults: {
line: {
geometry: null,
color: "black",
width: 1,
opacity: 1
},

sphere: {
position: [0, 0, 0],
radius: 1,
sides: 20,
units: "scene",
material: "MeshBasicMaterial"
},

tube: {
geometry: null,
radius: 1,
sides: 6,
material: "MeshBasicMaterial"
},

extrusion: {
footprint: null,
base: 0,
top: 100,
color: "black",
material: "MeshBasicMaterial",
scaleToLatitude: false
},

loadObj: {
obj: null,
mtl: null,
rotation: 0,
scale: 1,
units: "scene"
},

Object3D: {
obj: null,
units: "scene"
}
},

geometries: {
line: ["LineString"],
tube: ["LineString"],
sphere: ["Point"]
}
};

module.exports = exports = Objects;