Skip to content

Commit

Permalink
Adding a fallback to Canvas renderer when WebGL is unavailable (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed May 26, 2016
1 parent 2cd86f5 commit a032187
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/web/components/widgets/visualizer/Visualizer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import colornames from 'colornames';
import pubsub from 'pubsub-js';
import React from 'react';
import ReactDOM from 'react-dom';
import THREE from 'three';
import TrackballControls from '../../../lib/three/TrackballControls';
import { THREE, Detector } from '../../../lib/three';
import controller from '../../../lib/controller';
import Joystick from './Joystick';
import Toolbar from './Toolbar';
Expand Down Expand Up @@ -427,15 +426,20 @@ class Visualizer extends React.Component {
this.updateScene();
}
createRenderer(width, height) {
const renderer = new THREE.WebGLRenderer({
const options = {
autoClearColor: true,
antialias: true,
alpha: true
});
};
const renderer = Detector.webgl
? new THREE.WebGLRenderer(options)
: new THREE.CanvasRenderer(options);
renderer.setClearColor(new THREE.Color(colornames('white')), 1);
renderer.setSize(width, height);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
if (Detector.webgl) {
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
}
renderer.clear();

return renderer;
Expand All @@ -454,7 +458,7 @@ class Visualizer extends React.Component {
return camera;
}
createTrackballControls(object, domElement) {
const controls = new TrackballControls(object, domElement);
const controls = new THREE.TrackballControls(object, domElement);

controls.rotateSpeed = 1.0;
controls.zoomSpeed = 0.5;
Expand Down

0 comments on commit a032187

Please sign in to comment.