|
| 1 | +--- |
| 2 | +sidebar_position: 3 |
| 3 | +--- |
| 4 | + |
| 5 | +# `street-segment` Component |
| 6 | + |
| 7 | +The `street-segment` component creates and manages individual street segments in a 3D environment. Each segment represents a distinct part of the street (e.g., drive lanes, bike lanes, sidewalks) with specific properties and behaviors. |
| 8 | + |
| 9 | +## User Interface |
| 10 | + |
| 11 | +A custom sidebar in 3DStreet Editor allows users to edit a subset of `street-segment` properties and associated generated components. |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## Properties |
| 16 | + |
| 17 | +| Property | Type | Default | Description | |
| 18 | +|------------|--------|----------|-------------| |
| 19 | +| type | string | - | Type of street segment. Must be one of: 'drive-lane', 'bus-lane', 'bike-lane', 'sidewalk', 'parking-lane', 'divider', 'grass', 'rail' | |
| 20 | +| width | number | - | Width of the segment in meters | |
| 21 | +| length | number | - | Length of the segment in meters | |
| 22 | +| level | int | 0 | Vertical level of the segment (-1 to 2) | |
| 23 | +| direction | string | - | Direction of traffic flow: 'none', 'inbound', or 'outbound' | |
| 24 | +| surface | string | 'asphalt'| Surface material type. One of: 'asphalt', 'concrete', 'grass', 'sidewalk', 'gravel', 'sand', 'none', 'solid' | |
| 25 | +| color | color | - | Color of the segment surface | |
| 26 | + |
| 27 | +## Segment Types |
| 28 | + |
| 29 | +The component includes several predefined segment types with specific configurations: |
| 30 | + |
| 31 | +### Drive Lane |
| 32 | +```javascript |
| 33 | +{ |
| 34 | + type: 'drive-lane', |
| 35 | + color: white, |
| 36 | + surface: 'asphalt', |
| 37 | + level: 0, |
| 38 | + generated: { |
| 39 | + clones: [{ |
| 40 | + mode: 'random', |
| 41 | + modelsArray: 'sedan-rig, box-truck-rig, self-driving-waymo-car, suv-rig, motorbike', |
| 42 | + spacing: 7.3, |
| 43 | + count: 4 |
| 44 | + }] |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Bus Lane |
| 50 | +```javascript |
| 51 | +{ |
| 52 | + type: 'bus-lane', |
| 53 | + surface: 'asphalt', |
| 54 | + color: red, |
| 55 | + level: 0, |
| 56 | + generated: { |
| 57 | + clones: [{ mode: 'random', modelsArray: 'bus', spacing: 15, count: 1 }], |
| 58 | + stencil: [{ modelsArray: 'word-only, word-taxi, word-bus', spacing: 40, padding: 10 }] |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Bike Lane |
| 64 | +```javascript |
| 65 | +{ |
| 66 | + type: 'bike-lane', |
| 67 | + color: green, |
| 68 | + surface: 'asphalt', |
| 69 | + level: 0, |
| 70 | + generated: { |
| 71 | + stencil: [{ modelsArray: 'bike-arrow', cycleOffset: 0.3, spacing: 20 }], |
| 72 | + clones: [{ |
| 73 | + mode: 'random', |
| 74 | + modelsArray: 'cyclist-cargo, cyclist1, cyclist2, cyclist3, cyclist-dutch, cyclist-kid, ElectricScooter_1', |
| 75 | + spacing: 2.03, |
| 76 | + count: 4 |
| 77 | + }] |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +## Events |
| 83 | + |
| 84 | +| Event Name | Description | Event Detail | |
| 85 | +|------------|-------------|--------------| |
| 86 | +| segment-width-changed | Fired when segment width is modified | `{oldWidth, newWidth}` | |
| 87 | + |
| 88 | +## Generated Components |
| 89 | + |
| 90 | +The component can automatically generate and manage several sub-components based on the segment type: |
| 91 | + |
| 92 | +- **Clones**: Generates repeated 3D models (vehicles, cyclists, etc.) |
| 93 | +- **Stencils**: Adds road markings and symbols |
| 94 | +- **Pedestrians**: Adds pedestrian models with configurable density |
| 95 | +- **Striping**: Adds road stripes and markings |
| 96 | + |
| 97 | +## Surface Types and Textures |
| 98 | + |
| 99 | +The component supports various surface types with corresponding textures: |
| 100 | + |
| 101 | +| Surface Type | Texture ID | Description | |
| 102 | +|--------------|------------|-------------| |
| 103 | +| asphalt | seamless-road | Standard road surface | |
| 104 | +| concrete | seamless-bright-road | Bright concrete surface | |
| 105 | +| grass | grass-texture | Grass surface | |
| 106 | +| sidewalk | seamless-sidewalk | Sidewalk texture | |
| 107 | +| gravel | compacted-gravel-texture | Gravel surface | |
| 108 | +| sand | sandy-asphalt-texture | Sandy surface | |
| 109 | +| hatched | hatched-base | Hatched marking pattern | |
| 110 | + |
| 111 | +## Usage |
| 112 | + |
| 113 | +Basic usage example: |
| 114 | + |
| 115 | +```html |
| 116 | +<a-entity street-segment=" |
| 117 | + type: drive-lane; |
| 118 | + surface: asphalt; |
| 119 | + color: white; |
| 120 | + width: 3; |
| 121 | + length: 150"> |
| 122 | +</a-entity> |
| 123 | +``` |
| 124 | + |
| 125 | +## Component Lifecycle |
| 126 | + |
| 127 | +The component manages several key operations during its lifecycle: |
| 128 | + |
| 129 | +1. **Initialization**: Sets up default height and generated components list |
| 130 | +2. **Update**: Handles property changes and updates meshes accordingly |
| 131 | +3. **Remove**: Cleans up generated components and meshes |
| 132 | + |
| 133 | +## Methods |
| 134 | + |
| 135 | +### calculateHeight(elevationLevel) |
| 136 | +Converts elevation levels (-1 to 2) to Three.js meter units. |
| 137 | + |
| 138 | +### generateMesh(data) |
| 139 | +Creates the segment's 3D geometry and materials. |
| 140 | + |
| 141 | +### calculateTextureRepeat(length, width, textureSourceId) |
| 142 | +Calculates texture repeat and offset values based on segment dimensions. |
| 143 | + |
| 144 | +## Notes |
| 145 | + |
| 146 | +- The component automatically handles elevation changes based on the level property |
| 147 | +- Texture repeats are calculated automatically based on segment dimensions |
| 148 | +- Generated components (vehicles, pedestrians, etc.) are managed automatically based on segment type |
| 149 | +- The component uses a custom 'below-box' geometry for proper ground alignment |
| 150 | + |
| 151 | +## Known Limitations |
| 152 | + |
| 153 | +- Surface textures must be present via asset loader, this component does not preload textures |
| 154 | +- Some generated components require specific 3D models to be available |
| 155 | +- Elevation levels are limited to the range of -1 to 2 |
0 commit comments