Skip to content

Commit

Permalink
cleaning up example
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandojsg committed Mar 5, 2020
1 parent e628889 commit d6c3042
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions examples/webgl_geometry_cube.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
class Rotating extends Component {}

class RotationSystem extends System {
execute() {
execute(delta) {
this.queries.entities.results.forEach(entity => {
var transform = entity.getMutableComponent(Transform);
transform.rotation.x += 0.005;
transform.rotation.y += 0.01;
var rotation = entity.getMutableComponent(Transform).rotation;
rotation.x += 0.5 * delta;
rotation.y += 0.1 * delta;
});
}
}
Expand All @@ -34,15 +34,11 @@
initialize,
// Components
Parent,
SkyBox,
Camera,
Transform,
Object3D,
// Systems
CameraSystem,
SkyBoxSystem,
WebGLRendererSystem,
TransformSystem
WebGLRendererSystem
} from '../build/ecsy-three.module-unpkg.js';

var world, scene, camera, mesh, renderer;
Expand All @@ -51,29 +47,36 @@

function init() {

// Create a new world to hold all our entities and systems
world = new World();

// Register our custom sytem
world.registerSystem(RotationSystem);

// Initialize the default sets of entities and systems
let data = initialize(world);
debugger;

// Grab the initialized entities
let {scene, renderer, camera} = data.entities;

world.registerSystem(RotationSystem);

// Modify the position for the default camera
let transform = camera.getMutableComponent(Transform);
transform.position.z = 400;
transform.position.z = 40;

// Create a three.js textured box
var texture = new THREE.TextureLoader().load( 'textures/crate.gif' );
var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
var geometry = new THREE.BoxBufferGeometry( 20, 20, 20 );
var material = new THREE.MeshBasicMaterial( { map: texture } );
mesh = new THREE.Mesh( geometry, material );

// Create an entity to handle our rotating box
var rotatingBox = world.createEntity()
.addComponent(Rotating)
.addComponent(Object3D, {value: mesh})
.addComponent(Object3D, { value: mesh })
.addComponent(Transform)
.addComponent(Parent, { value: scene });
.addComponent(Parent, { value: scene })
.addComponent(Rotating);

// Let's begin
world.execute();
}
</script>
Expand Down

0 comments on commit d6c3042

Please sign in to comment.