Skip to content

Commit aa47d0e

Browse files
committed
feat: name and names prop types
1 parent 75db2a6 commit aa47d0e

File tree

67 files changed

+225
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+225
-182
lines changed

docs/property-types.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ Following list shows all property types and parsing schemas.
7171
Parsed as an array of vector2s.
7272
- ***fog***
7373
Space-separated paramaters as color, near and far, corresponding [THREE.Fog](https://threejs.org/docs/#api/en/scenes/Fog)
74+
- ***name***
75+
A string representing the component name. It must not contain any spaces.
7476
- ***names***
75-
A string or an array of string.
76-
- ***shapes***
77-
An array of vector2s or an array of
78-
[THREE.Shape](https://threejs.org/docs/#api/en/extras/core/Shape),
79-
corresponding to
80-
[THREE.ExtrudeBufferGeometry](https://threejs.org/docs/#api/en/geometries/ExtrudeBufferGeometry)
77+
Space separated strings or an array of string.

src/cameras/vgl-camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Camera, Vector3 } from 'three';
22
import VglObject3d from '../core/vgl-object3d';
33
import { parseVector3, parseSpherical } from '../parsers';
4-
import { vector3, spherical } from '../validators';
4+
import { vector3, spherical } from '../types';
55

66
/**
77
* This is abstract base component for cameras,

src/cameras/vgl-orthographic-camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OrthographicCamera } from 'three';
22
import VglCamera from './vgl-camera';
3-
import { number } from '../validators';
3+
import { number } from '../types';
44

55
/**
66
* Camera that uses orthographic projection,

src/cameras/vgl-perspective-camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PerspectiveCamera } from 'three';
22
import VglCamera from './vgl-camera';
3-
import { number } from '../validators';
3+
import { number } from '../types';
44

55
/**
66
* Camera that uses perspective projection,

src/core/vgl-geometry.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BufferGeometry, BufferAttribute } from 'three';
2-
import { string, floatArray } from '../validators';
2+
import { name, floatArray } from '../types';
3+
import { nameValidator } from '../validators';
34
import { parseArray } from '../parsers';
45

56
/**
@@ -16,7 +17,7 @@ export default {
1617
},
1718
props: {
1819
/** Name of the component. */
19-
name: string,
20+
name: { type: name, validator: nameValidator },
2021
/** The x, y, and z coordinates of each vertex in this geometry. */
2122
positionAttribute: floatArray,
2223
/** The red, green, and blue channels of vertex color of each vertex in this geometry. */
@@ -67,9 +68,9 @@ export default {
6768
},
6869
immediate: true,
6970
},
70-
name(name, oldName) {
71+
name(newName, oldName) {
7172
if (oldName !== undefined) this.vglNamespace.geometries.delete(oldName, this.inst);
72-
if (name !== undefined) this.vglNamespace.geometries.set(name, this.inst);
73+
if (newName !== undefined) this.vglNamespace.geometries.set(newName, this.inst);
7374
},
7475
positionAttribute(positionAttribute) {
7576
const positionArray = parseArray(positionAttribute);

src/core/vgl-namespace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Namespace from './namespace';
1010
* - `vglNamespace.geometries`
1111
* - `vglNamespace.materials`
1212
* - `vglNamespace.textures`
13+
* - `vglNamespace.curves`
1314
* - `vglNamespace.object3ds`
1415
*
1516
* Each namespace internally has a map of strings and objects, and has methods to access them.

src/core/vgl-object3d.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {
66
euler,
77
quaternion,
88
boolean,
9-
string,
10-
} from '../validators';
9+
name,
10+
} from '../types';
11+
import { nameValidator } from '../validators';
1112

1213
/**
1314
* This is the base mixin component for most object components in VueGL,
@@ -37,7 +38,7 @@ export default {
3738
/** Whether the material receives shadows. */
3839
receiveShadow: boolean,
3940
/** Optional name of the object. */
40-
name: string,
41+
name: { type: name, validator: nameValidator },
4142
/** Whether the object is visible. */
4243
hidden: boolean,
4344
},
@@ -93,15 +94,15 @@ export default {
9394
},
9495
parent(parent) { parent.add(this.inst); },
9596
name: [
96-
function handler(name) { this.inst.name = name; },
97+
function handler(newName) { this.inst.name = newName; },
9798
{
98-
handler(name, oldName) {
99+
handler(newName, oldName) {
99100
if (oldName !== undefined) {
100101
this.vglNamespace.object3ds.delete(oldName, this.inst);
101-
if (name === undefined) this.vglObject3d.unlisten(this.emitAsObject3d);
102+
if (newName === undefined) this.vglObject3d.unlisten(this.emitAsObject3d);
102103
}
103-
if (name !== undefined) {
104-
this.vglNamespace.object3ds.set(name, this.inst);
104+
if (newName !== undefined) {
105+
this.vglNamespace.object3ds.set(newName, this.inst);
105106
if (oldName === undefined) this.vglObject3d.listen(this.emitAsObject3d);
106107
}
107108
},

src/extras/vgl-curve-path.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import { CurvePath } from 'three';
22
import VglCurve from './vgl-curve';
3-
import { boolean } from '../validators';
3+
import { boolean } from '../types';
4+
5+
/**
6+
* An abstract base component extending VglCurve, Corresponding
7+
* [THREE.CurvePath](https://threejs.org/docs/index.html#api/extras/core/CurvePath).
8+
*
9+
* Properties of [VglCurve](vgl-curve) are also available as mixin.
10+
*/
411

512
export default {
613
mixins: [VglCurve],
714
props: {
15+
/** Whether or not to automatically close the path. */
816
autoClose: boolean,
917
},
1018
computed: {
19+
/** The THREE.CurvePath instance. */
1120
inst: () => new CurvePath(),
1221
},
1322
watch: {

src/extras/vgl-curve.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { Curve } from 'three';
2-
import { string } from '../validators';
2+
import { name } from '../types';
3+
import { nameValidator } from '../validators';
34

5+
/**
6+
* An abstract base component for representing a curve, corresponding
7+
* [THREE.Curve](https://threejs.org/docs/index.html#api/extras/core/Curve).
8+
*/
49
export default {
510
inject: {
611
vglNamespace: {
712
default() { throw new Error('VueGL components must be wraped by VglNamespace component.'); },
813
},
914
},
1015
props: {
11-
name: string,
16+
/** Name of the component. */
17+
name: { type: name, validator: nameValidator },
1218
},
1319
computed: {
20+
/** The THREE.Curve instance. */
1421
inst: () => new Curve(),
1522
},
1623
beforeDestroy() {
@@ -21,9 +28,9 @@ export default {
2128
handler(inst) { if (this.name !== undefined) this.vglNamespace.curves.set(this.name, inst); },
2229
immediate: true,
2330
},
24-
name(name, oldName) {
31+
name(newName, oldName) {
2532
if (oldName !== undefined) this.vglNamespace.curves.delete(oldName, this.inst);
26-
if (name !== undefined) this.vglNamespace.curves.set(name, this.inst);
33+
if (newName !== undefined) this.vglNamespace.curves.set(newName, this.inst);
2734
},
2835
},
2936
render(h) {

src/extras/vgl-path.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { Path } from 'three';
22
import VglCurvePath from './vgl-curve-path';
3-
import { vector2Array } from '../validators';
3+
import { vector2Array } from '../types';
44
import { parseVector2Array } from '../parsers';
55

6+
/**
7+
* A 2D path representation, Corresponding
8+
* [THREE.Path](https://threejs.org/docs/index.html#api/extras/core/Path).
9+
*
10+
* Properties of [VglCurvePath](vgl-curve-path) are also available as mixin.
11+
*/
12+
613
export default {
714
mixins: [VglCurvePath],
815
props: {
16+
/** The array of points as a LineCurve. */
917
path: vector2Array,
1018
},
1119
computed: {

0 commit comments

Comments
 (0)