Giter Club home page Giter Club logo

scenejs's Introduction

SceneJS

An extensible WebGL-based engine for high-detail 3D visualisation.

No longer maintained!

We now use a private and heavily-modified fork of SceneJS in the BioDigital Human. This repository is no longer being maintained, however we'll keep it around because it still works, and may still provide a useful resource for people learning WebGL and developing their own WebGL-based engines.

If you're looking for a production-ready WebGL engine for your visualization applications, try xeogl, which is based off lessons learned from SceneJS.

Building

With Grunt installed, build the snapshot binaries with:

grunt snapshot

The snapshot binaries are in api/latest and are used by the examples.

scenejs's People

Contributors

biodigital avatar geniass avatar jacquesc avatar mattc avatar mullerlele avatar nat-n avatar oyvinht avatar rehno-lindeque avatar salomonbrys avatar sascha-hendel avatar shrekshao avatar smurn avatar stepheneb avatar tsherif avatar tthmok avatar xeolabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scenejs's Issues

Fails to render: unilluminated geometry that has illuminated sibling in Chromium 5.0.363.0 (42723)

Symptoms are that first unilluminated geometry appears coloured and textured momentarily, then disappears when the second illuminated geometry appears. Works OK in Firefox Minefield 3.7a1pre.

Unilluminated geometry's fragment shader

varying vec4 vViewVertex;
varying vec3 vNormal;
varying vec3 vEyeVec;
varying vec2 vTextureCoord;
uniform sampler2D uSampler0;
uniform vec3 uMaterialEmission;
uniform vec3 uAmbient;
uniform vec3 uMaterialAmbient;
void main(void) {
vec3 emissionValue=uMaterialEmission;
vec3 ambientValue=uAmbient;
float alpha = 1.0;
float mask=1.0;
vec4 texturePos;
vec2 textureCoord=vec2(0.0,0.0);
texturePos = vec4(vTextureCoord.s, vTextureCoord.t, 1.0, 1.0);
textureCoord=texturePos.xy;
emissionValue = emissionValue * texture2D(uSampler0, vec2(textureCoord.x, 1.0 - textureCoord.y)).rgb;
vec4 colourValue = vec4(emissionValue + (ambientValue * uMaterialAmbient), 1);
gl_FragColor = colourValue;
}

Illuminated geometry's fragment shader

varying vec4 vViewVertex;
varying vec3 vNormal;
varying vec3 vEyeVec;
uniform vec3 uMaterialEmission;
uniform vec3 uAmbient;
uniform vec3 uMaterialAmbient;
uniform vec3 uMaterialDiffuse;
uniform vec3 uMaterialSpecular;
uniform float uMaterialShininess;
uniform vec3 uLightAmbient0;
uniform vec3 uLightDiffuse0;
uniform vec3 uLightSpecular0;
uniform vec4 uLightPos0;
uniform vec3 uLightSpotDir0;
uniform vec3 uLightAttenuation0;
varying vec3 vLightVec0;
varying float vLightDist0;
uniform vec3 uLightAmbient1;
uniform vec3 uLightDiffuse1;
uniform vec3 uLightSpecular1;
uniform vec4 uLightPos1;
uniform vec3 uLightSpotDir1;
uniform vec3 uLightAttenuation1;
varying vec3 vLightVec1;
varying float vLightDist1;
uniform vec3 uLightAmbient2;
uniform vec3 uLightDiffuse2;
uniform vec3 uLightSpecular2;
uniform vec4 uLightPos2;
uniform vec3 uLightSpotDir2;
uniform vec3 uLightAttenuation2;
varying vec3 vLightVec2;
varying float vLightDist2;
uniform vec3 uFogColor;
uniform float uFogDensity;
uniform float uFogStart;
uniform float uFogEnd;
void main(void) {
vec3 emissionValue=uMaterialEmission;
vec3 ambientValue=uAmbient;
float attenuation = 1.0;
vec3 diffuseValue=uMaterialDiffuse;
vec3 specularValue=uMaterialSpecular;
float shininessValue=uMaterialShininess;
float alpha = 1.0;
float mask=1.0;
vec4 texturePos;
vec2 textureCoord=vec2(0.0,0.0);
vec3 lightVec;
float dotN;
float spotFactor;
float pf;
vec3 diffuseWeighting = 0.0;
vec3 specularWeighting = 0.0;
lightVec = normalize(vLightVec0);
dotN = max(dot(vNormal, -lightVec), 0.0);
if (dotN > 0.0) {
attenuation = 1.0 / (uLightAttenuation0[0] + uLightAttenuation0[1] * vLightDist0 + uLightAttenuation0[2] * vLightDist0 * vLightDist0);
diffuseWeighting += dotN * uLightDiffuse0 * attenuation;
}
ambientValue += uLightAmbient0;
lightVec = normalize(vLightVec1);
dotN = max(dot(vNormal, -lightVec), 0.0);
if (dotN > 0.0) {
attenuation = 1.0 / (uLightAttenuation1[0] + uLightAttenuation1[1] * vLightDist1 + uLightAttenuation1[2] * vLightDist1 * vLightDist1);
diffuseWeighting += dotN * uLightDiffuse1 * attenuation;
}
ambientValue += uLightAmbient1;
lightVec = normalize(vLightVec2);
dotN = max(dot(vNormal, -lightVec), 0.0);
if (dotN > 0.0) {
attenuation = 1.0 / (uLightAttenuation2[0] + uLightAttenuation2[1] * vLightDist2 + uLightAttenuation2[2] * vLightDist2 * vLightDist2);
diffuseWeighting += dotN * uLightDiffuse2 * attenuation;
}
ambientValue += uLightAmbient2;
ambientValue /= 3;
vec4 colourValue =vec4(emissionValue + (ambientValue * uMaterialAmbient) + (diffuseWeighting * diffuseValue) + (specularWeighting * specularValue), 1);
float fogFact=1.0;
fogFact=clamp((uFogEnd - length(-vViewVertex.xyz)) / (uFogEnd - uFogStart), 0.0, 1.0);
gl_FragColor = colourValue * fogFact + vec4(uFogColor, 1) * (1.0 - fogFact);
}

