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

Vehicle Animation 1.0 #182

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions animated.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@
"variantString": "empty",
"type": "sidewalk"
},
{
"width": 9,
"variantString": "outbound",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "outbound|pedestrian|animated",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "outbound|car|animated",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "outbound|sharrow|animated",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "outbound|microvan|animated",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "inbound|truck|animated",
"type": "drive-lane"
},
{
"width": 9,
"variantString": "dense|animated",
Expand Down
2 changes: 1 addition & 1 deletion dist/aframe-street-component.js

Large diffs are not rendered by default.

69 changes: 53 additions & 16 deletions src/aframe-streetmix-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function createSidewalkClonedVariants (BasePositionX, segmentWidthInMeters, dens
const dividerParentEl = createParentElement(BasePositionX, 'pedestrians-parent');
// Randomly generate avatars
for (let i = 0; i < totalPedestrianNumber; i++) {
var variantName = (animated == 'true') ? 'a_char' + String(getRandomIntInclusive(1, 8)) : 'char' + String(getRandomIntInclusive(1, 16));
var variantName = (animated === 'true') ? 'a_char' + String(getRandomIntInclusive(1, 8)) : 'char' + String(getRandomIntInclusive(1, 16));
var xVal = getRandomArbitrary(xValueRange[0], xValueRange[1]);
var zVal = zValueRange.pop();
var positionXYZString = xVal + ' 0 ' + zVal;
Expand All @@ -214,10 +214,10 @@ function createSidewalkClonedVariants (BasePositionX, segmentWidthInMeters, dens
animationDirection = 'outbound';
}

if (animationDirection == 'outbound'){
startingDistanceToTravel = Math.abs(-length/2 - zVal);
if (animationDirection === 'outbound') {
startingDistanceToTravel = Math.abs(-length / 2 - zVal);
} else {
startingDistanceToTravel = Math.abs(length/2 - zVal);
startingDistanceToTravel = Math.abs(length / 2 - zVal);
}

startingDuration = (startingDistanceToTravel / 1.4) * 1000;
Expand All @@ -229,18 +229,18 @@ function createSidewalkClonedVariants (BasePositionX, segmentWidthInMeters, dens
placedObjectEl.setAttribute('animation__2', 'property', 'position');
placedObjectEl.setAttribute('animation__2', 'easing', 'linear');
placedObjectEl.setAttribute('animation__2', 'loop', 'true');
if (animationDirection === 'outbound'){
placedObjectEl.setAttribute('animation__1', 'to', {z: -length/2});
if (animationDirection === 'outbound') {
placedObjectEl.setAttribute('animation__1', 'to', { z: -length / 2 });
placedObjectEl.setAttribute('animation__1', 'dur', startingDuration);
placedObjectEl.setAttribute('animation__2', 'from', {x: xVal, y: 0, z: length/2});
placedObjectEl.setAttribute('animation__2', 'to', {x: xVal, y: 0, z: -length/2});
placedObjectEl.setAttribute('animation__2', 'from', { x: xVal, y: 0, z: length / 2 });
placedObjectEl.setAttribute('animation__2', 'to', { x: xVal, y: 0, z: -length / 2 });
placedObjectEl.setAttribute('animation__2', 'delay', startingDuration);
placedObjectEl.setAttribute('animation__2', 'dur', totalStreetDuration);
} else {
placedObjectEl.setAttribute('animation__1', 'to', {z: length/2});
placedObjectEl.setAttribute('animation__1', 'to', { z: length / 2 });
placedObjectEl.setAttribute('animation__1', 'dur', startingDuration);
placedObjectEl.setAttribute('animation__2', 'from', {x: xVal, y: 0, z: -length/2});
placedObjectEl.setAttribute('animation__2', 'to', {x: xVal, y: 0, z: length/2});
placedObjectEl.setAttribute('animation__2', 'from', { x: xVal, y: 0, z: -length / 2 });
placedObjectEl.setAttribute('animation__2', 'to', { x: xVal, y: 0, z: length / 2 });
placedObjectEl.setAttribute('animation__2', 'delay', startingDuration);
placedObjectEl.setAttribute('animation__2', 'dur', totalStreetDuration);
}
Expand Down Expand Up @@ -294,7 +294,18 @@ function createBusElement (isOutbound, positionX) {
return busParentEl;
}

function createDriveLaneElement (variantList, positionX, segmentWidthInMeters, length) {
function createDriveLaneElement (variantList, positionX, segmentWidthInMeters, length, animated = 'false') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for a string instead of boolean for animated? (like 'false' instead of the false and elsewhere below 'true' instead of true)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason - not using a boolean actually makes the code less clean. Just added a commit that changes animated to a boolean value in createSidewalkClonedVariants and createDriveLaneElement 👍

var speed = 10; // meters per second
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this increases the default speed to 10 m/s ~= 22mph

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very speedy 🐎

var totalStreetDuration = (length / speed) * 1000; // time in milliseconds
var animationDirection = variantList[0];
var startingDistanceToTravel;
var startingDuration;
if (animationDirection === 'outbound') {
startingDistanceToTravel = Math.abs(-length / 2 - 0);
} else {
startingDistanceToTravel = Math.abs(length / 2 - 0);
}
startingDuration = (startingDistanceToTravel / speed) * 1000;
const driveLaneParentEl = document.createElement('a-entity');

const reusableObjectEl = document.createElement('a-entity');
Expand All @@ -308,8 +319,33 @@ function createDriveLaneElement (variantList, positionX, segmentWidthInMeters, l
} else if (variantList[1] === 'truck') {
reusableObjectEl.setAttribute('mixin', 'box-truck');
} else if (variantList[1] === 'pedestrian') {
return createSidewalkClonedVariants(positionX, segmentWidthInMeters, 'normal', length, variantList[0]);
return createSidewalkClonedVariants(positionX, segmentWidthInMeters, 'normal', length, variantList[0], animated);
}

if (animated === 'true') {
reusableObjectEl.setAttribute('animation__1', 'property', 'position');
reusableObjectEl.setAttribute('animation__1', 'easing', 'linear');
reusableObjectEl.setAttribute('animation__1', 'loop', 'false');
reusableObjectEl.setAttribute('animation__2', 'property', 'position');
reusableObjectEl.setAttribute('animation__2', 'easing', 'linear');
reusableObjectEl.setAttribute('animation__2', 'loop', 'true');
if (animationDirection === 'outbound') {
reusableObjectEl.setAttribute('animation__1', 'to', { z: -length / 2 });
reusableObjectEl.setAttribute('animation__1', 'dur', startingDuration);
reusableObjectEl.setAttribute('animation__2', 'from', { x: positionX, y: 0, z: length / 2 });
reusableObjectEl.setAttribute('animation__2', 'to', { x: positionX, y: 0, z: -length / 2 });
reusableObjectEl.setAttribute('animation__2', 'delay', startingDuration);
reusableObjectEl.setAttribute('animation__2', 'dur', totalStreetDuration);
} else {
reusableObjectEl.setAttribute('animation__1', 'to', { z: length / 2 });
reusableObjectEl.setAttribute('animation__1', 'dur', startingDuration);
reusableObjectEl.setAttribute('animation__2', 'from', { x: positionX, y: 0, z: -length / 2 });
reusableObjectEl.setAttribute('animation__2', 'to', { x: positionX, y: 0, z: length / 2 });
reusableObjectEl.setAttribute('animation__2', 'delay', startingDuration);
reusableObjectEl.setAttribute('animation__2', 'dur', totalStreetDuration);
}
}

driveLaneParentEl.append(reusableObjectEl);

return driveLaneParentEl;
Expand Down Expand Up @@ -671,7 +707,8 @@ function processSegments (segments, showStriping, length) {
// add this stencil stuff to the segment parent
segmentParentEl.append(reusableObjectStencilsParentEl);
} else if (segments[i].type === 'drive-lane') {
segmentParentEl.append(createDriveLaneElement(variantList, positionX, segmentWidthInMeters, length));
var isAnimated = (variantList[2] === 'animated') ? 'true' : 'false';
segmentParentEl.append(createDriveLaneElement(variantList, positionX, segmentWidthInMeters, length, isAnimated));
} else if (segments[i].type === 'food-truck') {
groundMixinId = 'drive-lane';
segmentParentEl.append(createFoodTruckElement(variantList, positionX));
Expand All @@ -692,8 +729,8 @@ function processSegments (segments, showStriping, length) {
segmentParentEl.append(reusableObjectStencilsParentEl);
} else if (segments[i].type === 'sidewalk' && variantList[0] !== 'empty') {
// handles variantString with value sparse, normal, or dense sidewalk
const isAnimated = variantList[1] == 'animated' ? 'true' : 'false';
segmentParentEl.append(createSidewalkClonedVariants(positionX, segmentWidthInMeters, variantList[0], length,'random',isAnimated));
const isAnimated = variantList[1] === 'animated' ? 'true' : 'false';
segmentParentEl.append(createSidewalkClonedVariants(positionX, segmentWidthInMeters, variantList[0], length, 'random', isAnimated));
} else if (segments[i].type === 'sidewalk-wayfinding') {
segmentParentEl.append(createWayfindingElements(positionX));
} else if (segments[i].type === 'sidewalk-bench') {
Expand Down