Skip to content

Commit bc003ef

Browse files
committed
Update validator to support VRM 1.0 for VRMC_vrm, VRMC_springBone and VRMC_material_mtoon
1 parent f5c7fdc commit bc003ef

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

lib/src/ext/VRMC_materials_mtoon/vrmc_materials_mtoon.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class VrmcMaterialsMtoon extends GltfProperty {
142142
}
143143

144144
final specVersion = getString(map, SPEC_VERSION, context,
145-
req: true, regexp: RegExp(r'^1\.0-beta$'));
145+
req: true, regexp: RegExp(r'^1\.0$'));
146146

147147
return VrmcMaterialsMtoon._(
148148
specVersion,
@@ -166,8 +166,8 @@ class VrmcMaterialsMtoon extends GltfProperty {
166166
lengthsList: const [3], def: [0, 0, 0]),
167167
getObjectFromInnerMap(
168168
map, RIM_MULTIPLY_TEXTURE, context, TextureInfo.fromMap),
169-
getFloat(map, RIM_LIGHTING_MIX_FACTOR, context, def: 0),
170-
getFloat(map, PARAMETRIC_RIM_FRESNEL_POWER_FACTOR, context, def: 1),
169+
getFloat(map, RIM_LIGHTING_MIX_FACTOR, context, min: 0.0, max: 1.0, def: 1.0),
170+
getFloat(map, PARAMETRIC_RIM_FRESNEL_POWER_FACTOR, context, min: 0.0, def: 5.0),
171171
getFloat(map, PARAMETRIC_RIM_LIFT_FACTOR, context, def: 0),
172172
getString(map, OUTLINE_WIDTH_MODE, context,
173173
list: ['none', 'worldCoordinates', 'screenCoordinates'],

lib/src/ext/VRMC_springBone/vrmc_collider.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Collider extends GltfProperty {
4545

4646
return Collider._(
4747
getIndex(map, NODE, context),
48-
getObjectFromInnerMap(map, SHAPE, context, ColliderShape.fromMap),
48+
getObjectFromInnerMap(map, SHAPE, context, ColliderShape.fromMap, req: true),
4949
getExtensions(map, Collider, context),
5050
getExtras(map, context));
5151
}
@@ -142,7 +142,7 @@ class ColliderShape extends GltfProperty {
142142

143143
if (context.validate && (hasSphere && hasCapsule) ||
144144
(!hasSphere && !hasCapsule)) {
145-
context.addIssue(SchemaError.oneOfMismatch, args: CAMERA_TYPES);
145+
context.addIssue(SchemaError.oneOfMismatch, args: COLLIDER_SHAPE_MEMBERS);
146146
}
147147

148148
return ColliderShape._(

lib/src/ext/VRMC_springBone/vrmc_spring.dart

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@ import 'package:gltf/src/ext/extensions.dart';
2424
const String NAME = 'name';
2525
const String JOINTS = 'joints';
2626
const String COLLIDER_GROUPS = 'colliderGroups';
27+
const String CENTER = 'center';
2728

2829
const List<String> SPRING_MEMBERS = <String>[
2930
NAME,
3031
JOINTS,
3132
COLLIDER_GROUPS,
33+
CENTER,
3234
];
3335

3436
class Spring extends GltfProperty {
3537
final String name;
3638
final List<Joint> joints;
3739
final List<int> _colliderGroupIndices;
40+
final int center;
3841

3942
List<ColliderGroup> _colliderGroups;
4043

41-
Spring._(this.name, this.joints, this._colliderGroupIndices,
44+
Spring._(this.name, this.joints, this._colliderGroupIndices, this.center,
4245
Map<String, Object> extensions, Object extras)
4346
: super(extensions, extras);
4447

@@ -51,6 +54,7 @@ class Spring extends GltfProperty {
5154
getString(map, NAME, context),
5255
getObjectList(map, JOINTS, context, Joint.fromMap, req: true),
5356
getIndicesList(map, COLLIDER_GROUPS, context),
57+
getIndex(map, CENTER, context, req: false),
5458
getExtensions(map, Spring, context),
5559
getExtras(map, context));
5660
}
@@ -68,6 +72,19 @@ class Spring extends GltfProperty {
6872
context.path.removeLast();
6973
}
7074

75+
if (center != -1) {
76+
context.path.add(CENTER);
77+
var node = gltf.nodes[center];
78+
if (node == null) {
79+
context.addIssue(LinkError.unresolvedReference,
80+
name: INDEX, args: [center]);
81+
} else {
82+
// Mark the center node used
83+
node.markAsUsed();
84+
}
85+
context.path.removeLast();
86+
}
87+
7188
final springBoneExtension = gltf.extensions[VRMC_SPRING_BONE];
7289
if (_colliderGroupIndices != null) {
7390
_colliderGroups =

lib/src/ext/VRMC_springBone/vrmc_spring_bone.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class VrmcSpringBone extends GltfProperty {
5252
}
5353

5454
final specVersion = getString(map, SPEC_VERSION, context,
55-
req: true, regexp: RegExp(r'^1\.0-beta$'));
55+
req: true, regexp: RegExp(r'^1\.0$'));
5656

5757
return VrmcSpringBone._(
5858
specVersion,

lib/src/ext/VRMC_vrm/vrmc_vrm.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class VrmcVrm extends GltfProperty implements ResourceValidatable {
6767
}
6868

6969
final specVersion = getString(map, SPEC_VERSION, context,
70-
req: true, regexp: RegExp(r'^1\.0-beta$'));
70+
req: true, regexp: RegExp(r'^1\.0$'));
7171

7272
final meta = getObjectFromInnerMap(map, META, context, VrmcVrmMeta.fromMap,
7373
req: true);

lib/src/ext/VRMC_vrm/vrmc_vrm_humanoid.dart

+13-13
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ const String LEFT_RING_INTERMEDIATE = 'leftRingIntermediate';
8181
const String LEFT_RING_PROXIMAL = 'leftRingProximal';
8282
const String LEFT_SHOULDER = 'leftShoulder';
8383
const String LEFT_THUMB_DISTAL = 'leftThumbDistal';
84-
const String LEFT_THUMB_INTERMEDIATE = 'leftThumbIntermediate';
8584
const String LEFT_THUMB_PROXIMAL = 'leftThumbProximal';
85+
const String LEFT_THUMB_METACARPAL = 'leftThumbMetacarpal';
8686
const String LEFT_TOES = 'leftToes';
8787
const String LEFT_UPPER_ARM = 'leftUpperArm';
8888
const String LEFT_UPPER_LEG = 'leftUpperLeg';
@@ -106,8 +106,8 @@ const String RIGHT_RING_INTERMEDIATE = 'rightRingIntermediate';
106106
const String RIGHT_RING_PROXIMAL = 'rightRingProximal';
107107
const String RIGHT_SHOULDER = 'rightShoulder';
108108
const String RIGHT_THUMB_DISTAL = 'rightThumbDistal';
109-
const String RIGHT_THUMB_INTERMEDIATE = 'rightThumbIntermediate';
110109
const String RIGHT_THUMB_PROXIMAL = 'rightThumbProximal';
110+
const String RIGHT_THUMB_METACARPAL = 'rightThumbMetacarpal';
111111
const String RIGHT_TOES = 'rightToes';
112112
const String RIGHT_UPPER_ARM = 'rightUpperArm';
113113
const String RIGHT_UPPER_LEG = 'rightUpperLeg';
@@ -138,7 +138,7 @@ const List<String> HUMAN_BONES_MEMBERS = <String>[
138138
LEFT_RING_PROXIMAL,
139139
LEFT_SHOULDER,
140140
LEFT_THUMB_DISTAL,
141-
LEFT_THUMB_INTERMEDIATE,
141+
LEFT_THUMB_METACARPAL,
142142
LEFT_THUMB_PROXIMAL,
143143
LEFT_TOES,
144144
LEFT_UPPER_ARM,
@@ -163,7 +163,7 @@ const List<String> HUMAN_BONES_MEMBERS = <String>[
163163
RIGHT_RING_PROXIMAL,
164164
RIGHT_SHOULDER,
165165
RIGHT_THUMB_DISTAL,
166-
RIGHT_THUMB_INTERMEDIATE,
166+
RIGHT_THUMB_METACARPAL,
167167
RIGHT_THUMB_PROXIMAL,
168168
RIGHT_TOES,
169169
RIGHT_UPPER_ARM,
@@ -196,8 +196,8 @@ class HumanBones {
196196
final HumanBone leftRingProximal;
197197
final HumanBone leftShoulder;
198198
final HumanBone leftThumbDistal;
199-
final HumanBone leftThumbIntermediate;
200199
final HumanBone leftThumbProximal;
200+
final HumanBone leftThumbMetacarpal;
201201
final HumanBone leftToes;
202202
final HumanBone leftUpperArm;
203203
final HumanBone leftUpperLeg;
@@ -221,8 +221,8 @@ class HumanBones {
221221
final HumanBone rightRingProximal;
222222
final HumanBone rightShoulder;
223223
final HumanBone rightThumbDistal;
224-
final HumanBone rightThumbIntermediate;
225224
final HumanBone rightThumbProximal;
225+
final HumanBone rightThumbMetacarpal;
226226
final HumanBone rightToes;
227227
final HumanBone rightUpperArm;
228228
final HumanBone rightUpperLeg;
@@ -253,8 +253,8 @@ class HumanBones {
253253
this.leftRingProximal,
254254
this.leftShoulder,
255255
this.leftThumbDistal,
256-
this.leftThumbIntermediate,
257256
this.leftThumbProximal,
257+
this.leftThumbMetacarpal,
258258
this.leftToes,
259259
this.leftUpperArm,
260260
this.leftUpperLeg,
@@ -278,8 +278,8 @@ class HumanBones {
278278
this.rightRingProximal,
279279
this.rightShoulder,
280280
this.rightThumbDistal,
281-
this.rightThumbIntermediate,
282281
this.rightThumbProximal,
282+
this.rightThumbMetacarpal,
283283
this.rightToes,
284284
this.rightUpperArm,
285285
this.rightUpperLeg,
@@ -332,10 +332,10 @@ class HumanBones {
332332
getObjectFromInnerMap(map, LEFT_SHOULDER, context, HumanBone.fromMap),
333333
getObjectFromInnerMap(
334334
map, LEFT_THUMB_DISTAL, context, HumanBone.fromMap),
335-
getObjectFromInnerMap(
336-
map, LEFT_THUMB_INTERMEDIATE, context, HumanBone.fromMap),
337335
getObjectFromInnerMap(
338336
map, LEFT_THUMB_PROXIMAL, context, HumanBone.fromMap),
337+
getObjectFromInnerMap(
338+
map, LEFT_THUMB_METACARPAL, context, HumanBone.fromMap),
339339
getObjectFromInnerMap(map, LEFT_TOES, context, HumanBone.fromMap),
340340
getObjectFromInnerMap(map, LEFT_UPPER_ARM, context, HumanBone.fromMap,
341341
req: true),
@@ -363,8 +363,8 @@ class HumanBones {
363363
getObjectFromInnerMap(map, RIGHT_RING_PROXIMAL, context, HumanBone.fromMap),
364364
getObjectFromInnerMap(map, RIGHT_SHOULDER, context, HumanBone.fromMap),
365365
getObjectFromInnerMap(map, RIGHT_THUMB_DISTAL, context, HumanBone.fromMap),
366-
getObjectFromInnerMap(map, RIGHT_THUMB_INTERMEDIATE, context, HumanBone.fromMap),
367366
getObjectFromInnerMap(map, RIGHT_THUMB_PROXIMAL, context, HumanBone.fromMap),
367+
getObjectFromInnerMap(map, RIGHT_THUMB_METACARPAL, context, HumanBone.fromMap),
368368
getObjectFromInnerMap(map, RIGHT_TOES, context, HumanBone.fromMap),
369369
getObjectFromInnerMap(map, RIGHT_UPPER_ARM, context, HumanBone.fromMap, req: true),
370370
getObjectFromInnerMap(map, RIGHT_UPPER_LEG, context, HumanBone.fromMap, req: true),
@@ -411,8 +411,8 @@ class HumanBones {
411411
linkBone(LEFT_RING_PROXIMAL, leftRingProximal);
412412
linkBone(LEFT_SHOULDER, leftShoulder);
413413
linkBone(LEFT_THUMB_DISTAL, leftThumbDistal);
414-
linkBone(LEFT_THUMB_INTERMEDIATE, leftThumbIntermediate);
415414
linkBone(LEFT_THUMB_PROXIMAL, leftThumbProximal);
415+
linkBone(LEFT_THUMB_METACARPAL, leftThumbMetacarpal);
416416
linkBone(LEFT_TOES, leftToes);
417417
linkBone(LEFT_UPPER_ARM, leftUpperArm);
418418
linkBone(LEFT_UPPER_LEG, leftUpperLeg);
@@ -436,8 +436,8 @@ class HumanBones {
436436
linkBone(RIGHT_RING_PROXIMAL, rightRingProximal);
437437
linkBone(RIGHT_SHOULDER, rightShoulder);
438438
linkBone(RIGHT_THUMB_DISTAL, rightThumbDistal);
439-
linkBone(RIGHT_THUMB_INTERMEDIATE, rightThumbIntermediate);
440439
linkBone(RIGHT_THUMB_PROXIMAL, rightThumbProximal);
440+
linkBone(RIGHT_THUMB_METACARPAL, rightThumbMetacarpal);
441441
linkBone(RIGHT_TOES, rightToes);
442442
linkBone(RIGHT_UPPER_ARM, rightUpperArm);
443443
linkBone(RIGHT_UPPER_LEG, rightUpperLeg);

lib/src/ext/VRMC_vrm/vrmc_vrm_meta.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class VrmcVrmMeta extends GltfProperty implements ResourceValidatable {
8484
final String modification;
8585
final String otherLicenseUrl;
8686

87-
Texture _thumbnailTexture;
87+
Image _thumbnailImage;
8888

8989
VrmcVrmMeta._(
9090
this.name,
@@ -155,33 +155,33 @@ class VrmcVrmMeta extends GltfProperty implements ResourceValidatable {
155155

156156
@override
157157
void link(Gltf gltf, Context context) {
158-
_thumbnailTexture = gltf.textures[_thumbnailImageIndex];
158+
_thumbnailImage = gltf.images[_thumbnailImageIndex];
159159

160160
if (context.validate && _thumbnailImageIndex != -1) {
161-
if (_thumbnailTexture == null) {
161+
if (_thumbnailImage == null) {
162162
context.addIssue(LinkError.unresolvedReference,
163-
name: INDEX, args: [_thumbnailImageIndex]);
163+
name: THUMBNAIL_IMAGE, args: [_thumbnailImageIndex]);
164164
} else {
165-
_thumbnailTexture.markAsUsed();
165+
_thumbnailImage.markAsUsed();
166166
}
167167
}
168168
}
169169

170170
@override
171171
void validateResources(Gltf gltf, Context context) {
172-
if (_thumbnailTexture == null) {
172+
if (_thumbnailImage == null) {
173173
return;
174174
}
175175

176176
const types = [IMAGE_JPEG, IMAGE_PNG];
177-
final mimeType = _thumbnailTexture.source?.info?.mimeType;
177+
final mimeType = _thumbnailImage.info?.mimeType;
178178
if (mimeType != null && !types.contains(mimeType)) {
179179
context.addIssue(SemanticError.vrm1InvalidThumbnailImageMimeType,
180180
args: [mimeType]);
181181
}
182182

183-
final width = _thumbnailTexture.source?.info?.width;
184-
final height = _thumbnailTexture.source?.info?.height;
183+
final width = _thumbnailImage.info?.width;
184+
final height = _thumbnailImage.info?.height;
185185
if (width != 1024 || height != 1024) {
186186
context.addIssue(SemanticError.vrm1NonRecommendedThumbnailResolution,
187187
args: [width, height]);

0 commit comments

Comments
 (0)