Skip to content

Commit

Permalink
Merge pull request #178 from VCityTeam/dev
Browse files Browse the repository at this point in the history
eslint added
  • Loading branch information
EricBoix authored Jun 8, 2021
2 parents 77d6b5c + 09db777 commit 835dc54
Show file tree
Hide file tree
Showing 123 changed files with 4,046 additions and 3,349 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @format */

module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
rules: {
indent: [2, 2, { SwitchCase: 1 }],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'no-unused-vars': 'off',
},
};
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ install:

jobs:
include:
- stage: test
- stage: travis
script:
- npm run test
# - stage: lint
# script:
# - ./node_modules/eslint/bin/eslint.js --version
# - npm run lint
- npm run travis
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "ud-viz",
"version": "2.31.9",
"version": "2.32.0",
"description": "A collection of itowns plugins",
"main": "src",
"scripts": {
"test": "npm run build",
"travis": "npm run eslint && npm run build",
"eslint": "./node_modules/.bin/eslint ./src",
"build": "cross-env NODE_ENV=production webpack",
"build-debug": "cross-env NODE_ENV=development webpack",
"debug": "nodemon --verbose --watch src --delay 2500ms ./bin/debug.js -e js,css,html"
Expand Down Expand Up @@ -36,6 +37,7 @@
"child-process-promise": "^2.2.1",
"cross-env": "^7.0.3",
"css-loader": "^0.28.10",
"eslint": "^7.28.0",
"nodemon": "^2.0.7",
"style-loader": "^0.20.3",
"url-loader": "^1.0.1",
Expand Down
17 changes: 11 additions & 6 deletions src/Components/3DTiles/3DTilesBuildingUtils.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { setTileVerticesColor, getBatchIdFromIntersection,
getBatchTableFromTile,
getTileInLayer} from "./3DTilesUtils";
/** @format */

import {
setTileVerticesColor,
getBatchIdFromIntersection,
getBatchTableFromTile,
getTileInLayer,
} from './3DTilesUtils';

/**
* Gets a building ID from an intersection. The intersecting object must
* be a "Mesh" object with a batch id.
*
*
* @param {*} inter An intersection
*/
export function getBuildingIdFromIntersection(inter) {
Expand All @@ -28,7 +33,7 @@ export function getBuildingInfoFromBuildingId(tilesInfo, buildingId) {

/**
* Sets the color of one building in the scene.
*
*
* @param {*} layer The 3DTiles layer.
* @param {*} buildingInfo The building info.
* @param {Array<number>} color The color.
Expand All @@ -39,4 +44,4 @@ export function colorBuilding(layer, buildingInfo, color) {
throw 'Building not in the view - tile is not loaded';
}
setTileVerticesColor(tile, color, buildingInfo.arrayIndexes);
}
}
20 changes: 10 additions & 10 deletions src/Components/3DTiles/3DTilesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { objectEquals } from '../DataProcessing/DataProcessing.js';
* @param {*} tile A 3DTiles tile object from THREE.js.
*/
export function getBatchTableFromTile(tile) {
if (!!tile.batchTable) {
if (tile.batchTable) {
return tile.batchTable;
} else if (!!tile.parent) {
} else if (tile.parent) {
return getBatchTableFromTile(tile.parent);
}
return undefined;
Expand Down Expand Up @@ -66,11 +66,11 @@ export function getVisibleTiles(layer) {
let rootTile = layer.object3d.children[0];
let tiles = [];
let exploreTree = (node) => {
if (!!node) {
if (!!node.batchTable) {
if (node) {
if (node.batchTable) {
// It's an actual tile
tiles.push(node);
};
}
for (let childIndex = 0; childIndex < node.children.length; childIndex++) {
let child = node.children[childIndex];
if (child.type === 'Object3D') {
Expand Down Expand Up @@ -157,8 +157,8 @@ export function setTileVerticesColor(tile, newColor, indexArray = null) {
if (!!indexArray && (lowerBound > i || upperBound < i)) {
//If i is not one of the selected indexes, we keep the previous color
let previousColor = (tile.geometry.attributes.color) ?
tile.geometry.attributes.color.array.slice(i * 3, i * 3 + 3) :
tile.material.color.toArray();
tile.geometry.attributes.color.array.slice(i * 3, i * 3 + 3) :
tile.material.color.toArray();
vertexColor = previousColor;
}

Expand Down Expand Up @@ -215,8 +215,8 @@ export function createTileGroups(tile, materialsProps, ranges) {
let mesh = getMeshFromTile(tile);

let defaultMaterial = Array.isArray(mesh.material) ?
mesh.material[0] :
mesh.material;
mesh.material[0] :
mesh.material;

// Reset the materials
mesh.material = [ defaultMaterial ];
Expand Down Expand Up @@ -335,7 +335,7 @@ export function createTileGroupsFromBatchIDs(tile, groups) {
if (materialIndex < 0) {
// If the material is new, push it
materialIndex = materials.length;
materials.push(group.material)
materials.push(group.material);
}

// Push the batch IDs and remember their material
Expand Down
2 changes: 1 addition & 1 deletion src/Components/3DTiles/Model/CityObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tile } from "./Tile.js";
import { Tile } from './Tile.js';
import * as THREE from 'three';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Components/3DTiles/Model/CityObjectStyle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as THREE from "three";
import * as THREE from 'three';

/**
* Represents the style of a tile part. Accepted parameters are :
Expand All @@ -14,7 +14,7 @@ export class CityObjectStyle {
*/
this.materialProps = null;

if (typeof(params) !== "object") {
if (typeof(params) !== 'object') {
throw 'TilePartStyle require parameters in its constructor';
}

Expand Down
14 changes: 7 additions & 7 deletions src/Components/3DTiles/StyleManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CityObjectStyle } from "./Model/CityObjectStyle.js";
import { CityObjectID } from "./Model/CityObject.js";
import { createTileGroups } from "./3DTilesUtils.js";
import { Tile } from "./Model/Tile.js";
import { CityObjectStyle } from './Model/CityObjectStyle.js';
import { CityObjectID } from './Model/CityObject.js';
import { createTileGroups } from './3DTilesUtils.js';
import { Tile } from './Model/Tile.js';

/**
* Class used to manage the styles of city objects.
Expand Down Expand Up @@ -115,9 +115,9 @@ export class StyleManager {
* @returns {CityObjectStyle}
*/
getStyle(identifier) {
if (typeof(identifier) === "string") {
if (typeof(identifier) === 'string') {
return this.registeredStyles[identifier];
} else if (typeof(identifier) === "number") {
} else if (typeof(identifier) === 'number') {
return this.anonymousStyles[identifier];
}
throw 'Style identifier must be a string or a number';
Expand Down Expand Up @@ -197,7 +197,7 @@ export class StyleManager {
this._registerUsage(styleIdentifier, cityObjectId);
} else if (Array.isArray(cityObjectId)) {
cityObjectId.sort((idA, idB) => {
return idA.tileId - idB.tileId
return idA.tileId - idB.tileId;
});
for (let id of cityObjectId) {
if (this.styleTable[id.tileId] === undefined) {
Expand Down
60 changes: 30 additions & 30 deletions src/Components/3DTiles/TilesManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Tile } from "./Model/Tile.js";
import { getVisibleTiles, updateITownsView } from "./3DTilesUtils.js";
import { CityObjectID, CityObject, createCityObjectID } from "./Model/CityObject.js";
import { CityObjectStyle } from "./Model/CityObjectStyle.js";
import { StyleManager } from "./StyleManager.js";
import { EventSender } from "../Events/EventSender.js";
import { Tile } from './Model/Tile.js';
import { getVisibleTiles, updateITownsView } from './3DTilesUtils.js';
import { CityObjectID, CityObject, createCityObjectID } from './Model/CityObject.js';
import { CityObjectStyle } from './Model/CityObjectStyle.js';
import { StyleManager } from './StyleManager.js';
import { EventSender } from '../Events/EventSender.js';

/**
* Manages the tiles and the style for city objects.
Expand Down Expand Up @@ -54,15 +54,15 @@ export class TilesManager extends EventSender {
this.tiles = [];
if (this.totalTileCount !== 0)
{
// Load existing tiles
const tiles = getVisibleTiles(this.layer);
for (let tile of tiles) {
if (this.tiles[tile.tileId] === undefined) {
this.tiles[tile.tileId] = new Tile(this.layer, tile.tileId);
this.tiles[tile.tileId].loadCityObjects();
this.loadedTileCount += 1;
}
// Load existing tiles
const tiles = getVisibleTiles(this.layer);
for (let tile of tiles) {
if (this.tiles[tile.tileId] === undefined) {
this.tiles[tile.tileId] = new Tile(this.layer, tile.tileId);
this.tiles[tile.tileId].loadCityObjects();
this.loadedTileCount += 1;
}
}
}

///// EVENTS
Expand Down Expand Up @@ -93,22 +93,22 @@ export class TilesManager extends EventSender {
}

loadTile(tile) {
// Update the totalTileCount.
// TODO: this should be managed with an event: when the tileset is
// loaded (i.e. tileIndex filled), then totalTileCount should be set.
this.totalTileCount = this.layer.tileset.tiles.length;
// Verifies that the tile has not been already added (might be removed
// when tile unloading will be managed)
if (this.tiles[tile.tileId] === undefined) {
this.tiles[tile.tileId] = new Tile(this.layer, tile.tileId);
this.tiles[tile.tileId].loadCityObjects();
this.loadedTileCount += 1;
}
// Callback when a tile is loaded.
// TODO: Les tuiles d'iTowns devraient etre rendues invisibles plutot
// que d'etre déchargées et rechargées. A ce moment là, ce callback
// pourra etre dans le if ci dessus
this.sendEvent(TilesManager.EVENT_TILE_LOADED, tile);
// Update the totalTileCount.
// TODO: this should be managed with an event: when the tileset is
// loaded (i.e. tileIndex filled), then totalTileCount should be set.
this.totalTileCount = this.layer.tileset.tiles.length;
// Verifies that the tile has not been already added (might be removed
// when tile unloading will be managed)
if (this.tiles[tile.tileId] === undefined) {
this.tiles[tile.tileId] = new Tile(this.layer, tile.tileId);
this.tiles[tile.tileId].loadCityObjects();
this.loadedTileCount += 1;
}
// Callback when a tile is loaded.
// TODO: Les tuiles d'iTowns devraient etre rendues invisibles plutot
// que d'etre déchargées et rechargées. A ce moment là, ce callback
// pourra etre dans le if ci dessus
this.sendEvent(TilesManager.EVENT_TILE_LOADED, tile);
}

/**
Expand Down
17 changes: 11 additions & 6 deletions src/Components/Camera/CameraUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/** @format */

const THREE = require('three');

/**
* Makes the camera move to focus on the target position.
*
*
* @param {itowns.View} view The iTowns view.
* @param {itowns.PlanarControls} controls The camera controls.
* @param {THREE.Vector3} targetPos The target position.
Expand All @@ -23,10 +27,11 @@ export function focusCameraOn(view, controls, targetPos, options = {}) {
const horizontalDist = options.horizontalDistance || 1000;

let cameraPos = view.camera.camera3D.position.clone();
const direction = (new THREE.Vector3()).subVectors(targetPos, cameraPos);
const currentDist = Math.sqrt(direction.x * direction.x +
direction.y * direction.y);
cameraPos.addScaledVector(direction, (1 - horizontalDist / currentDist));
const direction = new THREE.Vector3().subVectors(targetPos, cameraPos);
const currentDist = Math.sqrt(
direction.x * direction.x + direction.y * direction.y
);
cameraPos.addScaledVector(direction, 1 - horizontalDist / currentDist);
cameraPos.z = targetPos.z + verticalDist;
const travelDuration = duration ? duration : 'auto';
const timeoutDuration = duration ? duration * 1000 : 0;
Expand All @@ -36,4 +41,4 @@ export function focusCameraOn(view, controls, targetPos, options = {}) {
reject(e);
}
});
}
}
4 changes: 2 additions & 2 deletions src/Components/Camera/PositionerWindow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Window } from "../GUI/js/Window";
import { Window } from '../GUI/js/Window';
import { MAIN_LOOP_EVENTS } from 'itowns';
import * as THREE from 'three';

Expand Down Expand Up @@ -60,7 +60,7 @@ export class PositionerWindow extends Window {

this.buttonValidateElement.onclick = () => {
this._validate();
}
};
}

/////////////////////////
Expand Down
Loading

0 comments on commit 835dc54

Please sign in to comment.