Skip to content

Commit

Permalink
Update validator to support VRM 1.0 for VRMC_vrm, VRMC_springBone and…
Browse files Browse the repository at this point in the history
… VRMC_material_mtoon
  • Loading branch information
mrxz committed Nov 7, 2024
1 parent f5c7fdc commit 663c61b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
8 changes: 5 additions & 3 deletions lib/src/ext/VRMC_materials_mtoon/vrmc_materials_mtoon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class VrmcMaterialsMtoon extends GltfProperty {
}

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

return VrmcMaterialsMtoon._(
specVersion,
Expand All @@ -166,8 +166,10 @@ class VrmcMaterialsMtoon extends GltfProperty {
lengthsList: const [3], def: [0, 0, 0]),
getObjectFromInnerMap(
map, RIM_MULTIPLY_TEXTURE, context, TextureInfo.fromMap),
getFloat(map, RIM_LIGHTING_MIX_FACTOR, context, def: 0),
getFloat(map, PARAMETRIC_RIM_FRESNEL_POWER_FACTOR, context, def: 1),
getFloat(map, RIM_LIGHTING_MIX_FACTOR, context,
min: 0.0, max: 1.0, def: 1.0),
getFloat(map, PARAMETRIC_RIM_FRESNEL_POWER_FACTOR, context,
min: 0.0, def: 5.0),
getFloat(map, PARAMETRIC_RIM_LIFT_FACTOR, context, def: 0),
getString(map, OUTLINE_WIDTH_MODE, context,
list: ['none', 'worldCoordinates', 'screenCoordinates'],
Expand Down
5 changes: 3 additions & 2 deletions lib/src/ext/VRMC_springBone/vrmc_collider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class Collider extends GltfProperty {

return Collider._(
getIndex(map, NODE, context),
getObjectFromInnerMap(map, SHAPE, context, ColliderShape.fromMap),
getObjectFromInnerMap(map, SHAPE, context, ColliderShape.fromMap,
req: true),
getExtensions(map, Collider, context),
getExtras(map, context));
}
Expand Down Expand Up @@ -142,7 +143,7 @@ class ColliderShape extends GltfProperty {

if (context.validate && (hasSphere && hasCapsule) ||
(!hasSphere && !hasCapsule)) {
context.addIssue(SchemaError.oneOfMismatch, args: CAMERA_TYPES);
context.addIssue(SchemaError.oneOfMismatch, args: COLLIDER_SHAPE_MEMBERS);
}

return ColliderShape._(
Expand Down
19 changes: 18 additions & 1 deletion lib/src/ext/VRMC_springBone/vrmc_spring.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ import 'package:gltf/src/ext/extensions.dart';
const String NAME = 'name';
const String JOINTS = 'joints';
const String COLLIDER_GROUPS = 'colliderGroups';
const String CENTER = 'center';

const List<String> SPRING_MEMBERS = <String>[
NAME,
JOINTS,
COLLIDER_GROUPS,
CENTER,
];

class Spring extends GltfProperty {
final String name;
final List<Joint> joints;
final List<int> _colliderGroupIndices;
final int center;

List<ColliderGroup> _colliderGroups;

Spring._(this.name, this.joints, this._colliderGroupIndices,
Spring._(this.name, this.joints, this._colliderGroupIndices, this.center,
Map<String, Object> extensions, Object extras)
: super(extensions, extras);

Expand All @@ -51,6 +54,7 @@ class Spring extends GltfProperty {
getString(map, NAME, context),
getObjectList(map, JOINTS, context, Joint.fromMap, req: true),
getIndicesList(map, COLLIDER_GROUPS, context),
getIndex(map, CENTER, context, req: false),
getExtensions(map, Spring, context),
getExtras(map, context));
}
Expand All @@ -68,6 +72,19 @@ class Spring extends GltfProperty {
context.path.removeLast();
}

if (center != -1) {
context.path.add(CENTER);
var node = gltf.nodes[center];
if (node == null) {
context.addIssue(LinkError.unresolvedReference,
name: INDEX, args: [center]);
} else {
// Mark the center node used
node.markAsUsed();
}
context.path.removeLast();
}

final springBoneExtension = gltf.extensions[VRMC_SPRING_BONE];
if (_colliderGroupIndices != null) {
_colliderGroups =
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ext/VRMC_springBone/vrmc_spring_bone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class VrmcSpringBone extends GltfProperty {
}

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

return VrmcSpringBone._(
specVersion,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/ext/VRMC_vrm/vrmc_vrm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class VrmcVrm extends GltfProperty implements ResourceValidatable {
}

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

final meta = getObjectFromInnerMap(map, META, context, VrmcVrmMeta.fromMap,
req: true);
Expand Down
26 changes: 13 additions & 13 deletions lib/src/ext/VRMC_vrm/vrmc_vrm_humanoid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ const String LEFT_RING_INTERMEDIATE = 'leftRingIntermediate';
const String LEFT_RING_PROXIMAL = 'leftRingProximal';
const String LEFT_SHOULDER = 'leftShoulder';
const String LEFT_THUMB_DISTAL = 'leftThumbDistal';
const String LEFT_THUMB_INTERMEDIATE = 'leftThumbIntermediate';
const String LEFT_THUMB_PROXIMAL = 'leftThumbProximal';
const String LEFT_THUMB_METACARPAL = 'leftThumbMetacarpal';
const String LEFT_TOES = 'leftToes';
const String LEFT_UPPER_ARM = 'leftUpperArm';
const String LEFT_UPPER_LEG = 'leftUpperLeg';
Expand All @@ -106,8 +106,8 @@ const String RIGHT_RING_INTERMEDIATE = 'rightRingIntermediate';
const String RIGHT_RING_PROXIMAL = 'rightRingProximal';
const String RIGHT_SHOULDER = 'rightShoulder';
const String RIGHT_THUMB_DISTAL = 'rightThumbDistal';
const String RIGHT_THUMB_INTERMEDIATE = 'rightThumbIntermediate';
const String RIGHT_THUMB_PROXIMAL = 'rightThumbProximal';
const String RIGHT_THUMB_METACARPAL = 'rightThumbMetacarpal';
const String RIGHT_TOES = 'rightToes';
const String RIGHT_UPPER_ARM = 'rightUpperArm';
const String RIGHT_UPPER_LEG = 'rightUpperLeg';
Expand Down Expand Up @@ -138,7 +138,7 @@ const List<String> HUMAN_BONES_MEMBERS = <String>[
LEFT_RING_PROXIMAL,
LEFT_SHOULDER,
LEFT_THUMB_DISTAL,
LEFT_THUMB_INTERMEDIATE,
LEFT_THUMB_METACARPAL,
LEFT_THUMB_PROXIMAL,
LEFT_TOES,
LEFT_UPPER_ARM,
Expand All @@ -163,7 +163,7 @@ const List<String> HUMAN_BONES_MEMBERS = <String>[
RIGHT_RING_PROXIMAL,
RIGHT_SHOULDER,
RIGHT_THUMB_DISTAL,
RIGHT_THUMB_INTERMEDIATE,
RIGHT_THUMB_METACARPAL,
RIGHT_THUMB_PROXIMAL,
RIGHT_TOES,
RIGHT_UPPER_ARM,
Expand Down Expand Up @@ -196,8 +196,8 @@ class HumanBones {
final HumanBone leftRingProximal;
final HumanBone leftShoulder;
final HumanBone leftThumbDistal;
final HumanBone leftThumbIntermediate;
final HumanBone leftThumbProximal;
final HumanBone leftThumbMetacarpal;
final HumanBone leftToes;
final HumanBone leftUpperArm;
final HumanBone leftUpperLeg;
Expand All @@ -221,8 +221,8 @@ class HumanBones {
final HumanBone rightRingProximal;
final HumanBone rightShoulder;
final HumanBone rightThumbDistal;
final HumanBone rightThumbIntermediate;
final HumanBone rightThumbProximal;
final HumanBone rightThumbMetacarpal;
final HumanBone rightToes;
final HumanBone rightUpperArm;
final HumanBone rightUpperLeg;
Expand Down Expand Up @@ -253,8 +253,8 @@ class HumanBones {
this.leftRingProximal,
this.leftShoulder,
this.leftThumbDistal,
this.leftThumbIntermediate,
this.leftThumbProximal,
this.leftThumbMetacarpal,
this.leftToes,
this.leftUpperArm,
this.leftUpperLeg,
Expand All @@ -278,8 +278,8 @@ class HumanBones {
this.rightRingProximal,
this.rightShoulder,
this.rightThumbDistal,
this.rightThumbIntermediate,
this.rightThumbProximal,
this.rightThumbMetacarpal,
this.rightToes,
this.rightUpperArm,
this.rightUpperLeg,
Expand Down Expand Up @@ -332,10 +332,10 @@ class HumanBones {
getObjectFromInnerMap(map, LEFT_SHOULDER, context, HumanBone.fromMap),
getObjectFromInnerMap(
map, LEFT_THUMB_DISTAL, context, HumanBone.fromMap),
getObjectFromInnerMap(
map, LEFT_THUMB_INTERMEDIATE, context, HumanBone.fromMap),
getObjectFromInnerMap(
map, LEFT_THUMB_PROXIMAL, context, HumanBone.fromMap),
getObjectFromInnerMap(
map, LEFT_THUMB_METACARPAL, context, HumanBone.fromMap),
getObjectFromInnerMap(map, LEFT_TOES, context, HumanBone.fromMap),
getObjectFromInnerMap(map, LEFT_UPPER_ARM, context, HumanBone.fromMap,
req: true),
Expand Down Expand Up @@ -363,8 +363,8 @@ class HumanBones {
getObjectFromInnerMap(map, RIGHT_RING_PROXIMAL, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_SHOULDER, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_THUMB_DISTAL, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_THUMB_INTERMEDIATE, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_THUMB_PROXIMAL, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_THUMB_METACARPAL, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_TOES, context, HumanBone.fromMap),
getObjectFromInnerMap(map, RIGHT_UPPER_ARM, context, HumanBone.fromMap, req: true),
getObjectFromInnerMap(map, RIGHT_UPPER_LEG, context, HumanBone.fromMap, req: true),
Expand Down Expand Up @@ -411,8 +411,8 @@ class HumanBones {
linkBone(LEFT_RING_PROXIMAL, leftRingProximal);
linkBone(LEFT_SHOULDER, leftShoulder);
linkBone(LEFT_THUMB_DISTAL, leftThumbDistal);
linkBone(LEFT_THUMB_INTERMEDIATE, leftThumbIntermediate);
linkBone(LEFT_THUMB_PROXIMAL, leftThumbProximal);
linkBone(LEFT_THUMB_METACARPAL, leftThumbMetacarpal);
linkBone(LEFT_TOES, leftToes);
linkBone(LEFT_UPPER_ARM, leftUpperArm);
linkBone(LEFT_UPPER_LEG, leftUpperLeg);
Expand All @@ -436,8 +436,8 @@ class HumanBones {
linkBone(RIGHT_RING_PROXIMAL, rightRingProximal);
linkBone(RIGHT_SHOULDER, rightShoulder);
linkBone(RIGHT_THUMB_DISTAL, rightThumbDistal);
linkBone(RIGHT_THUMB_INTERMEDIATE, rightThumbIntermediate);
linkBone(RIGHT_THUMB_PROXIMAL, rightThumbProximal);
linkBone(RIGHT_THUMB_METACARPAL, rightThumbMetacarpal);
linkBone(RIGHT_TOES, rightToes);
linkBone(RIGHT_UPPER_ARM, rightUpperArm);
linkBone(RIGHT_UPPER_LEG, rightUpperLeg);
Expand Down
18 changes: 9 additions & 9 deletions lib/src/ext/VRMC_vrm/vrmc_vrm_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class VrmcVrmMeta extends GltfProperty implements ResourceValidatable {
final String modification;
final String otherLicenseUrl;

Texture _thumbnailTexture;
Image _thumbnailImage;

VrmcVrmMeta._(
this.name,
Expand Down Expand Up @@ -155,33 +155,33 @@ class VrmcVrmMeta extends GltfProperty implements ResourceValidatable {

@override
void link(Gltf gltf, Context context) {
_thumbnailTexture = gltf.textures[_thumbnailImageIndex];
_thumbnailImage = gltf.images[_thumbnailImageIndex];

if (context.validate && _thumbnailImageIndex != -1) {
if (_thumbnailTexture == null) {
if (_thumbnailImage == null) {
context.addIssue(LinkError.unresolvedReference,
name: INDEX, args: [_thumbnailImageIndex]);
name: THUMBNAIL_IMAGE, args: [_thumbnailImageIndex]);
} else {
_thumbnailTexture.markAsUsed();
_thumbnailImage.markAsUsed();
}
}
}

@override
void validateResources(Gltf gltf, Context context) {
if (_thumbnailTexture == null) {
if (_thumbnailImage == null) {
return;
}

const types = [IMAGE_JPEG, IMAGE_PNG];
final mimeType = _thumbnailTexture.source?.info?.mimeType;
final mimeType = _thumbnailImage.info?.mimeType;
if (mimeType != null && !types.contains(mimeType)) {
context.addIssue(SemanticError.vrm1InvalidThumbnailImageMimeType,
args: [mimeType]);
}

final width = _thumbnailTexture.source?.info?.width;
final height = _thumbnailTexture.source?.info?.height;
final width = _thumbnailImage.info?.width;
final height = _thumbnailImage.info?.height;
if (width != 1024 || height != 1024) {
context.addIssue(SemanticError.vrm1NonRecommendedThumbnailResolution,
args: [width, height]);
Expand Down

0 comments on commit 663c61b

Please sign in to comment.