Skip to content

Commit

Permalink
Merge branch 'main' into backport-from-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarr authored Jan 26, 2025
2 parents ec8c933 + 3da0f5f commit 903abf2
Show file tree
Hide file tree
Showing 17 changed files with 799 additions and 313 deletions.
7 changes: 2 additions & 5 deletions src/components/street-generated-clones.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ AFRAME.registerComponent('street-generated-clones', {
multiple: true,
schema: {
// Common properties
model: { type: 'string' },
modelsArray: { type: 'array' }, // For random selection from multiple models
length: { type: 'number' }, // length in meters of segment
positionX: { default: 0, type: 'number' },
Expand Down Expand Up @@ -178,10 +177,8 @@ AFRAME.registerComponent('street-generated-clones', {

getModelMixin: function () {
const data = this.data;
if (data.modelsArray && data.modelsArray.length > 0) {
return data.modelsArray[Math.floor(this.rng() * data.modelsArray.length)];
}
return data.model;
if (!this.rng) return data.modelsArray[0]; // this is a hack but it works for now
return data.modelsArray[Math.floor(this.rng() * data.modelsArray.length)];
},

randPlacedElements: function (streetLength, spacing, count) {
Expand Down
37 changes: 13 additions & 24 deletions src/components/street-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const TYPES = {
clones: [
{
mode: 'random',
model: 'bus',
modelsArray: 'bus',
spacing: 15,
count: 1
}
Expand Down Expand Up @@ -198,33 +198,22 @@ AFRAME.registerComponent('street-segment', {
// for each of clones, stencils, rail, pedestrians, etc.
if (componentsToGenerate?.clones?.length > 0) {
componentsToGenerate.clones.forEach((clone, index) => {
if (clone?.modelsArray?.length > 0) {
this.el.setAttribute(`street-generated-clones__${index}`, {
mode: clone.mode,
modelsArray: clone.modelsArray,
length: this.data.length,
spacing: clone.spacing,
direction: this.data.direction,
count: clone.count
});
} else {
this.el.setAttribute(`street-generated-clones__${index}`, {
mode: clone.mode,
model: clone.model,
length: this.data.length,
spacing: clone.spacing,
direction: this.data.direction,
count: clone.count
});
}
this.el.setAttribute(`street-generated-clones__${index + 1}`, {
mode: clone.mode,
modelsArray: clone.modelsArray,
length: this.data.length,
spacing: clone.spacing,
direction: this.data.direction,
count: clone.count
});
});
}

if (componentsToGenerate?.stencil?.length > 0) {
componentsToGenerate.stencil.forEach((clone, index) => {
if (clone?.stencils?.length > 0) {
// case where there are multiple stencils such as bus-only
this.el.setAttribute(`street-generated-stencil__${index}`, {
this.el.setAttribute(`street-generated-stencil__${index + 1}`, {
stencils: clone.stencils,
length: this.data.length,
spacing: clone.spacing,
Expand All @@ -233,7 +222,7 @@ AFRAME.registerComponent('street-segment', {
cycleOffset: clone.cycleOffset
});
} else {
this.el.setAttribute(`street-generated-stencil__${index}`, {
this.el.setAttribute(`street-generated-stencil__${index + 1}`, {
model: clone.model,
length: this.data.length,
spacing: clone.spacing,
Expand All @@ -247,7 +236,7 @@ AFRAME.registerComponent('street-segment', {

if (componentsToGenerate?.pedestrians?.length > 0) {
componentsToGenerate.pedestrians.forEach((pedestrian, index) => {
this.el.setAttribute(`street-generated-pedestrians__${index}`, {
this.el.setAttribute(`street-generated-pedestrians__${index + 1}`, {
segmentWidth: this.data.width,
density: pedestrian.density,
length: this.data.length,
Expand All @@ -258,7 +247,7 @@ AFRAME.registerComponent('street-segment', {

if (componentsToGenerate?.striping?.length > 0) {
componentsToGenerate.striping.forEach((stripe, index) => {
this.el.setAttribute(`street-generated-striping__${index}`, {
this.el.setAttribute(`street-generated-striping__${index + 1}`, {
striping: stripe.striping,
segmentWidth: this.data.width,
length: this.data.length,
Expand Down
Loading

0 comments on commit 903abf2

Please sign in to comment.