Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 8fcf7e2

Browse files
committed
Fix array-based serialized properties (like wrapS/wrapT) and display the appropriate enum values
1 parent 9ac320a commit 8fcf7e2

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

src/app/constants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ const ConstantTypes = {
200200
// Copy some over since the constant type is found
201201
// by property name.
202202
ConstantTypes.shadowSide = ConstantTypes.side;
203-
ConstantTypes.wrapS = ConstantTypes.wrapping;
204-
ConstantTypes.wrapT = ConstantTypes.wrapping;
205203
ConstantTypes.blendSrcAlpha = ['null', ...ConstantTypes.blendSrc];
206204
ConstantTypes.blendDstAlpha = ['null', ...ConstantTypes.blendDst];
207205
ConstantTypes.blendEquationAlpha = ['null', ...ConstantTypes.blendEquation];

src/app/data/textures.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@ const Filters = {
1515
const Wrapping = object => ({
1616
name: 'Wrapping',
1717
type: 'group',
18+
// wrapR is currently used with DataTexture3D but not serialized,
19+
// let's not display it for now.
1820
props: [{
1921
name: 'Wrap S',
20-
prop: 'wrapS',
22+
prop: 'wrap[0]',
2123
type: 'enum',
24+
enumType: 'wrapping',
2225
}, {
2326
name: 'Wrap T',
24-
prop: 'wrapT',
27+
prop: 'wrap[1]',
2528
type: 'enum',
26-
}, {
27-
name: 'Wrap R',
28-
prop: 'wrapR',
29-
type: 'enum',
30-
}].filter(p => p.prop === 'wrapR' ?
31-
object.textureType === 'DepthTexture' :
32-
true)
29+
enumType: 'wrapping',
30+
}]
3331
});
3432

3533
const Transform = {

src/app/elements/ParametersViewElement.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import GeometryTypes from '../data/geometry.js';
66
import TextureTypes from '../data/textures.js';
77
import { getEntityName } from '../utils.js';
88

9+
// https://stackoverflow.com/a/6491621
10+
const propByString = function(o, s) {
11+
s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
12+
s = s.replace(/^\./, ''); // strip a leading dot
13+
var a = s.split('.');
14+
for (var i = 0, n = a.length; i < n; ++i) {
15+
var k = a[i];
16+
if (k in o) {
17+
o = o[k];
18+
} else {
19+
return;
20+
}
21+
}
22+
return o;
23+
}
24+
925
const $onRefresh = Symbol('onRefresh');
1026
const commonProps = [{
1127
name: 'Type',
@@ -41,20 +57,12 @@ function propsToElements(entity, elements, props, entities) {
4157
</accordion-view>`);
4258
continue;
4359
} else {
44-
const { name, type, prop: propName, default: def } = prop;
45-
let path = propName.split('.');
46-
let target = entity;
47-
let key = path.shift();
48-
// Support nested properties, like 'data.attributes'
49-
while (path.length) {
50-
if (!(key in target)) {
51-
break;
52-
}
53-
target = target[key];
54-
key = path.shift();
55-
}
60+
const { name, type, prop: propName, enumType, default: def } = prop;
5661

57-
const value = (key in target ) ? target[key] : def;
62+
let value = propByString(entity, propName);
63+
if (value === undefined) {
64+
value = def;
65+
}
5866

5967
// For number/int types
6068
let min = 'min' in prop ? prop.min : -Infinity;
@@ -76,6 +84,7 @@ function propsToElements(entity, elements, props, entities) {
7684
.value="${value}"
7785
type="${type}"
7886
property="${propName}"
87+
enumType="${enumType || ''}"
7988
.min="${min}"
8089
.max="${max}"
8190
.step="${step}"

src/app/elements/values/KeyValueElement.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class KeyValueElement extends LitElement {
1515
keyName: { type: String, reflect: true, attribute: 'key-name'},
1616
value: { type: String, reflect: true },
1717
type: { type: String, reflect: true },
18+
enumType: { type: String, reflect: true },
1819
property: { type: String, reflect: true },
1920
// For number types only
2021
min: { type: Number, reflect: true },
@@ -74,7 +75,8 @@ export default class KeyValueElement extends LitElement {
7475
}
7576
break;
7677
case 'enum':
77-
valueElement = html`<enum-value .uuid="${this.uuid}" .type="${this.property}" .value="${this.value}"></enum-value>`;
78+
let enumType = this.enumType || this.property;
79+
valueElement = html`<enum-value .uuid="${this.uuid}" .type="${enumType}" .value="${this.value}"></enum-value>`;
7880
break;
7981
case 'vec2':
8082
case 'vec3':

0 commit comments

Comments
 (0)