Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bicycle and electro scooter animation #417

Merged
merged 1 commit into from
Dec 8, 2023
Merged
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
25 changes: 19 additions & 6 deletions src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,26 +530,39 @@ function createOutdoorDining (length, posY) {
return outdoorDiningParentEl;
}

function createMicroMobilityElement (variantList, segmentType, posY = 0, length, showVehicles) {
function createMicroMobilityElement (variantList, segmentType, posY = 0, length, showVehicles, animated = false) {
if (!showVehicles) {
return;
}
const microMobilityParentEl = document.createElement('a-entity');

const bikeLength = 2.03;
const bikeCount = getRandomIntInclusive(2, 5);

const cyclistMixins = ['cyclist-cargo', 'cyclist1', 'cyclist2',
'cyclist3', 'cyclist-dutch', 'cyclist-kid'];

const countCyclist = cyclistMixins.length;
let mixinId = 'Bicycle_1';
const randPlaces = randPlacedElements(length, bikeLength, bikeCount);
randPlaces.forEach(randPosZ => {
const reusableObjectEl = document.createElement('a-entity');
const rotationY = (variantList[0] === 'inbound') ? 0 : 180;
reusableObjectEl.setAttribute('rotation', '0 ' + rotationY + ' 0');
reusableObjectEl.setAttribute('position', {y: posY, z: randPosZ});

if (animated) {
reusableObjectEl.setAttribute('animation-mixer', '');
const speed = 5;
addLinearStreetAnimation(reusableObjectEl, speed, length, 0, posY, randPosZ, variantList[0]);
}
if (segmentType === 'bike-lane') {
reusableObjectEl.setAttribute('mixin', 'Bicycle_1');
mixinId = cyclistMixins[getRandomIntInclusive(0, countCyclist)];
} else {
reusableObjectEl.setAttribute('mixin', 'ElectricScooter_1');
mixinId = 'ElectricScooter_1';
}
reusableObjectEl.setAttribute('position', {y: posY, z: randPosZ});

reusableObjectEl.setAttribute('mixin', mixinId);
microMobilityParentEl.append(reusableObjectEl);
});

Expand Down Expand Up @@ -802,7 +815,7 @@ function processSegments (segments, showStriping, length, globalAnimated, showVe
cloneMixinAsChildren({ objectMixinId: 'stencils bike-arrow', parentEl: stencilsParentEl, rotation: '-90 ' + rotationY + ' 0', step: 20, radius: clonedObjectRadius });
// add this stencil stuff to the segment parent
segmentParentEl.append(stencilsParentEl);
segmentParentEl.append(createMicroMobilityElement(variantList, segments[i].type, elevationPosY, length, showVehicles));
segmentParentEl.append(createMicroMobilityElement(variantList, segments[i].type, elevationPosY, length, showVehicles, globalAnimated));
} else if (segments[i].type === 'light-rail' || segments[i].type === 'streetcar') {
// get the mixin id for a bus lane
groundMixinId = getBusLaneMixin(variantList[1]);
Expand Down
Loading