/** * Namespace Import Example * * Bench3D supports namespace-style imports just like Three.js: * * import * as Bench3D from 'bench3d'; * * This gives you access to everything through the Bench3D namespace. * * NOTE: This file uses relative imports for development. In a real project, * after building and installing the package, you would use: * * import * as Bench3D from 'bench3d'; */ // ✅ Single line import - everything included! // For development (before package is built): import * as Bench3D from '../src/index'; // After building/installing, use: // import * as Bench3D from 'bench3d'; // Now you can use everything through the namespace: function example() { // Create engine const canvas = document.getElementById('canvas') as HTMLCanvasElement; const engine = new Bench3D.Bench3D({ canvas: canvas, onUpdate: (event) => { console.log('Update:', event.type); } }); // Create project const project = engine.createProject({ name: 'My Project', texture_width: 16, texture_height: 16 }); // Create geometry const cube = project.addCube({ name: 'My Cube', size: [16, 16, 16] }); // Transform operations const offset: Bench3D.Vector3 = [10, 0, 0]; Bench3D.moveElements([cube], offset); const rotation: Bench3D.Vector3 = [0, 45, 0]; Bench3D.rotateElements([cube], rotation, [0, 0, 0]); // Mesh operations if (cube instanceof Bench3D.Mesh) { const faceKeys = Object.keys(cube.faces); Bench3D.extrudeFaces(cube, faceKeys, { distance: 2 }); Bench3D.loopCut(cube, 'v1', 'v2', 1); } // Animation const animation = new Bench3D.Animation({ name: 'My Animation', length: 5.0, loop: 'loop' }); project.animations.push(animation); // Texture const texture = project.addTexture({ name: 'My Texture', width: 64, height: 64 }); // Export const exporter = new Bench3D.GLTFExporter(); const gltfData = exporter.export(project, { scale: 1, binary: false, embed_textures: true }); // Import const importer = new Bench3D.GLTFImporter(); importer.import(gltfData, project, { scale: 1, importAnimations: true }); // Render engine.render(); } // ✅ You can also mix namespace and named imports // For development: import { Cube, Mesh, Vector3 } from '../src/index'; // Named imports still work! // After building/installing: // import * as Bench3D from 'bench3d'; // import { Cube, Mesh, Vector3 } from 'bench3d'; function mixedExample() { // Use namespace const engine = new Bench3D.Bench3D({ canvas: document.createElement('canvas') }); // Use named imports const cube: Cube = engine.createProject().addCube({ size: [16, 16, 16] }); const offset: Vector3 = [10, 0, 0]; } // ✅ All available through namespace: // Bench3D.Bench3D - Main engine class // Bench3D.Project - Project class // Bench3D.Cube - Cube geometry // Bench3D.Mesh - Mesh geometry // Bench3D.Group - Group container // Bench3D.Armature - Armature for skeletal animation // Bench3D.ArmatureBone - Bone class // Bench3D.Texture - Texture class // Bench3D.TextureLayer - Texture layer // Bench3D.Animation - Animation class // Bench3D.Keyframe - Keyframe class // Bench3D.Animator - Animator class // Bench3D.Vector3 - Vector3 type // Bench3D.Vector2 - Vector2 type // Bench3D.moveElements - Transform function // Bench3D.rotateElements - Transform function // Bench3D.scaleElements - Transform function // Bench3D.extrudeFaces - Mesh operation // Bench3D.loopCut - Mesh operation // Bench3D.bevelEdges - Mesh operation // Bench3D.GLTFExporter - GLTF exporter // Bench3D.GLTFImporter - GLTF importer // Bench3D.OBJExporter - OBJ exporter // Bench3D.OBJImporter - OBJ importer // Bench3D.STLExporter - STL exporter // Bench3D.STLImporter - STL importer // Bench3D.JSONExporter - JSON exporter // Bench3D.JSONImporter - JSON importer // Bench3D.ThreeRenderer - Three.js renderer // Bench3D.Renderer - Renderer interface // ... and more!