Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into release/2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicFork committed Oct 27, 2016
2 parents 3a6f7ab + 7779abd commit ec723aa
Show file tree
Hide file tree
Showing 32 changed files with 1,286 additions and 177 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
CHANGELOG
===========

## 2.3.3 ( [see diff](https://github.com/toxicFork/react-three-renderer/compare/v2.3.2...v2.3.3) )

### Components
- Added `<shapeGeometry>` ( #114 )
- Fixed a bug which would cause a crash when you changed some properties on components
whose children used ref functions
- Added `<bufferGeometry>` ( #105 #119 )

### Core
- Fixed bug which would not allow you to get a canvas reference through the `canvasRef` property in some conditions ( #115 )

## 2.3.2 ( [see diff](https://github.com/toxicFork/react-three-renderer/compare/v2.3.1...v2.3.2) )

### Docs
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Would you like to know more? [See the wiki](https://github.com/toxicFork/react-t
> Currently supported react version: `15.3.1` ( things break fast when you fly this close to the sun )
> Currently supported three version: `0.79.0` ( need to update babel config to work better with rollup )
[![Join the chat at https://gitter.im/toxicFork/react-three-renderer](https://badges.gitter.im/toxicFork/react-three-renderer.svg)](https://gitter.im/toxicFork/react-three-renderer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/toxicFork/react-three-renderer.svg)](https://travis-ci.org/toxicFork/react-three-renderer)

[![npm](https://nodei.co/npm/react-three-renderer.svg?downloads=true)](https://nodei.co/npm/react-three-renderer/)
Expand All @@ -19,7 +21,7 @@ Installation
============

```
npm install --save react react-dom three
npm install --save react@15.3.1 react-dom@15.3.1 three@0.79.0
npm install --save react-three-renderer
```

Expand Down
2 changes: 1 addition & 1 deletion docs/src/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function mockPropTypes() {
constructor(type, isRequired = false) {
this._type = type;

this._isRequired = !!isRequired;
this._isRequired = isRequired;
if (!isRequired) {
this.isRequired = new PropType(type, true);
}
Expand Down
7 changes: 6 additions & 1 deletion docs/src/internalComponentCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ module.exports = {
geometry: {
isComponent: true,
},
bufferGeometry: {
isComponent: true,
},
boxGeometry: {
isComponent: true,
},
Expand Down Expand Up @@ -241,10 +244,12 @@ module.exports = {
textGeometry: {
isComponent: true,
},
shapeGeometry: {
isComponent: true,
},
},
TODO: [
'CubeGeometry', // BoxGeometry
'ShapeGeometry', // hmmm
],
},
Shapes: {
Expand Down
24 changes: 24 additions & 0 deletions docs/src/internalComponents/bufferGeometry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import DocInfo from '../DocInfo';

class bufferGeometry extends DocInfo {
getIntro() {
return 'Creates a [THREE.BufferGeometry](http://threejs.org/docs/#Reference/Core/BufferGeometry)';
}

getDescription() {
return '';
}

getAttributesText() {
return {
name: '',
resourceId: '',
position: '',
normal: '',
color: '',
index: '',
};
}
}

module.exports = bufferGeometry;
4 changes: 2 additions & 2 deletions docs/src/internalComponents/gridHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import object3D from './object3D';

class gridHelper extends object3D {
getDescription() {
return 'Creates a [THREE.AxisHelper](https://threejs.org/docs/index.html#Reference/Extras.Helpers/GridHelper)';
getIntro() {
return 'Creates a [THREE.GridHelper](https://threejs.org/docs/index.html#Reference/Extras.Helpers/GridHelper)';
}

getAttributesText() {
Expand Down
5 changes: 3 additions & 2 deletions docs/src/internalComponents/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ class shape extends DocInfo {
}

getDescription() {
return `Place this within [[&lt;extrudeGeometry&gt;|extrudeGeometry]]
or [&lt;resources&gt;](resources).`;
return `Place this within [[&lt;extrudeGeometry&gt;|extrudeGeometry]],
[[&lt;shapeGeometry&gt;|shapeGeometry]],
or [[&lt;resources&gt;|resources]].`;
}

getAttributesText() {
Expand Down
20 changes: 20 additions & 0 deletions docs/src/internalComponents/shapeGeometry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import geometry from './geometry';

class shapeGeometry extends geometry {
getIntro() {
return 'Creates a [THREE.ShapeGeometry](https://threejs.org/docs/#Reference/Geometries/ShapeGeometry)';
}

getAttributesText() {
return {
...super.getAttributesText(),

shapes: 'Array of shapes, or a single shape THREE.Shape',
curveSegments: 'Default is 12 (not used in three.js at the moment)',
material: 'Index of the material in a material list',
UVGenerator: 'A UV generator, defaults to ExtrudeGeometry\'s WorldUVGenerator',
};
}
}

module.exports = shapeGeometry;
4 changes: 4 additions & 0 deletions src/lib/ElementDescriptorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import TextureResourceDescriptor from './descriptors/Resource/TextureResourceDes
import ShapeResourceDescriptor from './descriptors/Resource/ShapeResourceDescriptor';

import GeometryDescriptor from './descriptors/Geometry/GeometryDescriptor';
import BufferGeometryDescriptor from './descriptors/Geometry/BufferGeometryDescriptor';
import BoxGeometryDescriptor from './descriptors/Geometry/BoxGeometryDescriptor';
import SphereGeometryDescriptor from './descriptors/Geometry/SphereGeometryDescriptor';
import ParametricGeometryDescriptor from './descriptors/Geometry/ParametricGeometryDescriptor';
Expand All @@ -51,6 +52,7 @@ import ExtrudeGeometryDescriptor from './descriptors/Geometry/ExtrudeGeometryDes
import TubeGeometryDescriptor from './descriptors/Geometry/TubeGeometryDescriptor';
import DodecahedronGeometryDescriptor from './descriptors/Geometry/DodecahedronGeometryDescriptor';
import TextGeometryDescriptor from './descriptors/Geometry/TextGeometryDescriptor';
import ShapeGeometryDescriptor from './descriptors/Geometry/ShapeGeometryDescriptor';

import ShapeDescriptor from './descriptors/Geometry/Shapes/ShapeDescriptor';
import MoveToDescriptor from './descriptors/Geometry/Shapes/MoveToDescriptor';
Expand Down Expand Up @@ -126,6 +128,7 @@ class ElementDescriptorContainer {
texture: new TextureDescriptor(react3RendererInstance),

geometry: new GeometryDescriptor(react3RendererInstance),
bufferGeometry: new BufferGeometryDescriptor(react3RendererInstance),
boxGeometry: new BoxGeometryDescriptor(react3RendererInstance),
sphereGeometry: new SphereGeometryDescriptor(react3RendererInstance),
parametricGeometry: new ParametricGeometryDescriptor(react3RendererInstance),
Expand All @@ -146,6 +149,7 @@ class ElementDescriptorContainer {
tubeGeometry: new TubeGeometryDescriptor(react3RendererInstance),
dodecahedronGeometry: new DodecahedronGeometryDescriptor(react3RendererInstance),
textGeometry: new TextGeometryDescriptor(react3RendererInstance),
shapeGeometry: new ShapeGeometryDescriptor(react3RendererInstance),

shape: new ShapeDescriptor(react3RendererInstance),
moveTo: new MoveToDescriptor(react3RendererInstance),
Expand Down
32 changes: 32 additions & 0 deletions src/lib/InternalComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import emptyFunction from 'fbjs/lib/emptyFunction';
import flattenChildren from 'react/lib/flattenChildren';
import ReactCurrentOwner from 'react/lib/ReactCurrentOwner';
import ReactInstrumentation from 'react/lib/ReactInstrumentation';

import ReactElement from 'react/lib/ReactElement';
import ReactRef from 'react/lib/ReactRef';

import Flags from './React3ComponentFlags';

import ID_PROPERTY_NAME from './utils/idPropertyName';
Expand Down Expand Up @@ -574,6 +578,30 @@ class InternalComponent {
this.threeElementDescriptor.completePropertyUpdates(this._threeObject);
}

_removeAllChildRefs() {
const renderedChildren = this._renderedChildren;

if (renderedChildren) {
const renderedChildrenKeys = Object.keys(renderedChildren);

for (let i = 0; i < renderedChildrenKeys.length; ++i) {
const name = renderedChildrenKeys[i];

const renderedChild = renderedChildren[name];

if (renderedChild && renderedChild._currentElement && renderedChild._currentElement.ref) {
ReactRef.detachRefs(renderedChild, renderedChild._currentElement);

renderedChild._currentElement = ReactElement.cloneElement(renderedChild._currentElement, {
ref: null,
});
}

renderedChild._removeAllChildRefs();
}
}
}

/**
* @see ReactDOMComponent.Mixin.unmountComponent
*/
Expand All @@ -582,6 +610,10 @@ class InternalComponent {
this.threeElementDescriptor.componentWillUnmount(this._threeObject);
}

if (this._forceRemountOfComponent) {
this._removeAllChildRefs(); // prevent attaching of refs to children
}

this.unmountChildren(safely);
React3ComponentTree.uncacheMarkup(this);

Expand Down
14 changes: 14 additions & 0 deletions src/lib/React3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ class React3 extends React.Component {
this._render();
}

componentWillReceiveProps(newProps) {
const lastProps = this.props;

if (lastProps.canvasRef !== newProps.canvasRef) {
if (lastProps.canvasRef) {
lastProps.canvasRef(null);
}

if (newProps.canvasRef) {
newProps.canvasRef(this._canvas);
}
}
}

shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate;

componentDidUpdate() {
Expand Down
7 changes: 2 additions & 5 deletions src/lib/React3Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,10 @@ class React3DInstance {
}

if (contextLossExtension && this._canvas) {
this._canvas.addEventListener('webglcontextlost', () => {
// this should recreate the canvas
this._recreateCanvasCallback();
}, false);

// noinspection JSUnresolvedFunction
contextLossExtension.loseContext();

this._recreateCanvasCallback();
} else {
this._recreateCanvasCallback();
}
Expand Down
61 changes: 61 additions & 0 deletions src/lib/descriptors/Geometry/BufferGeometryDescriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import THREE from 'three';
import PropTypes from 'react/lib/ReactPropTypes';

import GeometryDescriptorBase from './GeometryDescriptorBase';
import propTypeInstanceOf from '../../utils/propTypeInstanceOf';

class BufferGeometryDescriptor extends GeometryDescriptorBase {
constructor(react3RendererInstance) {
super(react3RendererInstance);

[
'vertices',
'colors',
'faceVertexUvs',
'faces',
'dynamic',
].forEach(propName => {
this.removeProp(propName);
});

[
'position',
'normal',
'color',
].forEach(attributeName => {
this.hasProp(attributeName, {
type: PropTypes.oneOfType([
propTypeInstanceOf(THREE.BufferAttribute),
propTypeInstanceOf(THREE.InterleavedBufferAttribute),
]),
update(threeObject, attributeValue) {
if (attributeValue) {
threeObject.addAttribute(attributeName, attributeValue);
} else {
threeObject.removeAttribute(attributeName);
}
},
updateInitial: true,
default: undefined,
});
});

this.hasProp('index', {
type: PropTypes.oneOfType([
propTypeInstanceOf(THREE.BufferAttribute),
propTypeInstanceOf(THREE.InterleavedBufferAttribute),
]),
update(threeObject, attributeValue) {
threeObject.setIndex(attributeValue);
},
updateInitial: true,
default: undefined,
});
}

construct() {
return new THREE.BufferGeometry();
}
}

module.exports = BufferGeometryDescriptor;
Loading

0 comments on commit ec723aa

Please sign in to comment.