đ Creating your first scene â
This is based on the three.js - Creating a scene tutorial.
đ Setup your template â
html
<!-- Add your container element -->
<div id="three-app"></div>
<!-- Import your script as a `module` -->
<script type="module" src="/main.ts"></script>
đ¨ Add your styles â
css
#three-app {
width: 100%;
aspect-ratio: 16 / 9;
}
đ Write your awesome 3D script â
ts
import { createThreeApp } from '@slzr/three-app'
import * as THREE from 'three'
(async () => {
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshBasicMaterial({ color: 0x00FF00 })
const cube = new THREE.Mesh(geometry, material)
// Create three app instance
const threeApp = await createThreeApp({
container: document.getElementById('three-app')!,
onInit({ scene }) {
scene.add(cube) // Add objects to the scene
},
onRender() {
// Animating the cube
cube.rotation.x += 0.01
cube.rotation.y += 0.01
},
})
threeApp.start() // Start the render loop
})()
đ§ Let it rip â
And that is pretty much of it