Text node displays nothing

Text node in bitmap mode displays nothing. Texture image is created, but texture appears to not be applied.

Create a vectorInterpolator scene node type

Maybe something along the lines of:

vectorInterpolator({
type:"linear",
input:"alpha",
output:"position",
keys: [0.0, 0.2, 0.5, 0.7, 0.9, 1.0],
values: [
{ x: 0.0, y: 0.0, z: 0.0 },
{ x: 0.3, y: 0.0, z: 0.6 },
{ x: 3.0, y: 4.0, z: 5.5 },
{ x: 5.0, y: 0.5, z: 6.0 },
{ x: 0.4, y: 0.0, z: 0.3 }],
}

Modelling transform node optimisation - lazy insertion of matrix into shader

The super transform's matrix is reinserted into the shader every time a modelling transform node is exited during traversal. We could save on this by just lazy-inserting the current matrix held on the backend before geometry node processing, if it is not currently inserted.

Good for deeply nested transform hierarchies!

use requestAnimationFrame instead of setInterval so as to not DOS user's machine

It's going to be hard to get everyone to stop using setInterval but could you consider not using it in your SceneJS? setInterval is bad because it runs regardless of whether your app is visible. That means even in a hidden tab your WebGL app is running full speed, taking up CPU and eating battery.

Firefox, Chrome and Webkit have implemented requestAnimationFrame to solve this problem. You can use it in a cross browser way with this small snippet of JavaScript.

https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/common/webgl-utils.js

You don't have to use that snippet. you could write your own. It just seems like it would be a good idea to not propagate bad practices if possible.

Scenes with lines and triangles break if lines don't have normals.

In the latest v8.0 source, scenes that have lines and non-line primitives break if the lines don't have normals -- the non-line primitives appear not to be shaded.

Add the following to basic-scene.js (in the hello-teapot example), just before the example translation node:
{ type: "material", baseColor: { r:1 }, emit: 1,
nodes: [
{ type: "geometry", primitive:"lines",
positions: [ 0,0,0, 0,0,15, 0,15,0, 15,0,0],
normals: [ 1,0,0, 1,0,0, 1,0,0, 1,0,0 ],
indices: [0,1, 0,2, 0,3, ]
}
]
},

This works as intended: Draws the axes in red.

Remove the normals, and it breaks: The teapot is black.

Don't allow same resource ID among the geometries in a composite

Note that the resource attributes of both of these geometries share the same value, which is illegal because the inner one inherits the positions and normals of the outer. It should not try to reuse them, just inherit.

[
{
type: "geometry"
resource: "my-vbo",
positions: p
normals: normals
nodes: [
{
type: "geometry"
resource: "my-vbo",
primitive: "triangles"
indices: i[0]
}
]
}
]

Normals vectors are reversed

Koji Ligura reports:

At this page: http://scenejs.wikispaces.com/geometry, on the front face, v0's normal vector is (x,y,z)=(0, 0, -1).

Why it is not (0,0,+1)?

In SceneJS, should normal vector towards inside?

To fix:

  • reverse normals on built-in primitives
  • reverse normals in GLSL shading calculations

blendFunc fails on chrome

In chrome (both the beta and latest unstable 10.0.648.11 dev) the console gives this error:

scenejs.js:3863 gl.disable(gl.BLEND);
scenejs.js:3863 gl.blendFunc(gl.SRC_ALPHA, gl.LESS);
scenejs.js:6715 s0: WebGL error calling blendFunc on WebGL canvas context - see console log for details

Happens with both master v0.7.9 and v0.8 branches

This is a long shot, but perhaps gl.blendFunc(gl.SRC_ALPHA, gl.LESS); is illegal after gl.disable(gl.BLEND);

Interpolator bug with non-zero initial key

It looks like interpolator nodes only work properly if there is at least 1 such node that has a first key time as 0. If no interpolator with an initial key time of 0 is seen then the interpolator nodes will not switch out of the STATE_BEFORE state, never getting to the STATE_RUNNING.

An easy way to see this behaviour is to take the pouring-teapot example and remove all but 2 of the interpolator nodes. Leave only these 2 nodes, and no animation will play

{
  type: "interpolator",
  mode:"linear",
  target: "stretch",
  targetProperty: "y",
  keys: [2.0, 3.0, 4.0, 5.0],
  values: [1.0, 2.0, .3, 1.0],
  once: true
},
{
   type: "interpolator",
   mode:"linear",
   target: "stretch",
   targetProperty: "x",
   keys: [2.5, 3.5, 4.5, 5.5],
   values: [1.0, 3.0, .1, 1.0],
   once: true
}

If you change the first key from 2.0 to 0.0, then both animations will play.

Firefox 4 beta 10 breaks with the master branch

In firefox 4 beta 10 with the "master" branch (0.7.9) and the v0.8 branch:

Error: uncaught exception: SceneJS.errors.WebGLNotSupportedException: Canvas document element with ID 'gameCanvas' failed to provide a supported WebGL context
Warning: WebGL: Can't get a usable WebGL context 
Source File: file:///home/snow/projects/active/web/erased/scenejs.js Line: 6971

webgl.enabled_for_all_sites is enabled in about:config

Invisible pickable objects

If we have thin objects, they are very difficult to pick, requiring pixel perfect mouse precision. So we could define some kind of pick area, maybe a new node type, that encompasses the thin object.

Right now setting the transparent flag to true and having the alpha 0 of a material makes my object invisible but it also makes it unpickable.

Support colors for geometry vertices

For example, triangle with RGB vertices:

{
type: "geometry",
vertices: [ .. three verts ... ],
colors: [
1, 0,0, 1
0, 1, 0, 1,
0, 0, 1, 1
],
indices: [... ]
}

Node ID in "picked" event

After adding:

SceneJS.withNode("root").bind("picked", function(event) {
var params = event.params;
alert("Picked 'root' at coords " + params.canvasX + ", " + params.canvasY);
});

We know the coordinates of the mouse, but would like to know the node ID of the picked node.

Can e.g. 'params.nodeID' be added to the event?

When the event has the node ID, you only need to bind a function to the 'root' of the scene, instead of to each node you're interested in.

Text Node Exception 'Updated node without a compiler scene'

The select-teapot example shows this uncaught exception being thrown for the textures created for the text nodes being rendered. Looks like somehow the texture nodes _scene fields are set to point back to themselves rather than the actual scene.

Matrix transforms seem to be screwed

Everything else in the framework tests OK.
The previous version of SceneJS works fine.
The only area unverified in this version is the matrix transforms, so that's where the problem must lie.

Support getBoundary for subtree

Support query of the boundary of a subtree, ie. containing all the geometries within a subtree after they have been instanced by their modelling transforms.

Eg. SceneJS.withNode("my-node").getBoundary()

  • requires that boundary be cached on the query node,
  • which in requires that boundary be uncached after updates to transforms or graph topology within the subtree

SceneJS.replaceNode

Maybe like this:

SceneJS.replaceNode({
"some-node",
node: {
type: "node",
//..
}
});

Math min/max

I made the old change to use Number.MAX_VALUE and Number.MIN_VALUE what I didn't realize that Number.MIN_VALUE is actually the smallest non-zero positive number available in JavaScript (why that is useful I don't know) and not actually the smallest number available in JavaScript.

The proper MAX/MIN to use for comparison are Number.POSITIVE_INFINITY and Number.NEGATIVE_INFINITY.

Looks like this:

/** @private */
SceneJS._math_MAX_DOUBLE = Number.POSITIVE_INFINITY;
/** @private */
SceneJS._math_MIN_DOUBLE = Number.NEGATIVE_INFINITY;

Did some testing and those seem to work properly in comparisons.

Add evict() method to backends

Backends that cache things (such as geometry's VBOs, asset node etc) can have an evict() method, so that SceneJS can periodically call that across all such backends, or whenever VRAM gets full (on a GL out-of-memory error). Each backend will manage its own eviction policy.

Website V2

With sections for live examples, developer's, downloads.

Using JQuery, but with no MVC framework yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.