Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051------<canvas id="primitives-demo" style="width:100%;height:400px;border-radius:8px;background:#1a1a2e;display:block;"></canvas>
<script> async function init() { const THREE = await import('three') const { OrbitControls } = await import('three/examples/jsm/controls/OrbitControls.js') const { box, sphere, cylinder, cone, icosphere, torus } = await import('shapecraft') const { toThreeMesh } = await import('shapecraft/three')
const canvas = document.getElementById('primitives-demo') as HTMLCanvasElement if (!canvas) return
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true }) renderer.setSize(canvas.clientWidth, canvas.clientHeight) const scene = new THREE.Scene() scene.background = new THREE.Color(0x2a2a3a) const camera = new THREE.PerspectiveCamera(50, canvas.clientWidth / canvas.clientHeight, 0.1, 100) camera.position.set(6, 4, 8) const controls = new OrbitControls(camera, canvas) controls.target.set(3, 0.5, 0) controls.enableDamping = true controls.update()
scene.add(new THREE.HemisphereLight(0x87ceeb, 0x3a5a2a, 0.6)) const sun = new THREE.DirectionalLight(0xfff4e0, 1.2) sun.position.set(5, 8, 5) scene.add(sun)
const primitives = [ box().vertexColor('#cc8844'), sphere().vertexColor('#4488cc'), cylinder().vertexColor('#88cc44'), cone().vertexColor('#cc4488'), icosphere().vertexColor('#44ccaa'), torus().vertexColor('#aa44cc'), ] primitives.forEach((m, i) => { scene.add(toThreeMesh(m.translate(i * 1.5, 0.5, 0))) })
;(function animate() { requestAnimationFrame(animate) controls.update() renderer.render(scene, camera) })() } init()</script>