Famous / Famous/engine

Adding a camera to a scene then resizing the scene deletes all meshes from the scene

Open
#453 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.7k
Forks
249
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce


  1. Add some meshes to a `Scene`

  2. Add a `DOMElement` to the Scene (this is required for the bug to occur)

  3. Add a `Camera` to the same Scene

  4. Resize the said Scene with Scene#setScale()

  5. Observe the meshes will disappar

Isolation

Tested against:


  • v0.6.2 (hard to observe in the code example but its there)

  • v0.7.0

  • a5d7fd552505c0f2d40c4a86aa0a61950736ff16

Code Example

``` JavaScript
'use strict';

console.log(famous);
//var famous = require('famous');
var DOMElement = famous.domRenderables.DOMElement;
var FamousEngine = famous.core.FamousEngine;
var Mesh = famous.webglRenderables.Mesh;
var Color = famous.utilities.Color;
var Geometry = famous.webglGeometries.Geometry;
var Camera = famous.components.Camera;

var scene = FamousEngine.createScene();
var centeredOriginNode;

FamousEngine.init();

scene
.setSizeMode('relative', 'relative', 'absolute')
.setProportionalSize(0.7, 0.7, 0.7)
.setAbsoluteSize(1000, 1000, 500)
.setOrigin(0.5,0.5,0.5)
.setRotation(0.5,0.5,0.5)
;

centeredOriginNode =
scene.addChild()
.setSizeMode('relative','relative','relative')
.setProportionalSize(0.6,0.6,0.6)
.setAlign(0.5,0.5,0.5)
.setOrigin(0.5,0.5,0.5)
.setMountPoint(0.5,0.5,0.5)
;

var oCubeNode = addDebugCube(centeredOriginNode);
oCubeNode.setOrigin(0.5,0.5,0.5);

var oDOMElement = new DOMElement(centeredOriginNode, {properties: {'font-size':'100px', 'background-color':'#F00'}}).setContent("hello cruel world!");

setTimeout(function() {
var oCamera = new Camera(scene).setDepth(800);
oDOMElement.setContent("camera added to scene");
setTimeout(function() {
scene.setScale(0.5,0.5,0.5);
oDOMElement.setContent("scene scaled (notice we are now missing the cube mesh)");
}, 1000 * 3);
}, 1000 * 3);

function addDebugCube(parent) {

var oCube = parent.addChild().setOpacity(0.3);

// cube
var oGeometry =
new Geometry({
type: 'LINES',
buffers: [
{ name: 'a_pos', data: [
-1,-1,-1, 1,-1,-1, 1,1,-1, -1,1,-1,
-1,-1,1, 1,-1,1, 1,1,1, -1,1,1
], size: 3 },
{ name: 'indices', data: [
0,1, 1,2, 2,3, 3,0, // front face
4,5, 5,6, 6,7, 7,4, // back face
0,4, 4,7, 7,3, 3,0, // left face
1,5, 5,6, 6,2, 2,1 // right face
], size: 2 }
]});

var oMesh =
new Mesh(oCube)
.setGeometry(oGeometry)
.setBaseColor(new Color("#FFFFFF"))
;

return oCube;
};
```

Relevant code chunk

``` JavaScript
setTimeout(function() {
scene.setScale(0.5,0.5,0.5);
oDOMElement.setContent("scene scaled (notice we are now missing the cube mesh)");
}, 1000 * 3);
```

Observed Output

After one adds a wireframe cube mesh & a DOM element (correct output):
![tick1](https://cloud.githubusercontent.com/assets/9260493/8895659/2ba6ba74-3425-11e5-9e9a-c475912aeb47.png)

After then adding a camera (again correct output):
![tick2](https://cloud.githubusercontent.com/assets/9260493/8895660/3101e5b6-3425-11e5-9384-9b1125569143.png)

Finally, this is the output after scaling the scene. Notice that the wireframe cube has disappeared:
![tick3](https://cloud.githubusercontent.com/assets/9260493/8895661/33b461b2-3425-11e5-962b-3854ad920e72.png)

Expected Output

The red DOM element should be enclosed by a wireframe cube. Instead the cube has disappeared.

Workaround

Add a child node to the scene below the camera then Node#setScale() the child node instead.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.