Famous / engine

MIT License
1.75k stars 250 forks source link

Adding a mesh to the scene graph by extending Node breaks in 0.7.0 #414

Open psyrendust opened 9 years ago

psyrendust commented 9 years ago

When working on my visualizer I had everything working in 0.6.2 (https://github.com/psyrendust/Vizzy/tree/feat/waves). But when doing a fresh npm installI'm getting seeing an issue in 0.7.0. I was able to get it partially working again in this branch (https://github.com/psyrendust/Vizzy/tree/bug/waves). Below are the changes I used to get things working again.

I also had to remove my background because it's placement in the scene graph is different and now cuts my plane in half only allowing you to see a small portion of the wave.

diff --git a/src/Grid.js b/src/Grid.js
index 29b1882..70450a4 100644
--- a/src/Grid.js
+++ b/src/Grid.js
@@ -53,13 +53,12 @@ const vizzyVS = Material.vizzyVS(null, {
   }
 });

-export default class Grid extends Node {
-  constructor(audio) {
-    super();
+export default class Grid {
+  constructor(node, audio) {
     // gl_PointSize = 20.0;

-
-    this
+    this.node = node;
+    this.node
       .setAlign(0.5, 0.5, 0.5)
       .setOrigin(0.5, 0.5, 0.5)
       .setMountPoint(0.5, 0.5, 0.5)
@@ -71,9 +70,9 @@ export default class Grid extends Node {
     this.clock = FamousEngine.getClock();
     this.audio = audio;

-    this.mesh = new Mesh(this);
+    this.mesh = new Mesh(this.node);
     this.geometry = new DynamicGeometry();
-    this.dragRotation = new DragRotation(this);
+    this.dragRotation = new DragRotation(this.node);

     this.plane = new Plane({
       detailY: this.audio.getData().TIMEBUFFER - 1,
diff --git a/src/index.js b/src/index.js
index ccb31e8..9db0d9d 100644
--- a/src/index.js
+++ b/src/index.js
@@ -29,12 +29,13 @@ class Background extends Node {
       .setAlign(0.5, 0.5, 0.5)
       .setOrigin(0.5, 0.5, 0.5)
       .setMountPoint(0.5, 0.5, 0.5)
-      .setProportionalSize(1, 1)
+      .setProportionalSize(1, 1, 1)
       .setPosition(0, 0, 0);
     this.opacity = new Opacity(this);
     this.opacity.set(0);
     this.el = new DOMElement(this, {
       properties: {
+        'z-index': '0',
         width: '100%',
         height: '100%',
         background: "#00b9d7",
@@ -69,10 +70,10 @@ class Vizzy {
     this.camera = new Camera(this.scene);
     this.camera.setDepth(120);
     this.root = this.scene.addChild()
-    this.background = this.root.addChild(new Background());
+    // this.background = this.root.addChild(new Background());
     this.lights = this.root.addChild(new Lights());
     this.audio = new Audio(this.root);
-    this.grid = this.root.addChild(new Grid(this.audio));
+    this.grid = new Grid(this.root.addChild(), this.audio);
     this.data = {};
     this.refreshRate = new RefreshRate(100);
     this.id = this.root.addComponent(this);
@@ -80,17 +81,17 @@ class Vizzy {
   }
   onUpdate() {
     this.data = this.audio.getData();
-    this.refreshRate.throttle(() => {
-      if (this.data.fftBufferFloat[0]) {
-        if (this.data.fftBufferFloat[0][this.data.fftSize - 8] > -90) {
-          this.background.show();
-        } else {
-          this.background.hide();
-        }
-      } else {
-        this.background.hide();
-      }
-    });
+    // this.refreshRate.throttle(() => {
+    //   if (this.data.fftBufferFloat[0]) {
+    //     if (this.data.fftBufferFloat[0][this.data.fftSize - 8] > -90) {
+    //       this.background.show();
+    //     } else {
+    //       this.background.hide();
+    //     }
+    //   } else {
+    //     this.background.hide();
+    //   }
+    // });
     this.grid.updateItems(this.data);
     this.root.requestUpdateOnNextTick(this.id);
   }