From 9a5c3f57b76bbb3176705f5fc38091bea152e970 Mon Sep 17 00:00:00 2001 From: 0reo Date: Fri, 4 Mar 2022 16:20:52 -0500 Subject: [PATCH 01/14] vrm template makes and stores toon materials --- type_templates/vrm.js | 148 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 7 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index a7874ca..ff67704 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; import metaversefile from 'metaversefile'; import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer } = metaversefile; +const {useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, getGfxSettingJSON} = metaversefile; const localVector = new THREE.Vector3(); const localVector2 = new THREE.Vector3(); @@ -77,15 +77,103 @@ const _addAnisotropy = (o, anisotropyLevel) => { }); }; +const _setQuality = async (quality, app)=> { + const skinnedVrms = app.skinnedVrms; + const baseVrm = skinnedVrms.base; + + const _swapMaterials = async (type) => { + + //actually do the swap + switch (type) { + case "toon": { + const target = skinnedVrms.toon ?? skinnedVrms.base; + + let update = Object.keys(app.materials.toon).length > 0; + + skinnedVrms.base.scene.traverse((object) => { + if (object.material && app.isBasic(object.material)) { + const name = object.material.name; + app.setMaterial(name, 'base', object.material); + update && (object.material = [app.materials.toon[name]]); + } + + }); + break; + + } + default: { + let update = false; + const target = skinnedVrms.base; + target.scene.traverse((object) => { + if (!update && object.material && app.isToon(object.material)) { + update = true; + } + }); + + target.scene.traverse((object) => { + if (object.material && app.isToon(object.material)) { + const name = object.material[0].name; + update && app.setMaterial(name, 'toon', object.material[0]); + + object.material = app.materials.base[name]; + } + }); + } + } + } + + switch (quality) { + case 'LOW': + case 'MEDIUM': + case 'HIGH': { + await _swapMaterials(); + baseVrm.scene.name = "base mesh" + app.setActive('base'); + break; + } + case 'ULTRA': { + if (skinnedVrms.toon){ + + } else { + if (!skinnedVrms.toon) { + + await _toonShaderify(baseVrm); + skinnedVrms['toon'] = baseVrm; + skinnedVrms.toon.scene.name = 'base-tooned'; + } + } + + await _swapMaterials("toon"); + app.setActive('toon'); + break; + } + default: { + throw new Error('unknown avatar quality: ' + quality); + } + } + return app.getActive(); +} export default e => { const physics = usePhysics(); const app = useApp(); app.appType = 'vrm'; + app.active = 'base'; - const srcUrl = ${ this.srcUrl }; - for (const { key, value } of components) { + //make sure we have materials to work with + app.materials = { + toon: {}, + base: {} + }; + app.isToon = material => material[0] && material[0].isMToonMaterial; + app.isBasic = material => material.type == "MeshBasicMaterial" && material.name; //we're only changing named materials + app.setMaterial = (name, type, material) => app.materials[type][name] = material; + + app.skinnedVrms = {}; + + const srcUrl = ${this.srcUrl}; + for (const {key, value} of components) { app.setComponent(key, value); } @@ -93,26 +181,54 @@ export default e => { const _cloneVrm = async () => { const vrm = await parseVrm(arrayBuffer, srcUrl); vrm.cloneVrm = _cloneVrm; + vrm.toonShaderify = _toonShaderify; return vrm; }; const _prepVrm = (vrm) => { - //vrm.visible = false; //will need later + vrm.visible = false; app.add(vrm); vrm.updateMatrixWorld(); _addAnisotropy(vrm, 16); } + app.getActive = (_app = false) => { + //return scene if we have an active vrm and we're not requesting the scene. else return the(possibly) active vrm + return app.skinnedVrms[app.active] && !_app ? app.skinnedVrms[app.active].scene : app.skinnedVrms[app.active]; + } + + // use this to change which mesh we're using + app.setActive = (target) => { + for (const key in app.skinnedVrms) { + if (Object.hasOwnProperty.call(app.skinnedVrms, key)) { + app.skinnedVrms[key].scene.visible = false + } + } + + app.active = target; + !app.getActive().parent && _prepVrm(app.getActive()); + app.getActive().visible = true; + } + let physicsIds = []; let activateCb = null; e.waitUntil((async () => { arrayBuffer = await _fetchArrayBuffer(srcUrl); const skinnedVrmBase = await _cloneVrm(); - app.skinnedVrm = skinnedVrmBase; - await _toonShaderify(skinnedVrmBase); + app.skinnedVrms['base'] = skinnedVrmBase; + app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated _prepVrm(skinnedVrmBase.scene); - + app.skinnedVrms.base.scene.name = 'base mesh'; + //collect basic materials for reuse + app.skinnedVrms.base.scene.traverse((o) => { + if (o.material && app.isBasic(o.material)) { + const name = o.material.name; + app.setMaterial(name, 'base', o.material); + } + }); + + const _addPhysics = () => { const fakeHeight = 1.5; localMatrix.compose( @@ -144,7 +260,25 @@ export default e => { localPlayer.setAvatarApp(app); }; + const quality = getGfxSettingJSON('character').details; + await _setQuality(quality, app) + + app.updateQuality = async () => { + const quality = getGfxSettingJSON('character').details; + return await _setQuality(quality, app) + } + + //prep any outstanding meshes + //may not need this yet + for (const type in app.skinnedVrms) { + if (type !== 'base' && Object.hasOwnProperty.call(app.skinnedVrms, type)) { + const vrm = app.skinnedVrms[type]; + vrm && _prepVrm(vrm.isMesh ? vrm : vrm.scene); + } + } + })()); + useActivate(() => { activateCb && activateCb(); From 799327687a2d067411a2ee212b32367217c18d80 Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 10 Mar 2022 22:03:33 -0500 Subject: [PATCH 02/14] read quality from localstorage --- type_templates/vrm.js | 61 ++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index ff67704..7f4ae21 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; import metaversefile from 'metaversefile'; import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const {useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, getGfxSettingJSON} = metaversefile; +const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, /* getGfxSettingJSON */ } = metaversefile; const localVector = new THREE.Vector3(); const localVector2 = new THREE.Vector3(); @@ -77,29 +77,29 @@ const _addAnisotropy = (o, anisotropyLevel) => { }); }; -const _setQuality = async (quality, app)=> { +const _setQuality = async (quality, app) => { const skinnedVrms = app.skinnedVrms; const baseVrm = skinnedVrms.base; - + const _swapMaterials = async (type) => { - + //actually do the swap switch (type) { case "toon": { const target = skinnedVrms.toon ?? skinnedVrms.base; - + let update = Object.keys(app.materials.toon).length > 0; - + skinnedVrms.base.scene.traverse((object) => { if (object.material && app.isBasic(object.material)) { const name = object.material.name; app.setMaterial(name, 'base', object.material); update && (object.material = [app.materials.toon[name]]); } - + }); break; - + } default: { let update = false; @@ -109,12 +109,12 @@ const _setQuality = async (quality, app)=> { update = true; } }); - + target.scene.traverse((object) => { if (object.material && app.isToon(object.material)) { const name = object.material[0].name; update && app.setMaterial(name, 'toon', object.material[0]); - + object.material = app.materials.base[name]; } }); @@ -122,7 +122,7 @@ const _setQuality = async (quality, app)=> { } } - switch (quality) { + switch (quality ?? 'MEDIUM') { case 'LOW': case 'MEDIUM': case 'HIGH': { @@ -132,7 +132,7 @@ const _setQuality = async (quality, app)=> { break; } case 'ULTRA': { - if (skinnedVrms.toon){ + if (skinnedVrms.toon) { } else { if (!skinnedVrms.toon) { @@ -151,7 +151,7 @@ const _setQuality = async (quality, app)=> { throw new Error('unknown avatar quality: ' + quality); } } - return app.getActive(); + return app.getActive(); } export default e => { @@ -169,11 +169,11 @@ export default e => { app.isToon = material => material[0] && material[0].isMToonMaterial; app.isBasic = material => material.type == "MeshBasicMaterial" && material.name; //we're only changing named materials app.setMaterial = (name, type, material) => app.materials[type][name] = material; - + app.skinnedVrms = {}; - - const srcUrl = ${this.srcUrl}; - for (const {key, value} of components) { + + const srcUrl = ${ this.srcUrl }; + for (const { key, value } of components) { app.setComponent(key, value); } @@ -196,7 +196,7 @@ export default e => { //return scene if we have an active vrm and we're not requesting the scene. else return the(possibly) active vrm return app.skinnedVrms[app.active] && !_app ? app.skinnedVrms[app.active].scene : app.skinnedVrms[app.active]; } - + // use this to change which mesh we're using app.setActive = (target) => { for (const key in app.skinnedVrms) { @@ -204,12 +204,12 @@ export default e => { app.skinnedVrms[key].scene.visible = false } } - + app.active = target; !app.getActive().parent && _prepVrm(app.getActive()); app.getActive().visible = true; } - + let physicsIds = []; let activateCb = null; e.waitUntil((async () => { @@ -226,9 +226,9 @@ export default e => { const name = o.material.name; app.setMaterial(name, 'base', o.material); } - }); - - + }); + + const _addPhysics = () => { const fakeHeight = 1.5; localMatrix.compose( @@ -260,14 +260,15 @@ export default e => { localPlayer.setAvatarApp(app); }; - const quality = getGfxSettingJSON('character').details; - await _setQuality(quality, app) - app.updateQuality = async () => { - const quality = getGfxSettingJSON('character').details; - return await _setQuality(quality, app) + // const quality = getGfxSettingJSON('character').details; + // return await _setQuality(quality, app) + const quality = JSON.parse(localStorage.getItem('GfxSettings')); + return await _setQuality(quality?.character.details, app) } - + + await app.updateQuality(); + //prep any outstanding meshes //may not need this yet for (const type in app.skinnedVrms) { @@ -278,7 +279,7 @@ export default e => { } })()); - + useActivate(() => { activateCb && activateCb(); From bdfa7fc4e9557046bbf4a68a263f65bd8a8d7a2d Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Thu, 10 Mar 2022 22:17:06 -0500 Subject: [PATCH 03/14] remove unused target reference --- type_templates/vrm.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 7f4ae21..bab757c 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -86,7 +86,6 @@ const _setQuality = async (quality, app) => { //actually do the swap switch (type) { case "toon": { - const target = skinnedVrms.toon ?? skinnedVrms.base; let update = Object.keys(app.materials.toon).length > 0; @@ -324,4 +323,4 @@ export default e => { export const contentId = ${ this.contentId }; export const name = ${ this.name }; export const description = ${ this.description }; -export const components = ${ this.components }; \ No newline at end of file +export const components = ${ this.components }; From 8f8e23a53fa1067d70e08e43cfc0a95a9c5b899d Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 10 Mar 2022 22:22:36 -0500 Subject: [PATCH 04/14] generate and store crunched vrms --- type_templates/vrm.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index bab757c..2d3fe7e 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; import metaversefile from 'metaversefile'; import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, /* getGfxSettingJSON */ } = metaversefile; +const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useAvatarCruncher, /* getGfxSettingJSON */ } = metaversefile; const localVector = new THREE.Vector3(); const localVector2 = new THREE.Vector3(); @@ -49,6 +49,9 @@ const parseVrm = (arrayBuffer, srcUrl) => new Promise((accept, reject) => { }); return result; }; */ +const _crunch = async o => { + return useAvatarCruncher().crunchAvatarModel(o); +}; const _toonShaderify = async o => { await new VRMMaterialImporter().convertGLTFMaterials(o); }; @@ -123,7 +126,18 @@ const _setQuality = async (quality, app) => { switch (quality ?? 'MEDIUM') { case 'LOW': - case 'MEDIUM': + case 'MEDIUM': { + if (skinnedVrms.crunched) { + if (skinnedVrms.crunched.scene.name !== "crunched") { + await skinnedVrms.crunched.makeCrunched(skinnedVrms.base); + } + } else { + throw new Error('something went wrong, missing crunched avatar'); + } + app.setActive('crunched'); + + break; + } case 'HIGH': { await _swapMaterials(); baseVrm.scene.name = "base mesh" @@ -227,6 +241,21 @@ export default e => { } }); + app.skinnedVrms['base'].makeCrunched = async (src) => { + if (src.scene.name == "crunched") return src.scene; + //we always need the crunched avatar + const skinnedVrmCrunched = await _crunch(src.scene); + skinnedVrmCrunched.name = 'crunched'; + _prepVrm(skinnedVrmCrunched) + let tmpVrms = { ...app.skinnedVrms }; + delete tmpVrms.crunched; + tmpVrms.crunched = { ...src }; + tmpVrms.crunched.scene = skinnedVrmCrunched; + app.skinnedVrms = tmpVrms; + return skinnedVrmCrunched; + } + + app.skinnedVrms['crunched'] = app.skinnedVrms['base']; const _addPhysics = () => { const fakeHeight = 1.5; From be6500578da99a5efc05d78814801fc2965ce36e Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 24 Mar 2022 17:40:24 -0400 Subject: [PATCH 05/14] get graphics settings from settings manager --- type_templates/vrm.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 2d3fe7e..e3e39d0 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; import metaversefile from 'metaversefile'; import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useAvatarCruncher, /* getGfxSettingJSON */ } = metaversefile; +const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useSettingsManager } = metaversefile; const localVector = new THREE.Vector3(); const localVector2 = new THREE.Vector3(); @@ -289,10 +289,9 @@ export default e => { }; app.updateQuality = async () => { - // const quality = getGfxSettingJSON('character').details; - // return await _setQuality(quality, app) - const quality = JSON.parse(localStorage.getItem('GfxSettings')); - return await _setQuality(quality?.character.details, app) + const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); + const quality = gfxSettings.character.details; + return await _setQuality(quality, app) } await app.updateQuality(); From b5d3d21d999e5af26813260cd49ded7901558017 Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 24 Mar 2022 17:41:04 -0400 Subject: [PATCH 06/14] remove premptive prep calls --- type_templates/vrm.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index e3e39d0..41ed422 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -219,7 +219,7 @@ export default e => { } app.active = target; - !app.getActive().parent && _prepVrm(app.getActive()); + !app.getActive().parent && _prepVrm(app.getActive()); app.getActive().visible = true; } @@ -296,14 +296,6 @@ export default e => { await app.updateQuality(); - //prep any outstanding meshes - //may not need this yet - for (const type in app.skinnedVrms) { - if (type !== 'base' && Object.hasOwnProperty.call(app.skinnedVrms, type)) { - const vrm = app.skinnedVrms[type]; - vrm && _prepVrm(vrm.isMesh ? vrm : vrm.scene); - } - } })()); From f5c0cff77f7407d5b4df432b26f65316f8c3c95d Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 24 Mar 2022 17:59:09 -0400 Subject: [PATCH 07/14] remove toon code --- type_templates/vrm.js | 72 +------------------------------------------ 1 file changed, 1 insertion(+), 71 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 41ed422..36ac5f6 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -84,46 +84,6 @@ const _setQuality = async (quality, app) => { const skinnedVrms = app.skinnedVrms; const baseVrm = skinnedVrms.base; - const _swapMaterials = async (type) => { - - //actually do the swap - switch (type) { - case "toon": { - - let update = Object.keys(app.materials.toon).length > 0; - - skinnedVrms.base.scene.traverse((object) => { - if (object.material && app.isBasic(object.material)) { - const name = object.material.name; - app.setMaterial(name, 'base', object.material); - update && (object.material = [app.materials.toon[name]]); - } - - }); - break; - - } - default: { - let update = false; - const target = skinnedVrms.base; - target.scene.traverse((object) => { - if (!update && object.material && app.isToon(object.material)) { - update = true; - } - }); - - target.scene.traverse((object) => { - if (object.material && app.isToon(object.material)) { - const name = object.material[0].name; - update && app.setMaterial(name, 'toon', object.material[0]); - - object.material = app.materials.base[name]; - } - }); - } - } - } - switch (quality ?? 'MEDIUM') { case 'LOW': case 'MEDIUM': { @@ -139,25 +99,12 @@ const _setQuality = async (quality, app) => { break; } case 'HIGH': { - await _swapMaterials(); baseVrm.scene.name = "base mesh" app.setActive('base'); break; } case 'ULTRA': { - if (skinnedVrms.toon) { - - } else { - if (!skinnedVrms.toon) { - - await _toonShaderify(baseVrm); - skinnedVrms['toon'] = baseVrm; - skinnedVrms.toon.scene.name = 'base-tooned'; - } - } - - await _swapMaterials("toon"); - app.setActive('toon'); + console.log('not implimented'); break; } default: { @@ -174,15 +121,6 @@ export default e => { app.appType = 'vrm'; app.active = 'base'; - //make sure we have materials to work with - app.materials = { - toon: {}, - base: {} - }; - app.isToon = material => material[0] && material[0].isMToonMaterial; - app.isBasic = material => material.type == "MeshBasicMaterial" && material.name; //we're only changing named materials - app.setMaterial = (name, type, material) => app.materials[type][name] = material; - app.skinnedVrms = {}; const srcUrl = ${ this.srcUrl }; @@ -194,7 +132,6 @@ export default e => { const _cloneVrm = async () => { const vrm = await parseVrm(arrayBuffer, srcUrl); vrm.cloneVrm = _cloneVrm; - vrm.toonShaderify = _toonShaderify; return vrm; }; @@ -233,13 +170,6 @@ export default e => { app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated _prepVrm(skinnedVrmBase.scene); app.skinnedVrms.base.scene.name = 'base mesh'; - //collect basic materials for reuse - app.skinnedVrms.base.scene.traverse((o) => { - if (o.material && app.isBasic(o.material)) { - const name = o.material.name; - app.setMaterial(name, 'base', o.material); - } - }); app.skinnedVrms['base'].makeCrunched = async (src) => { if (src.scene.name == "crunched") return src.scene; From 5ee54752aa9ee67bbe32e48fa59c12dbd0abe97e Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 24 Mar 2022 18:05:59 -0400 Subject: [PATCH 08/14] readd useAvatarCruncher --- type_templates/vrm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 36ac5f6..8456577 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,7 +1,7 @@ import * as THREE from 'three'; import metaversefile from 'metaversefile'; import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useSettingsManager } = metaversefile; +const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useAvatarCruncher, useSettingsManager } = metaversefile; const localVector = new THREE.Vector3(); const localVector2 = new THREE.Vector3(); From 910b403090b466eaf9e6ce830630cd91dfaa4c4f Mon Sep 17 00:00:00 2001 From: 0reo Date: Thu, 24 Mar 2022 18:30:48 -0400 Subject: [PATCH 09/14] rename active to current, make skinnedVrms internal --- type_templates/vrm.js | 51 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 8456577..c4433f9 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -80,8 +80,8 @@ const _addAnisotropy = (o, anisotropyLevel) => { }); }; -const _setQuality = async (quality, app) => { - const skinnedVrms = app.skinnedVrms; +const _setQuality = async (quality, app, skinnedVrms) => { + const baseVrm = skinnedVrms.base; switch (quality ?? 'MEDIUM') { @@ -94,13 +94,13 @@ const _setQuality = async (quality, app) => { } else { throw new Error('something went wrong, missing crunched avatar'); } - app.setActive('crunched'); + app.setCurrent('crunched'); break; } case 'HIGH': { baseVrm.scene.name = "base mesh" - app.setActive('base'); + app.setCurrent('base'); break; } case 'ULTRA': { @@ -111,7 +111,7 @@ const _setQuality = async (quality, app) => { throw new Error('unknown avatar quality: ' + quality); } } - return app.getActive(); + return app.getCurrentVrm().scene; } export default e => { @@ -119,9 +119,9 @@ export default e => { const app = useApp(); app.appType = 'vrm'; - app.active = 'base'; + app.current = 'base'; - app.skinnedVrms = {}; + let skinnedVrms = {}; const srcUrl = ${ this.srcUrl }; for (const { key, value } of components) { @@ -142,22 +142,23 @@ export default e => { _addAnisotropy(vrm, 16); } - app.getActive = (_app = false) => { - //return scene if we have an active vrm and we're not requesting the scene. else return the(possibly) active vrm - return app.skinnedVrms[app.active] && !_app ? app.skinnedVrms[app.active].scene : app.skinnedVrms[app.active]; + app.getCurrentVrm = () => { + //return scene if we have an current vrm and we're not requesting the scene. else return the(possibly) current vrm + return skinnedVrms[app.current] && skinnedVrms[app.current]; } // use this to change which mesh we're using - app.setActive = (target) => { - for (const key in app.skinnedVrms) { - if (Object.hasOwnProperty.call(app.skinnedVrms, key)) { - app.skinnedVrms[key].scene.visible = false + app.setCurrent = (target) => { + for (const key in skinnedVrms) { + if (Object.hasOwnProperty.call(skinnedVrms, key)) { + skinnedVrms[key].scene.visible = false } } - app.active = target; - !app.getActive().parent && _prepVrm(app.getActive()); - app.getActive().visible = true; + app.current = target; + //if this app's scene has no parent, then it's never been prepped. prep it now + !app.getCurrentVrm().scene.parent && _prepVrm(app.getCurrentVrm().scene); + app.getCurrentVrm().scene.visible = true; } let physicsIds = []; @@ -166,26 +167,26 @@ export default e => { arrayBuffer = await _fetchArrayBuffer(srcUrl); const skinnedVrmBase = await _cloneVrm(); - app.skinnedVrms['base'] = skinnedVrmBase; + skinnedVrms['base'] = skinnedVrmBase; app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated _prepVrm(skinnedVrmBase.scene); - app.skinnedVrms.base.scene.name = 'base mesh'; + skinnedVrms.base.scene.name = 'base mesh'; - app.skinnedVrms['base'].makeCrunched = async (src) => { + skinnedVrms['base'].makeCrunched = async (src) => { if (src.scene.name == "crunched") return src.scene; //we always need the crunched avatar const skinnedVrmCrunched = await _crunch(src.scene); skinnedVrmCrunched.name = 'crunched'; _prepVrm(skinnedVrmCrunched) - let tmpVrms = { ...app.skinnedVrms }; + let tmpVrms = { ...skinnedVrms }; delete tmpVrms.crunched; tmpVrms.crunched = { ...src }; tmpVrms.crunched.scene = skinnedVrmCrunched; - app.skinnedVrms = tmpVrms; + skinnedVrms = tmpVrms; return skinnedVrmCrunched; } - app.skinnedVrms['crunched'] = app.skinnedVrms['base']; + skinnedVrms['crunched'] = skinnedVrms['base']; const _addPhysics = () => { const fakeHeight = 1.5; @@ -221,7 +222,7 @@ export default e => { app.updateQuality = async () => { const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); const quality = gfxSettings.character.details; - return await _setQuality(quality, app) + return await _setQuality(quality, app, skinnedVrms) } await app.updateQuality(); @@ -246,7 +247,7 @@ export default e => { app.toggleBoneUpdates = update => { - const scene = app.skinnedVrm.scene; + const {scene} = skinnedVrms.base; scene.traverse(o => { // o.matrixAutoUpdate = update; if (o.isBone) o.matrixAutoUpdate = update; From 300d291125a6df2c8d99bb6b0339e3a1e6f8f252 Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Sat, 26 Mar 2022 17:49:17 -0400 Subject: [PATCH 10/14] remove toon ref --- type_templates/vrm.js | 551 +++++++++++++++++++++--------------------- 1 file changed, 274 insertions(+), 277 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index c4433f9..9ddfd30 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -1,277 +1,274 @@ -import * as THREE from 'three'; -import metaversefile from 'metaversefile'; -import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; -const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useAvatarCruncher, useSettingsManager } = metaversefile; - -const localVector = new THREE.Vector3(); -const localVector2 = new THREE.Vector3(); -const localQuaternion = new THREE.Quaternion(); -const localMatrix = new THREE.Matrix4(); -// const q180 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI); - -const _fetchArrayBuffer = async srcUrl => { - const res = await fetch(srcUrl); - if (res.ok) { - const arrayBuffer = await res.arrayBuffer(); - return arrayBuffer; - } else { - throw new Error('failed to load: ' + res.status + ' ' + srcUrl); - } -}; -/* const loadVrm = async (srcUrl) => { - let vrmObject; - try { - const res = await fetch(srcUrl); - if (res.ok) { - const arrayBuffer = await res.arrayBuffer(); - vrmObject = await parseVrm(arrayBuffer, srcUrl); - vrmObject.arrayBuffer = arrayBuffer; - // startMonetization(instanceId, monetizationPointer, ownerAddress); - } else { - throw new Error('failed to load: ' + res.status + ' ' + srcUrl); - } - } catch(err) { - console.warn(err); - vrmObject = null; - } - return vrmObject; -}; */ -const parseVrm = (arrayBuffer, srcUrl) => new Promise((accept, reject) => { - const { gltfLoader } = useLoaders(); - gltfLoader.parse(arrayBuffer, srcUrl, accept, reject); -}); -/* const _findMaterialsObjects = (o, name) => { - const result = []; - o.traverse(o => { - if (o.isMesh && o.material.name === name) { - result.push(o); - } - }); - return result; -}; */ -const _crunch = async o => { - return useAvatarCruncher().crunchAvatarModel(o); -}; -const _toonShaderify = async o => { - await new VRMMaterialImporter().convertGLTFMaterials(o); -}; -const mapTypes = [ - 'alphaMap', - 'aoMap', - 'bumpMap', - 'displacementMap', - 'emissiveMap', - 'envMap', - 'lightMap', - 'map', - 'metalnessMap', - 'normalMap', - 'roughnessMap', -]; -const _addAnisotropy = (o, anisotropyLevel) => { - o.traverse(o => { - if (o.isMesh) { - for (const mapType of mapTypes) { - if (o.material[mapType]) { - o.material[mapType].anisotropy = anisotropyLevel; - } - } - } - }); -}; - -const _setQuality = async (quality, app, skinnedVrms) => { - - const baseVrm = skinnedVrms.base; - - switch (quality ?? 'MEDIUM') { - case 'LOW': - case 'MEDIUM': { - if (skinnedVrms.crunched) { - if (skinnedVrms.crunched.scene.name !== "crunched") { - await skinnedVrms.crunched.makeCrunched(skinnedVrms.base); - } - } else { - throw new Error('something went wrong, missing crunched avatar'); - } - app.setCurrent('crunched'); - - break; - } - case 'HIGH': { - baseVrm.scene.name = "base mesh" - app.setCurrent('base'); - break; - } - case 'ULTRA': { - console.log('not implimented'); - break; - } - default: { - throw new Error('unknown avatar quality: ' + quality); - } - } - return app.getCurrentVrm().scene; -} - -export default e => { - const physics = usePhysics(); - - const app = useApp(); - app.appType = 'vrm'; - app.current = 'base'; - - let skinnedVrms = {}; - - const srcUrl = ${ this.srcUrl }; - for (const { key, value } of components) { - app.setComponent(key, value); - } - - let arrayBuffer = null; - const _cloneVrm = async () => { - const vrm = await parseVrm(arrayBuffer, srcUrl); - vrm.cloneVrm = _cloneVrm; - return vrm; - }; - - const _prepVrm = (vrm) => { - vrm.visible = false; - app.add(vrm); - vrm.updateMatrixWorld(); - _addAnisotropy(vrm, 16); - } - - app.getCurrentVrm = () => { - //return scene if we have an current vrm and we're not requesting the scene. else return the(possibly) current vrm - return skinnedVrms[app.current] && skinnedVrms[app.current]; - } - - // use this to change which mesh we're using - app.setCurrent = (target) => { - for (const key in skinnedVrms) { - if (Object.hasOwnProperty.call(skinnedVrms, key)) { - skinnedVrms[key].scene.visible = false - } - } - - app.current = target; - //if this app's scene has no parent, then it's never been prepped. prep it now - !app.getCurrentVrm().scene.parent && _prepVrm(app.getCurrentVrm().scene); - app.getCurrentVrm().scene.visible = true; - } - - let physicsIds = []; - let activateCb = null; - e.waitUntil((async () => { - arrayBuffer = await _fetchArrayBuffer(srcUrl); - - const skinnedVrmBase = await _cloneVrm(); - skinnedVrms['base'] = skinnedVrmBase; - app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated - _prepVrm(skinnedVrmBase.scene); - skinnedVrms.base.scene.name = 'base mesh'; - - skinnedVrms['base'].makeCrunched = async (src) => { - if (src.scene.name == "crunched") return src.scene; - //we always need the crunched avatar - const skinnedVrmCrunched = await _crunch(src.scene); - skinnedVrmCrunched.name = 'crunched'; - _prepVrm(skinnedVrmCrunched) - let tmpVrms = { ...skinnedVrms }; - delete tmpVrms.crunched; - tmpVrms.crunched = { ...src }; - tmpVrms.crunched.scene = skinnedVrmCrunched; - skinnedVrms = tmpVrms; - return skinnedVrmCrunched; - } - - skinnedVrms['crunched'] = skinnedVrms['base']; - - const _addPhysics = () => { - const fakeHeight = 1.5; - localMatrix.compose( - localVector.set(0, fakeHeight / 2, 0), - localQuaternion.identity(), - localVector2.set(0.3, fakeHeight / 2, 0.3) - ) - .premultiply(app.matrixWorld) - .decompose(localVector, localQuaternion, localVector2); - - const physicsId = physics.addBoxGeometry( - localVector, - localQuaternion, - localVector2, - false - ); - physicsIds.push(physicsId); - }; - if (app.getComponent('physics')) { - _addPhysics(); - } - - // we don't want to have per-frame bone updates for unworn avatars - // so we toggle bone updates off and let the app enable them when worn - app.toggleBoneUpdates(false); - - activateCb = async () => { - const localPlayer = useLocalPlayer(); - localPlayer.setAvatarApp(app); - }; - - app.updateQuality = async () => { - const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); - const quality = gfxSettings.character.details; - return await _setQuality(quality, app, skinnedVrms) - } - - await app.updateQuality(); - - - })()); - - - useActivate(() => { - activateCb && activateCb(); - }); - - app.lookAt = (lookAt => function (p) { - lookAt.apply(this, arguments); - this.quaternion.premultiply(q180); - })(app.lookAt); - - app.setSkinning = async skinning => { - console.warn("WARNING: setSkinning FUNCTION IS DEPRICATED and will be removed. Please use toggleBoneUpdates instead."); - app.toggleBoneUpdates(skinning); - } - - app.toggleBoneUpdates = update => { - - const {scene} = skinnedVrms.base; - scene.traverse(o => { - // o.matrixAutoUpdate = update; - if (o.isBone) o.matrixAutoUpdate = update; - }); - - if (update) { - app.position.set(0, 0, 0); - app.quaternion.identity(); - app.scale.set(1, 1, 1); - app.updateMatrixWorld(); - } - - } - - useCleanup(() => { - for (const physicsId of physicsIds) { - physics.removeGeometry(physicsId); - } - physicsIds.length = 0; - }); - - return app; -}; -export const contentId = ${ this.contentId }; -export const name = ${ this.name }; -export const description = ${ this.description }; -export const components = ${ this.components }; +import * as THREE from 'three'; +import metaversefile from 'metaversefile'; +import { VRMMaterialImporter } from '@pixiv/three-vrm/lib/three-vrm.module'; +const { useApp, useLoaders, usePhysics, useCleanup, useActivate, useLocalPlayer, useAvatarCruncher, useSettingsManager } = metaversefile; + +const localVector = new THREE.Vector3(); +const localVector2 = new THREE.Vector3(); +const localQuaternion = new THREE.Quaternion(); +const localMatrix = new THREE.Matrix4(); +// const q180 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI); + +const _fetchArrayBuffer = async srcUrl => { + const res = await fetch(srcUrl); + if (res.ok) { + const arrayBuffer = await res.arrayBuffer(); + return arrayBuffer; + } else { + throw new Error('failed to load: ' + res.status + ' ' + srcUrl); + } +}; +/* const loadVrm = async (srcUrl) => { + let vrmObject; + try { + const res = await fetch(srcUrl); + if (res.ok) { + const arrayBuffer = await res.arrayBuffer(); + vrmObject = await parseVrm(arrayBuffer, srcUrl); + vrmObject.arrayBuffer = arrayBuffer; + // startMonetization(instanceId, monetizationPointer, ownerAddress); + } else { + throw new Error('failed to load: ' + res.status + ' ' + srcUrl); + } + } catch(err) { + console.warn(err); + vrmObject = null; + } + return vrmObject; +}; */ +const parseVrm = (arrayBuffer, srcUrl) => new Promise((accept, reject) => { + const { gltfLoader } = useLoaders(); + gltfLoader.parse(arrayBuffer, srcUrl, accept, reject); +}); +/* const _findMaterialsObjects = (o, name) => { + const result = []; + o.traverse(o => { + if (o.isMesh && o.material.name === name) { + result.push(o); + } + }); + return result; +}; */ +const _crunch = async o => { + return useAvatarCruncher().crunchAvatarModel(o); +}; +const mapTypes = [ + 'alphaMap', + 'aoMap', + 'bumpMap', + 'displacementMap', + 'emissiveMap', + 'envMap', + 'lightMap', + 'map', + 'metalnessMap', + 'normalMap', + 'roughnessMap', +]; +const _addAnisotropy = (o, anisotropyLevel) => { + o.traverse(o => { + if (o.isMesh) { + for (const mapType of mapTypes) { + if (o.material[mapType]) { + o.material[mapType].anisotropy = anisotropyLevel; + } + } + } + }); +}; + +const _setQuality = async (quality, app, skinnedVrms) => { + + const baseVrm = skinnedVrms.base; + + switch (quality ?? 'MEDIUM') { + case 'LOW': + case 'MEDIUM': { + if (skinnedVrms.crunched) { + if (skinnedVrms.crunched.scene.name !== "crunched") { + await skinnedVrms.crunched.makeCrunched(skinnedVrms.base); + } + } else { + throw new Error('something went wrong, missing crunched avatar'); + } + app.setCurrent('crunched'); + + break; + } + case 'HIGH': { + baseVrm.scene.name = "base mesh" + app.setCurrent('base'); + break; + } + case 'ULTRA': { + console.log('not implimented'); + break; + } + default: { + throw new Error('unknown avatar quality: ' + quality); + } + } + return app.getCurrentVrm().scene; +} + +export default e => { + const physics = usePhysics(); + + const app = useApp(); + app.appType = 'vrm'; + app.current = 'base'; + + let skinnedVrms = {}; + + const srcUrl = ${ this.srcUrl }; + for (const { key, value } of components) { + app.setComponent(key, value); + } + + let arrayBuffer = null; + const _cloneVrm = async () => { + const vrm = await parseVrm(arrayBuffer, srcUrl); + vrm.cloneVrm = _cloneVrm; + return vrm; + }; + + const _prepVrm = (vrm) => { + vrm.visible = false; + app.add(vrm); + vrm.updateMatrixWorld(); + _addAnisotropy(vrm, 16); + } + + app.getCurrentVrm = () => { + //return scene if we have an current vrm and we're not requesting the scene. else return the(possibly) current vrm + return skinnedVrms[app.current] && skinnedVrms[app.current]; + } + + // use this to change which mesh we're using + app.setCurrent = (target) => { + for (const key in skinnedVrms) { + if (Object.hasOwnProperty.call(skinnedVrms, key)) { + skinnedVrms[key].scene.visible = false + } + } + + app.current = target; + //if this app's scene has no parent, then it's never been prepped. prep it now + !app.getCurrentVrm().scene.parent && _prepVrm(app.getCurrentVrm().scene); + app.getCurrentVrm().scene.visible = true; + } + + let physicsIds = []; + let activateCb = null; + e.waitUntil((async () => { + arrayBuffer = await _fetchArrayBuffer(srcUrl); + + const skinnedVrmBase = await _cloneVrm(); + skinnedVrms['base'] = skinnedVrmBase; + app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated + _prepVrm(skinnedVrmBase.scene); + skinnedVrms.base.scene.name = 'base mesh'; + + skinnedVrms['base'].makeCrunched = async (src) => { + if (src.scene.name == "crunched") return src.scene; + //we always need the crunched avatar + const skinnedVrmCrunched = await _crunch(src.scene); + skinnedVrmCrunched.name = 'crunched'; + _prepVrm(skinnedVrmCrunched) + let tmpVrms = { ...skinnedVrms }; + delete tmpVrms.crunched; + tmpVrms.crunched = { ...src }; + tmpVrms.crunched.scene = skinnedVrmCrunched; + skinnedVrms = tmpVrms; + return skinnedVrmCrunched; + } + + skinnedVrms['crunched'] = skinnedVrms['base']; + + const _addPhysics = () => { + const fakeHeight = 1.5; + localMatrix.compose( + localVector.set(0, fakeHeight / 2, 0), + localQuaternion.identity(), + localVector2.set(0.3, fakeHeight / 2, 0.3) + ) + .premultiply(app.matrixWorld) + .decompose(localVector, localQuaternion, localVector2); + + const physicsId = physics.addBoxGeometry( + localVector, + localQuaternion, + localVector2, + false + ); + physicsIds.push(physicsId); + }; + if (app.getComponent('physics')) { + _addPhysics(); + } + + // we don't want to have per-frame bone updates for unworn avatars + // so we toggle bone updates off and let the app enable them when worn + app.toggleBoneUpdates(false); + + activateCb = async () => { + const localPlayer = useLocalPlayer(); + localPlayer.setAvatarApp(app); + }; + + app.updateQuality = async () => { + const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); + const quality = gfxSettings.character.details; + return await _setQuality(quality, app, skinnedVrms) + } + + await app.updateQuality(); + + + })()); + + + useActivate(() => { + activateCb && activateCb(); + }); + + app.lookAt = (lookAt => function (p) { + lookAt.apply(this, arguments); + this.quaternion.premultiply(q180); + })(app.lookAt); + + app.setSkinning = async skinning => { + console.warn("WARNING: setSkinning FUNCTION IS DEPRICATED and will be removed. Please use toggleBoneUpdates instead."); + app.toggleBoneUpdates(skinning); + } + + app.toggleBoneUpdates = update => { + + const {scene} = skinnedVrms.base; + scene.traverse(o => { + // o.matrixAutoUpdate = update; + if (o.isBone) o.matrixAutoUpdate = update; + }); + + if (update) { + app.position.set(0, 0, 0); + app.quaternion.identity(); + app.scale.set(1, 1, 1); + app.updateMatrixWorld(); + } + + } + + useCleanup(() => { + for (const physicsId of physicsIds) { + physics.removeGeometry(physicsId); + } + physicsIds.length = 0; + }); + + return app; +}; +export const contentId = ${ this.contentId }; +export const name = ${ this.name }; +export const description = ${ this.description }; +export const components = ${ this.components }; From 3e09dcf1fe1e9171b6fdcc4d6ead75dc14736771 Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Sat, 26 Mar 2022 17:53:13 -0400 Subject: [PATCH 11/14] toggleBoneUpdates for all vrms in app --- type_templates/vrm.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 9ddfd30..87b4104 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -244,11 +244,16 @@ export default e => { app.toggleBoneUpdates = update => { - const {scene} = skinnedVrms.base; + for (const key in skinnedVrms) { + if (Object.hasOwnProperty.call(skinnedVrms, key)) { + const _vrm = skinnedVrms[key]; + const { scene } = _vrm; scene.traverse(o => { // o.matrixAutoUpdate = update; if (o.isBone) o.matrixAutoUpdate = update; }); + } + } if (update) { app.position.set(0, 0, 0); From 1120d028c58e44d486558782c7ab62a0c9b7bd6e Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Sat, 26 Mar 2022 17:56:49 -0400 Subject: [PATCH 12/14] rework update logic --- type_templates/vrm.js | 67 +++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 87b4104..35acf51 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -77,27 +77,18 @@ const _addAnisotropy = (o, anisotropyLevel) => { }); }; -const _setQuality = async (quality, app, skinnedVrms) => { +const _setQuality = (quality, app) => { - const baseVrm = skinnedVrms.base; - - switch (quality ?? 'MEDIUM') { + switch (quality) { case 'LOW': + console.log('not implimented'); + break; case 'MEDIUM': { - if (skinnedVrms.crunched) { - if (skinnedVrms.crunched.scene.name !== "crunched") { - await skinnedVrms.crunched.makeCrunched(skinnedVrms.base); - } - } else { - throw new Error('something went wrong, missing crunched avatar'); - } - app.setCurrent('crunched'); - + app.setCurrentVrm('crunched'); break; } case 'HIGH': { - baseVrm.scene.name = "base mesh" - app.setCurrent('base'); + app.setCurrentVrm('base'); break; } case 'ULTRA': { @@ -139,24 +130,7 @@ export default e => { _addAnisotropy(vrm, 16); } - app.getCurrentVrm = () => { - //return scene if we have an current vrm and we're not requesting the scene. else return the(possibly) current vrm - return skinnedVrms[app.current] && skinnedVrms[app.current]; - } - - // use this to change which mesh we're using - app.setCurrent = (target) => { - for (const key in skinnedVrms) { - if (Object.hasOwnProperty.call(skinnedVrms, key)) { - skinnedVrms[key].scene.visible = false - } - } - app.current = target; - //if this app's scene has no parent, then it's never been prepped. prep it now - !app.getCurrentVrm().scene.parent && _prepVrm(app.getCurrentVrm().scene); - app.getCurrentVrm().scene.visible = true; - } let physicsIds = []; let activateCb = null; @@ -216,13 +190,8 @@ export default e => { localPlayer.setAvatarApp(app); }; - app.updateQuality = async () => { - const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); - const quality = gfxSettings.character.details; - return await _setQuality(quality, app, skinnedVrms) - } - await app.updateQuality(); + app.updateQuality(); })()); @@ -237,6 +206,22 @@ export default e => { this.quaternion.premultiply(q180); })(app.lookAt); + app.getCurrentVrm = () => { + return skinnedVrms[app.current]; + } + + // use this to change which vrm we're using + app.setCurrentVrm = (newCurrent) => { + for (const key in skinnedVrms) { + if (Object.hasOwnProperty.call(skinnedVrms, key)) { + skinnedVrms[key].scene.visible = false + } + } + + app.current = newCurrent; + app.getCurrentVrm().scene.visible = true; + } + app.setSkinning = async skinning => { console.warn("WARNING: setSkinning FUNCTION IS DEPRICATED and will be removed. Please use toggleBoneUpdates instead."); app.toggleBoneUpdates(skinning); @@ -264,6 +249,12 @@ export default e => { } + app.updateQuality = () => { + const gfxSettings = useSettingsManager().getSettingsJson('GfxSettings'); + const quality = gfxSettings.character.details; + return _setQuality(quality, app) + } + useCleanup(() => { for (const physicsId of physicsIds) { physics.removeGeometry(physicsId); From f2baf3bd54dee6f3a2ea59f4fd05a0591f7d203f Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Sat, 26 Mar 2022 17:58:03 -0400 Subject: [PATCH 13/14] rework crunching logic --- type_templates/vrm.js | 46 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 35acf51..69146cd 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -119,15 +119,14 @@ export default e => { let arrayBuffer = null; const _cloneVrm = async () => { const vrm = await parseVrm(arrayBuffer, srcUrl); - vrm.cloneVrm = _cloneVrm; return vrm; }; - const _prepVrm = (vrm) => { - vrm.visible = false; - app.add(vrm); - vrm.updateMatrixWorld(); - _addAnisotropy(vrm, 16); + const _prepScene = (scene) => { + scene.visible = false; + app.add(scene); + scene.updateMatrixWorld(); + _addAnisotropy(scene, 16); } @@ -137,27 +136,14 @@ export default e => { e.waitUntil((async () => { arrayBuffer = await _fetchArrayBuffer(srcUrl); - const skinnedVrmBase = await _cloneVrm(); - skinnedVrms['base'] = skinnedVrmBase; - app.skinnedVrm = skinnedVrmBase; //temporary support for webaverse code base until it's updated - _prepVrm(skinnedVrmBase.scene); - skinnedVrms.base.scene.name = 'base mesh'; - - skinnedVrms['base'].makeCrunched = async (src) => { - if (src.scene.name == "crunched") return src.scene; - //we always need the crunched avatar - const skinnedVrmCrunched = await _crunch(src.scene); - skinnedVrmCrunched.name = 'crunched'; - _prepVrm(skinnedVrmCrunched) - let tmpVrms = { ...skinnedVrms }; - delete tmpVrms.crunched; - tmpVrms.crunched = { ...src }; - tmpVrms.crunched.scene = skinnedVrmCrunched; - skinnedVrms = tmpVrms; - return skinnedVrmCrunched; - } + skinnedVrms['base'] = await _cloneVrm(); + _prepScene(skinnedVrms.base.scene); - skinnedVrms['crunched'] = skinnedVrms['base']; + //we always need the crunched avatar + skinnedVrms['crunched'] = { ...skinnedVrms.base }; + skinnedVrms.crunched.scene = await _crunch(skinnedVrms.base.scene); + _prepScene(skinnedVrms.crunched.scene) + const _addPhysics = () => { const fakeHeight = 1.5; @@ -233,10 +219,10 @@ export default e => { if (Object.hasOwnProperty.call(skinnedVrms, key)) { const _vrm = skinnedVrms[key]; const { scene } = _vrm; - scene.traverse(o => { - // o.matrixAutoUpdate = update; - if (o.isBone) o.matrixAutoUpdate = update; - }); + scene.traverse(o => { + // o.matrixAutoUpdate = update; + if (o.isBone) o.matrixAutoUpdate = update; + }); } } From e1a2dac004dfb5eef0c8f55d1e3f7805c1e59cc8 Mon Sep 17 00:00:00 2001 From: Adam Clarke Date: Sat, 26 Mar 2022 18:32:12 -0400 Subject: [PATCH 14/14] direct access to crunched for diorama/depth calls --- type_templates/vrm.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/type_templates/vrm.js b/type_templates/vrm.js index 69146cd..5515736 100644 --- a/type_templates/vrm.js +++ b/type_templates/vrm.js @@ -208,6 +208,10 @@ export default e => { app.getCurrentVrm().scene.visible = true; } + app.getCrunchedVrm = ()=>{ + return skinnedVrms.crunched; + } + app.setSkinning = async skinning => { console.warn("WARNING: setSkinning FUNCTION IS DEPRICATED and will be removed. Please use toggleBoneUpdates instead."); app.toggleBoneUpdates(skinning);