This repository was archived by the owner on Aug 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathShapeGeometryResourceDescriptor.js
More file actions
61 lines (49 loc) · 1.5 KB
/
Copy pathShapeGeometryResourceDescriptor.js
File metadata and controls
61 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import PropTypes from 'prop-types';
import * as THREE from 'three';
import GeometryResourceDescriptor from './GeometryResourceDescriptor';
class ShapeGeometryResourceDescriptor extends GeometryResourceDescriptor {
constructor(react3RendererInstance) {
super(react3RendererInstance);
this.hasProp('type', {
type: PropTypes.oneOf([
'points',
'spacedPoints',
'shape',
]).isRequired,
update: this.triggerRemount,
default: '',
});
this.hasProp('divisions', {
type: PropTypes.number,
update: this.triggerRemount,
default: 5,
});
}
applyInitialProps(threeObject, props) {
super.applyInitialProps(threeObject, props);
threeObject.userData._divisions = props.divisions;
threeObject.userData._type = props.type;
}
applyToSlot(threeObject, parentObject, shape: THREE.Shape) {
if (!shape) {
return super.applyToSlot(threeObject, parentObject, null);
}
let geometry;
switch (threeObject.userData._type) {
case 'points':
geometry = shape.createPointsGeometry();
break;
case 'spacedPoints':
geometry = shape.createSpacedPointsGeometry(threeObject.userData._divisions);
break;
case 'shape':
// TODO shapeGeometryDescriptor
geometry = new THREE.ShapeGeometry(shape);
break;
default:
break;
}
return super.applyToSlot(threeObject, parentObject, geometry);
}
}
module.exports = ShapeGeometryResourceDescriptor;