|
| 1 | +# Map Builder Export System |
| 2 | + |
| 3 | +This document describes the enhanced export functionality for the Map Builder application. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The export system has been completely refactored to provide professional-grade Three.js code generation with comprehensive options and best practices. |
| 8 | + |
| 9 | +## Key Improvements |
| 10 | + |
| 11 | +### π **Enhanced TypeScript Export** |
| 12 | +- **Complete Scene Setup**: Generates full scene initialization with renderer configuration |
| 13 | +- **Professional Lighting**: Includes ambient, directional, and fill lighting with proper shadow setup |
| 14 | +- **Camera System**: Configurable perspective camera with proper aspect ratio handling |
| 15 | +- **Controls Integration**: OrbitControls with optimized settings |
| 16 | +- **Type Safety**: Full TypeScript interfaces and type definitions |
| 17 | +- **Render Loop**: Complete animation loop with window resize handling |
| 18 | + |
| 19 | +### π **JavaScript Export Support** |
| 20 | +- **Multiple Module Formats**: ES6, CommonJS, and UMD support |
| 21 | +- **Cross-browser Compatibility**: Compatible with older browsers |
| 22 | +- **Flexible Integration**: Easy to integrate into existing projects |
| 23 | + |
| 24 | +### β **Export Dialog** |
| 25 | +- **Tabbed Interface**: Organized options across Format, Features, Optimization, and Advanced tabs |
| 26 | +- **Real-time Preview**: Shows estimated file size and enabled features |
| 27 | +- **Export Options**: Comprehensive customization options |
| 28 | + |
| 29 | +## Export Options |
| 30 | + |
| 31 | +### Format Options |
| 32 | +- **Language**: TypeScript (recommended) or JavaScript |
| 33 | +- **Target Framework**: Three.js (WebGPU), with Babylon.js and WebGL planned |
| 34 | +- **Module Format**: ES6 modules, CommonJS, or UMD (JavaScript only) |
| 35 | + |
| 36 | +### Features |
| 37 | +- β
**Camera Setup**: Perspective camera with proper configuration |
| 38 | +- β
**Professional Lighting**: Multi-light setup with shadows |
| 39 | +- β
**Grid Helper**: Visual grid for reference |
| 40 | +- β
**Debug Helpers**: Development aids |
| 41 | +- β
**Documentation Comments**: Comprehensive JSDoc comments |
| 42 | + |
| 43 | +### Optimization |
| 44 | +- β
**Geometry Optimization**: Reduces polygon count for better performance |
| 45 | +- β
**Material Factories**: Reusable material creation functions |
| 46 | +- β
**Geometry Factories**: Optimized geometry creation |
| 47 | +- β
**Code Minification**: Smaller file sizes |
| 48 | + |
| 49 | +### Advanced Settings |
| 50 | +- **Performance Metrics**: Object count and estimated file size |
| 51 | +- **Export Summary**: Complete overview of selected options |
| 52 | + |
| 53 | +## Usage Examples |
| 54 | + |
| 55 | +### TypeScript Export (Full Featured) |
| 56 | + |
| 57 | +```typescript |
| 58 | +import { createMapScene } from './scene'; |
| 59 | + |
| 60 | +// Create renderer |
| 61 | +const renderer = new THREE.WebGLRenderer({ antialias: true }); |
| 62 | +document.body.appendChild(renderer.domElement); |
| 63 | + |
| 64 | +// Create scene with configuration |
| 65 | +const { scene, camera, controls, animate } = createMapScene(renderer, { |
| 66 | + enableShadows: true, |
| 67 | + shadowMapSize: 2048, |
| 68 | + pixelRatio: 2 |
| 69 | +}); |
| 70 | + |
| 71 | +// Start animation |
| 72 | +animate(); |
| 73 | +``` |
| 74 | + |
| 75 | +### JavaScript Export (ES6 Modules) |
| 76 | + |
| 77 | +```javascript |
| 78 | +import { createMapScene } from './scene.js'; |
| 79 | + |
| 80 | +// Create renderer |
| 81 | +const renderer = new THREE.WebGLRenderer({ antialias: true }); |
| 82 | +document.body.appendChild(renderer.domElement); |
| 83 | + |
| 84 | +// Create scene |
| 85 | +const result = createMapScene(renderer, { |
| 86 | + enableShadows: true, |
| 87 | + shadowMapSize: 2048 |
| 88 | +}); |
| 89 | + |
| 90 | +// Start animation |
| 91 | +result.animate(); |
| 92 | +``` |
| 93 | + |
| 94 | +### JavaScript Export (CommonJS) |
| 95 | + |
| 96 | +```javascript |
| 97 | +const { createMapScene } = require('./scene.js'); |
| 98 | + |
| 99 | +// Create renderer |
| 100 | +const renderer = new THREE.WebGLRenderer({ antialias: true }); |
| 101 | +document.body.appendChild(renderer.domElement); |
| 102 | + |
| 103 | +// Create scene |
| 104 | +const result = createMapScene(renderer); |
| 105 | +result.animate(); |
| 106 | +``` |
| 107 | + |
| 108 | +## Generated Code Features |
| 109 | + |
| 110 | +### Professional Scene Setup |
| 111 | +- Proper renderer configuration with optimal settings |
| 112 | +- Shadow mapping with configurable quality |
| 113 | +- Pixel ratio handling for high-DPI displays |
| 114 | +- Responsive window resize handling |
| 115 | + |
| 116 | +### Advanced Lighting System |
| 117 | +- **Ambient Light**: Provides overall base illumination |
| 118 | +- **Directional Light**: Main light source with shadows |
| 119 | +- **Fill Light**: Reduces harsh shadows for better visual quality |
| 120 | + |
| 121 | +### Object Management |
| 122 | +- **User Data**: Each object includes metadata (id, name, type) |
| 123 | +- **Shadow Casting/Receiving**: Proper shadow configuration |
| 124 | +- **Transform Application**: Position, rotation, and scale applied correctly |
| 125 | +- **Material Properties**: PBR materials with metalness and roughness |
| 126 | + |
| 127 | +### Camera and Controls |
| 128 | +- **Perspective Camera**: Proper FOV and clipping planes |
| 129 | +- **Orbit Controls**: Professional interaction with damping |
| 130 | +- **Constraint Settings**: Sensible min/max distances and polar angle limits |
| 131 | + |
| 132 | +### Helper Functions |
| 133 | +- **Door Geometry**: Complex extruded geometry with cutouts |
| 134 | +- **Geometry Factories**: Optimized geometry creation for performance |
| 135 | +- **Material Factories**: Reusable material creation functions |
| 136 | + |
| 137 | +## Performance Considerations |
| 138 | + |
| 139 | +### Optimization Options |
| 140 | +1. **Geometry Optimization**: Reduces segment count by ~50% |
| 141 | +2. **Material Factories**: Enables material instance reuse |
| 142 | +3. **Geometry Factories**: Reduces memory usage through shared geometries |
| 143 | +4. **Code Minification**: Smaller file sizes for production |
| 144 | + |
| 145 | +### Estimated File Sizes |
| 146 | +- **Basic Export**: ~2-5 KB for simple scenes |
| 147 | +- **Full Featured Export**: ~8-15 KB with all options |
| 148 | +- **Large Scenes**: Scales linearly with object count |
| 149 | + |
| 150 | +## Best Practices |
| 151 | + |
| 152 | +### When to Use TypeScript |
| 153 | +- β
New projects with modern tooling |
| 154 | +- β
Projects requiring type safety |
| 155 | +- β
Team development environments |
| 156 | +- β
IDE integration and autocompletion |
| 157 | + |
| 158 | +### When to Use JavaScript |
| 159 | +- β
Legacy browser support required |
| 160 | +- β
Integration with existing JavaScript projects |
| 161 | +- β
Rapid prototyping |
| 162 | +- β
Learning and educational purposes |
| 163 | + |
| 164 | +### Module Format Selection |
| 165 | +- **ES6**: Modern browsers and bundlers (recommended) |
| 166 | +- **CommonJS**: Node.js environments and older bundlers |
| 167 | +- **UMD**: Universal compatibility and CDN usage |
| 168 | + |
| 169 | +## Migration Guide |
| 170 | + |
| 171 | +### From Old Export System |
| 172 | +The old export system generated minimal code. To migrate: |
| 173 | + |
| 174 | +1. **Replace Export Calls**: Use the new export dialog instead of direct function calls |
| 175 | +2. **Update Integration**: The new exports include complete scene setup |
| 176 | +3. **Review Dependencies**: Ensure OrbitControls import is available |
| 177 | +4. **Test Thoroughly**: The new system provides more comprehensive output |
| 178 | + |
| 179 | +### Example Migration |
| 180 | + |
| 181 | +**Old Export (Basic)**: |
| 182 | +```typescript |
| 183 | +// Old: Just geometry and basic positioning |
| 184 | +const boxGeometry = new THREE.BoxGeometry(2, 2, 2); |
| 185 | +const boxMaterial = new THREE.MeshStandardMaterial({ color: "#4f46e5" }); |
| 186 | +const box = new THREE.Mesh(boxGeometry, boxMaterial); |
| 187 | +box.position.set(0, 1, 0); |
| 188 | +scene.add(box); |
| 189 | +``` |
| 190 | + |
| 191 | +**New Export (Professional)**: |
| 192 | +```typescript |
| 193 | +// New: Complete scene with lighting, camera, controls, and optimization |
| 194 | +export function createMapScene(renderer: THREE.WebGLRenderer, config: SceneConfig = {}) { |
| 195 | + // Complete scene setup with professional lighting |
| 196 | + // Proper camera configuration and controls |
| 197 | + // Optimized materials and geometry |
| 198 | + // Full render loop and event handling |
| 199 | +} |
| 200 | +``` |
| 201 | + |
| 202 | +## Future Enhancements |
| 203 | + |
| 204 | +### Planned Features |
| 205 | +- π **Babylon.js Support**: Alternative 3D engine target |
| 206 | +- π **WebGL Raw Export**: Direct WebGL code generation |
| 207 | +- π **Animation Export**: Keyframe animation support |
| 208 | +- π **Physics Integration**: Cannon.js/Ammo.js physics export |
| 209 | +- π **Material Templates**: Pre-configured material library |
| 210 | +- π **Texture Support**: Image texture integration |
| 211 | + |
| 212 | +### Community Contributions |
| 213 | +We welcome contributions to expand the export system capabilities! |
| 214 | + |
| 215 | +## Support |
| 216 | + |
| 217 | +For issues or feature requests related to the export system, please check the main repository documentation or create an issue with the `export` label. |
0 commit comments