Skip to content

Commit

Permalink
Update readme example
Browse files Browse the repository at this point in the history
  • Loading branch information
raub committed Oct 6, 2023
1 parent 51fd412 commit a843f83
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,45 @@ custom options to start with the first window and acquire all the features.

See [TypeSctipt defenitions](/index.d.ts) for more details.

Example:
Example (also see [here](/examples/crate-lean.js)):

```
const three = require('three');
const { init, addThreeHelpers } = require('3d-core-raub');
const { Screen, Brush, loop, gl } = init();
const { doc, gl, requestAnimationFrame } = init({ isGles3: true });
addThreeHelpers(three, gl);
const screen = new Screen();
loop(() => screen.draw());
const brush = new Brush({ screen, color: 0x00FF00 });
screen.on('mousemove', e => brush.pos = [e.x, e.y]);
const renderer = new three.WebGLRenderer();
renderer.setPixelRatio( doc.devicePixelRatio );
renderer.setSize( doc.innerWidth, doc.innerHeight );
const camera = new three.PerspectiveCamera(70, doc.innerWidth / doc.innerHeight, 1, 1000);
camera.position.z = 2;
const scene = new three.Scene();
const texture = new three.TextureLoader().load(__dirname + '/three/textures/crate.gif');
texture.colorSpace = three.SRGBColorSpace;
const geometry = new three.BoxGeometry();
const material = new three.MeshBasicMaterial({ map: texture });
const mesh = new three.Mesh( geometry, material );
scene.add(mesh);
doc.addEventListener('resize', () => {
camera.aspect = doc.innerWidth / doc.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(doc.innerWidth, doc.innerHeight);
});
const animate = () => {
requestAnimationFrame(animate);
const time = Date.now();
mesh.rotation.x = time * 0.0005;
mesh.rotation.y = time * 0.001;
renderer.render(scene, camera);
};
animate();
```

0 comments on commit a843f83

Please sign in to comment.