Skip to content

Commit

Permalink
Merge pull request #503 from 3DStreet/streetplan-support
Browse files Browse the repository at this point in the history
Streetplan support
  • Loading branch information
kfarr authored Apr 11, 2024
2 parents a3d4a15 + 2137cbd commit a629f82
Show file tree
Hide file tree
Showing 13 changed files with 1,039 additions and 34 deletions.
4 changes: 2 additions & 2 deletions dist/aframe-street-component.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Orientation - default model orientation is "outbound" (away from camera)
var streetmixParsersTested = require('./tested/aframe-streetmix-parsers-tested');
var streetmixUtils = require('./tested/streetmix-utils');
var segmentsVariants = require('./segments-variants.json');
var { segmentVariants } = require('./segments-variants.js');

function cloneMixinAsChildren ({ objectMixinId = '', parentEl = null, step = 15, radius = 60, rotation = '0 0 0', positionXYString = '0 0', length = undefined, randomY = false }) {
for (let j = (radius * -1); j <= radius; j = j + step) {
Expand Down Expand Up @@ -236,6 +236,9 @@ function getBikeLaneMixin (variant) {
if (variant === 'red') {
return 'surface-red bike-lane';
}
if (variant === 'blue') {
return 'surface-blue bike-lane';
}
if (variant === 'green') {
return 'surface-green bike-lane';
}
Expand All @@ -246,6 +249,9 @@ function getBusLaneMixin (variant) {
if (variant === 'colored' | variant === 'red') {
return 'surface-red bus-lane';
}
if (variant === 'blue') {
return 'surface-blue bus-lane';
}
if (variant === 'grass') {
return 'surface-green bus-lane';
}
Expand Down Expand Up @@ -757,7 +763,7 @@ function createSeparatorElement (positionY, rotationY, mixinId, length, repeatCo
function supportCheck (segmentType, segmentVariantString) {
if (segmentType == 'separator') return;
// variants supported in 3DStreet
const supportedVariants = segmentsVariants[segmentType];
const supportedVariants = segmentVariants[segmentType];
if (!supportedVariants) {
STREET.notify.warningMessage(`The '${segmentType}' segment type is not yet supported in 3DStreet`);
console.log(`The '${segmentType}' segment type is not yet supported in 3DStreet`);
Expand Down Expand Up @@ -798,7 +804,7 @@ function processSegments (segments, showStriping, length, globalAnimated, showVe
var positionY = 0;

// get variantString
var variantList = segments[i].variantString.split('|');
var variantList = segments[i].variantString ? segments[i].variantString.split('|') : '';

// show warning message if segment or variantString are not supported
supportCheck(segments[i].type, segments[i].variantString);
Expand Down
1 change: 1 addition & 0 deletions src/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function buildAssetHTML (assetUrl, categories) {
<a-mixin id="yellow" material="color:#f7d117"></a-mixin>
<a-mixin id="surface-green" material="color:#adff83"></a-mixin>
<a-mixin id="surface-red" material="color:#ff9393"></a-mixin>
<a-mixin id="surface-blue" material="color:#00b6b6"></a-mixin>
`,
'lane-separator': `
<!-- lane separator markings -->
Expand Down
98 changes: 98 additions & 0 deletions src/components/streetplan-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* global AFRAME, THREE, XMLHttpRequest */
var streetplanUtils = require('../streetplan/streetplan-utils.js');
var exampleJSON = require('../streetplan/exampleJSON.json');

AFRAME.registerComponent('streetplan-loader', {
dependencies: ['street'],
schema: {
streetplanStreetURL: { type: 'string' },
streetplanAPIURL: { type: 'string' },
streetplanEncJSON: { type: 'string' },
showBuildings: { default: true },
name: { default: '' }
},
streetplanResponseParse: function (streetplanResponseObject) {
const el = this.el;
const data = this.data;
const streetplanProject = streetplanResponseObject.project;

// convert Streetplan structure to Streetmix-like structure
const streetData = streetplanUtils.convertStreetStruct(streetplanProject);

const streetplanSegments = streetData.segments;

const streetplanName = streetData.name;
// streetplan alternative name
const streetplanAltName = streetData.altName;

console.log('streetplanName', streetplanName);
// el.setAttribute('streetplan-loader', 'name', streetplanName);

let currentSceneTitle;
const sceneEl = this.el.sceneEl;
if (sceneEl && sceneEl.getAttribute('metadata')) {
currentSceneTitle = sceneEl.getAttribute('metadata').sceneTitle;
}
if (!currentSceneTitle) { // only set title from streetplan if none exists
sceneEl.setAttribute('metadata', 'sceneTitle', streetplanName);
console.log('therefore setting metadata sceneTitle as streetplanName', streetplanName);
}

el.setAttribute('data-layer-name', 'StreetPlan • ' + streetplanName);

if (data.showBuildings) {
el.setAttribute('street', 'right', streetData.rightBuildingVariant);
el.setAttribute('street', 'left', streetData.leftBuildingVariant);
}
el.setAttribute('street', 'type', 'streetmixSegmentsMetric');
// set JSON attribute last or it messes things up
el.setAttribute('street', 'JSON', JSON.stringify({ streetmixSegmentsMetric: streetplanSegments }));
el.emit('streetplan-loader-street-loaded');
},
update: function (oldData) { // fired at start and at each subsequent change of any schema value
// This method may fire a few times when viewing a streetmix street in 3dstreet:
// First to find the proper path, once to actually load the street, and then subsequent updates such as street name
const that = this;
const data = this.data;
const el = this.el;

// /* ***** debugging ***** */
// setTimeout(()=> {
// this.streetplanResponseParse(exampleJSON);
// }, 1000);
// return;

// load from URL encoded Streetplan JSON
if (data.streetplanEncJSON) {
const streetplanJSON = decodeURIComponent(encodedString);
this.streetplanResponseParse(JSON.parse(streetplanJSON));
return;
}

// if the loader has run once already, and upon update neither URL has changed, do not take action
if ((oldData.streetplanStreetURL === data.streetplanStreetURL) && (oldData.streetplanAPIURL === data.streetplanAPIURL)) {
// console.log('[streetmix-loader]', 'Neither streetplanStreetURL nor streetplanAPIURL have changed in this component data update, not reloading street.')
return;
}

var request = new XMLHttpRequest();
console.log('[streetplan-loader]', 'GET ' + data.streetplanAPIURL);

request.open('GET', data.streetplanAPIURL, true);
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
// Connection success
const streetplanResponseObject = JSON.parse(this.response);
that.streetplanResponseParse(streetplanResponseObject);
} else {
// We reached our target server, but it returned an error
console.log('[streetplan-loader]', 'Loading Error: We reached the target server, but it returned an error');
}
};
request.onerror = function () {
// There was a connection error of some sort
console.log('[streetplan-loader]', 'Loading Error: There was a connection error of some sort');
};
request.send();
}
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require('./components/notify.js');
require('./components/create-from-json');
require('./components/screentock.js');
require('aframe-atlas-uvs-component');
require('./components/streetplan-loader');

AFRAME.registerComponent('street', {
schema: {
Expand Down
13 changes: 12 additions & 1 deletion src/json-utils_1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ AFRAME.registerComponent('scene-title', {
});

AFRAME.registerComponent('set-loader-from-hash', {
dependencies: ['streetmix-loader'],
schema: {
defaultURL: { type: 'string' }
},
Expand All @@ -536,6 +535,18 @@ AFRAME.registerComponent('set-loader-from-hash', {
'streetmixStreetURL',
streetURL
);
} else if (streetURL.includes('streetplan.net/')) {
// load from Streetplan encoded JSON in URL
console.log(
'[set-loader-from-hash]',
'Set streetplan-loader streetplanAPIURL to',
streetURL
);
this.el.setAttribute(
'streetplan-loader',
'streetplanAPIURL',
streetURL
);
} else {
// try to load JSON file from remote resource
console.log(
Expand Down
38 changes: 38 additions & 0 deletions src/segments-variants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const segmentVariants = {
/* sidewalk segments */
sidewalk: ['empty', 'sparse', 'normal', 'dense'],
'sidewalk-wayfinding': ['large'],
'sidewalk-bench': ['left', 'right', 'center'],
'sidewalk-bike-rack': ['left|sidewalk-parallel', 'right|sidewalk-parallel', 'left|sidewalk', 'right|sidewalk'],
'sidewalk-tree': ['big', 'palm-tree'],
/* lights and utilities */
utilities: ['left', 'right'],
'sidewalk-lamp': ['right|modern', 'both|modern', 'left|modern', 'right|traditional', 'both|traditional', 'left|traditional', 'right|pride', 'both|pride', 'left|pride'],
// furniture segments
parklet: ['left', 'right'],
'outdoor-dining': ['empty|sidewalk', 'empty|road'],
bikeshare: ['left|road', 'right|road', 'left|sidewalk', 'right|sidewalk'],
// bike and scooter segments
'bike-lane': ['inbound|green|sidewalk', 'inbound|green|road', 'outbound|green|sidewalk', 'outbound|green|road', 'inbound|regular|sidewalk', 'inbound|regular|road', 'outbound|regular|sidewalk', 'outbound|regular|road', 'inbound|red|sidewalk', 'inbound|red|road', 'outbound|red|sidewalk', 'outbound|red|road'],
scooter: ['inbound|regular', 'inbound|green', 'inbound|red', 'outbound|regular', 'outbound|green', 'outbound|red'],
// road segments
'bus-lane': ['inbound|colored|typical', 'outbound|colored|typical', 'inbound|regular|typical', 'outbound|regular|typical', 'inbound|red|typical', 'outbound|red|typical'],
'drive-lane': ['inbound|car', 'outbound|car', 'inbound|truck', 'outbound|truck', 'outbound|av', 'inbound|av', 'outbound|pedestrian', 'inbound|pedestrian', 'inbound|sharrow', 'outbound|sharrow'],
'turn-lane': ['inbound|left', 'inbound|right', 'inbound|left-right-straight', 'inbound|shared', 'inbound|both', 'inbound|left-straight', 'inbound|right-straight', 'inbound|straight', 'outbound|left', 'outbound|right', 'outbound|left-right-straight', 'outbound|shared', 'outbound|both', 'outbound|left-straight', 'outbound|right-straight', 'outbound|straight'],
'parking-lane': ['sideways|right', 'sideways|left', 'inbound|right', 'inbound|left', 'outbound|left', 'outbound|right', 'angled-front-left|left', 'angled-front-right|left', 'angled-rear-left|left', 'angled-rear-right|left', 'angled-front-left|right', 'angled-front-right|right', 'angled-rear-left|right', 'angled-rear-right|right'],
'food-truck': ['left', 'right'],
'flex-zone': ['taxi|inbound|right', 'taxi|inbound|left', 'taxi|outbound|right', 'taxi|outbound|left', 'rideshare|outbound|right', 'rideshare|outbound|right', 'rideshare|inbound|right', 'rideshare|inbound|left'],
// rail vehicles
streetcar: ['inbound|regular', 'inbound|colored', 'inbound|grass', 'outbound|regular', 'outbound|colored', 'outbound|grass'],
'light-rail': ['inbound|regular', 'inbound|colored', 'inbound|grass', 'outbound|regular', 'outbound|colored', 'outbound|grass'],
// stations
'brt-station': ['center'],
'transit-shelter': ['left|street-level', 'right|street-level', 'right|light-rail', 'left|light-rail'],
// divider and temporary
divider: ['buffer', 'flowers', 'planting-strip', 'planter-box', 'palm-tree', 'big-tree', 'bush', 'dome', 'bollard', 'striped-buffer'],
temporary: ['barricade', 'traffic-cone', 'jersey-barrier-plastic', 'jersey-barrier-concrete'],
// magic segment
'magic-carpet': ['aladdin']
};

module.exports.segmentVariants = segmentVariants;
27 changes: 0 additions & 27 deletions src/segments-variants.json

This file was deleted.

Loading

0 comments on commit a629f82

Please sign in to comment.