Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of Concept VRM0/VRM1 Extension #1180

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
],
"dependencies": {
"@gltf-transform/core": "^3.9.0",
"ktx-parse": "^0.6.0"
"ktx-parse": "^0.6.0",
"@pixiv/types-vrm-0.0": "2.0.6",
"@pixiv/types-vrmc-materials-mtoon-1.0": "2.0.6",
"@pixiv/types-vrmc-vrm-1.0": "2.0.6"
},
"files": [
"dist/",
Expand All @@ -46,4 +49,4 @@
"package.json"
],
"gitHead": "405359aa647acc95d47f1da9ac11cb83060ab482"
}
}
1 change: 1 addition & 0 deletions packages/extensions/src/vrm/VRM0/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const VRM0 = "VRM";
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { PropertyType as VRMPropertyType } from "../../constants.js";
import { HumanoidHumanBoneProp } from "../../humanoid-human-bone-prop.js";

export default class VRM0HumanoidHumanBoneProp extends HumanoidHumanBoneProp {
protected init(): void {
this.propertyType = VRMPropertyType.HUMANOID_HUMAN_BONE;
}
}
11 changes: 11 additions & 0 deletions packages/extensions/src/vrm/VRM0/properties/vrm0-humanoid-prop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PropertyType } from "@gltf-transform/core";
import { VRM0 as NAME } from "../constants.js";
import { HumanoidProp } from "../../humanoid-prop.js";

export default class VRM0HumanoidProp extends HumanoidProp {
protected init(): void {
this.extensionName = NAME;
this.propertyType = "VRMC_vrm.humanoid";
this.parentTypes = [PropertyType.ROOT];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PropertyType } from "@gltf-transform/core";
import MaterialMToonProp from "../../material-mtoon-prop.js";
import { VRM0 as NAME } from "../constants.js";

export default class VRM0MaterialMToonProp extends MaterialMToonProp {
protected init(): void {
this.extensionName = NAME;
this.propertyType = "VRMC_materialsMToon";
this.parentTypes = [PropertyType.MATERIAL];
}
}
11 changes: 11 additions & 0 deletions packages/extensions/src/vrm/VRM0/properties/vrm0-meta-prop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PropertyType } from "@gltf-transform/core";
import { MetaProp } from "../../meta-prop.js";
import { VRM0 as NAME } from "../constants.js";

export default class VRM0MetaProp extends MetaProp {
protected init(): void {
this.extensionName = NAME;
this.propertyType = "VRMC_vrm";
this.parentTypes = [PropertyType.ROOT];
}
}
154 changes: 154 additions & 0 deletions packages/extensions/src/vrm/VRM0/properties/vrm0-vrm-prop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import {
ExtensionProperty,
IProperty,
Nullable,
PropertyType,
} from "@gltf-transform/core";
import * as VRM0Type from "@pixiv/types-vrm-0.0";
import { VRM0 as NAME } from "../constants.js";
import VRM0MetaProp from "./vrm0-meta-prop.js";
import VRM0HumanoidProp from "./vrm0-humanoid-prop.js";

interface IVRM0Prop extends IProperty {
metaProp: VRM0MetaProp;
// specVersion?: "0.0";
exporterVersion: string;
humanoidProp: VRM0HumanoidProp;
serializedHumanoid: string;
serializedFirstPerson: string;
serializedBlendShapeMaster: string;
serializedSecondaryAnimation: string;
serializedMaterialProperties: string;
}

export default class VRM0Prop extends ExtensionProperty<IVRM0Prop> {
public static EXTENSION_NAME = NAME;
public declare extensionName: typeof NAME;
public declare propertyType: "VRM";
public declare parentTypes: [PropertyType.ROOT];

protected init(): void {
this.extensionName = NAME;
this.propertyType = "VRM";
this.parentTypes = [PropertyType.ROOT];
}

protected getDefaults(): Nullable<IVRM0Prop> {
return Object.assign(super.getDefaults() as IProperty, {
metaProp: null,
exporterVersion: "GLTF Transform",
humanoidProp: null,
serializedHumanoid: "{}",
serializedFirstPerson: "{}",
serializedBlendShapeMaster: "{}",
serializedSecondaryAnimation: "{}",
serializedMaterialProperties: "[]",
});
}

public setExporterVersion(exporterVersion: string): this {
return this.set("exporterVersion", exporterVersion);
}

public getExporterVersion() {
return this.get("exporterVersion");
}

public setMetaProp(meta: VRM0MetaProp): this {
return this.setRef("metaProp", meta);
}
public getMetaProp(): VRM0MetaProp | null {
return this.getRef("metaProp");
}

public setHumanoid(humanoid: VRM0Type.Humanoid): this {
return this.set("serializedHumanoid", JSON.stringify(humanoid));
}
public getHumanoid(): VRM0Type.Humanoid | undefined {
const serializedHumanoid = this.get("serializedHumanoid");
if (serializedHumanoid) {
return JSON.parse(serializedHumanoid) as VRM0Type.Humanoid;
}
return undefined;
}

public setHumanoidProp(humanoidProp: VRM0HumanoidProp): this {
return this.setRef("humanoidProp", humanoidProp);
}
public getHumanoidProp(): VRM0HumanoidProp | null {
return this.getRef("humanoidProp");
}

public setFirstPerson(firstPerson: VRM0Type.FirstPerson): this {
return this.set("serializedFirstPerson", JSON.stringify(firstPerson));
}

public getFirstPerson(): VRM0Type.FirstPerson | undefined {
const serializedFirstPerson = this.get("serializedFirstPerson");

if (serializedFirstPerson) {
return JSON.parse(serializedFirstPerson) as VRM0Type.FirstPerson;
}

return undefined;
}

public setBlendShapeMaster(blendShapeMaster: VRM0Type.BlendShape): this {
return this.set(
"serializedBlendShapeMaster",
JSON.stringify(blendShapeMaster)
);
}

public getBlendShapeMaster(): VRM0Type.BlendShape | undefined {
const serializedBlendShapeMaster = this.get("serializedBlendShapeMaster");

if (serializedBlendShapeMaster) {
return JSON.parse(serializedBlendShapeMaster) as VRM0Type.BlendShape;
}

return undefined;
}

public setSecondaryAnimation(
secondaryAnimation: VRM0Type.SecondaryAnimation
) {
return this.set(
"serializedSecondaryAnimation",
JSON.stringify(secondaryAnimation)
);
}

public getSecondaryAnimation(): VRM0Type.SecondaryAnimation | undefined {
const serializedSecondaryAnimation = this.get(
"serializedSecondaryAnimation"
);

if (serializedSecondaryAnimation) {
return JSON.parse(
serializedSecondaryAnimation
) as VRM0Type.SecondaryAnimation;
}

return undefined;
}

public setMaterialProperties(materialProperties: VRM0Type.Material[]): this {
return this.set(
"serializedMaterialProperties",
JSON.stringify(materialProperties)
);
}

public getMaterialProperties(): VRM0Type.Material[] | undefined {
const serializedMaterialProperties = this.get(
"serializedMaterialProperties"
);

if (serializedMaterialProperties) {
return JSON.parse(serializedMaterialProperties) as VRM0Type.Material[];
}

return undefined;
}
}
Loading