Skip to content

Commit 0c0b532

Browse files
committed
rename variables to reflect correctly trait groups and trait models
1 parent f16f54f commit 0c0b532

File tree

1 file changed

+107
-20
lines changed

1 file changed

+107
-20
lines changed

src/library/characterManager.js

+107-20
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ export class CharacterManager {
2828
this.traitLoadManager = new TraitLoadingManager();
2929
}
3030

31-
31+
32+
3233
getGroupTraits(){
3334
if (this.manifestData){
3435
return this.manifestData.getGroupModelTraits();
3536
}
3637
}
3738

38-
39+
// returns wether or not the trait group can be removed
40+
isTraitGroupRemovable(groupTraitID){
41+
42+
}
43+
3944
// manifest data requests
4045
getTraits(groupTraitID){
4146
if (this.manifestData){
@@ -89,6 +94,18 @@ export class CharacterManager {
8994
this._loadTraits(getAsArray(selectedTrait));
9095
}
9196

97+
removeTrait(groupTraitID){
98+
const groupTrait = this.manifestData.getModelGroup(groupTraitID);
99+
if (groupTrait){
100+
const itemData = new LoadedData({traitGroup:groupTrait, traitModel:null})
101+
this._addLoadedData(itemData);
102+
cullHiddenMeshes(this.avatar);
103+
}
104+
else{
105+
console.warn(`No trait with name: ${ groupTraitID } was found.`)
106+
}
107+
}
108+
92109
async loadCustom(url){
93110

94111
}
@@ -346,22 +363,22 @@ export class CharacterManager {
346363

347364
_addLoadedData(itemData){
348365
const {
349-
item,
350-
trait,
366+
traitGroup,
367+
traitModel,
351368
textureTrait,
352369
colorTrait,
353370
models,
354371
textures,
355372
colors
356373
} = itemData;
357374
console.log(itemData);
358-
const traitName = trait.name;
375+
const traitGroupName = traitGroup.name;
359376

360377
// user selected to remove trait
361-
if (item == null){
362-
if ( this.avatar[traitName] && this.avatar[traitName].vrm ){
378+
if (traitModel == null){
379+
if ( this.avatar[traitGroupName] && this.avatar[traitGroupName].vrm ){
363380
// just dispose for now
364-
disposeVRM(avatar[traitData.name].vrm)
381+
disposeVRM(avatar[traitGroupName].vrm)
365382
// XXX restore effects without setTimeout
366383
}
367384
return;
@@ -373,7 +390,7 @@ export class CharacterManager {
373390

374391
// basic vrm setup (only if model is vrm)
375392
// send textures and colors
376-
vrm = this._VRMBaseSetup(m, item, trait, textures, colors);
393+
vrm = this._VRMBaseSetup(m, traitModel, traitGroup, textures, colors);
377394

378395
this._applyManagers(vrm)
379396

@@ -384,8 +401,8 @@ export class CharacterManager {
384401
})
385402

386403
// If there was a previous loaded model, remove it (maybe also remove loaded textures?)
387-
if (this.avatar[traitName] && this.avatar[traitName].vrm) {
388-
disposeVRM(this.avatar[traitName].vrm)
404+
if (this.avatar[traitGroupName] && this.avatar[traitGroupName].vrm) {
405+
disposeVRM(this.avatar[traitGroupName].vrm)
389406
// XXX restore effects
390407
}
391408

@@ -394,11 +411,11 @@ export class CharacterManager {
394411

395412
// and then add the new avatar data
396413
// to do, we are now able to load multiple vrm models per options, set the options to include vrm arrays
397-
this.avatar[traitName] = {
398-
traitInfo: item,
414+
this.avatar[traitGroupName] = {
415+
traitInfo: traitModel,
399416
textureInfo: textureTrait,
400417
colorInfo: colorTrait,
401-
name: item.name,
418+
name: traitModel.name,
402419
model: vrm && vrm.scene,
403420
vrm: vrm
404421
}
@@ -487,8 +504,8 @@ class TraitLoadingManager{
487504
const loadedColors = getAsArray(option?.traitColor?.value).map((colorValue) => new THREE.Color(colorValue));
488505

489506
resultData[index] = new LoadedData({
490-
item: option?.traitModel,
491-
trait: option?.traitModel.traitGroup,
507+
traitGroup: option?.traitModel.traitGroup,
508+
traitModel: option?.traitModel,
492509
textureTrait: option?.traitTexture,
493510
colorTrait: option?.traitColor,
494511
models: loadedModels,
@@ -514,8 +531,8 @@ class TraitLoadingManager{
514531
class LoadedData{
515532
constructor(data){
516533
const {
517-
item,
518-
trait,
534+
traitGroup,
535+
traitModel,
519536
textureTrait,
520537
colorTrait,
521538
models,
@@ -524,8 +541,8 @@ class LoadedData{
524541
} = data;
525542

526543
// Option base data
527-
this.item = item;
528-
this.trait = trait;
544+
this.traitGroup = traitGroup;
545+
this.traitModel = traitModel;
529546
this.textureTrait = textureTrait;
530547
this.colorTrait = colorTrait;
531548

@@ -995,6 +1012,61 @@ class TraitOption{
9951012

9961013
// should be called within manifestData, as it is the one that holds this information
9971014

1015+
// const getRestrictions = () => {
1016+
1017+
// const traitRestrictions = templateInfo.traitRestrictions // can be null
1018+
// const typeRestrictions = {};
1019+
1020+
// for (const prop in traitRestrictions){
1021+
1022+
// // create the counter restrcitions traits
1023+
// getAsArray(traitRestrictions[prop].restrictedTraits).map((traitName)=>{
1024+
1025+
// // check if the trait restrictions exists for the other trait, if not add it
1026+
// if (traitRestrictions[traitName] == null) traitRestrictions[traitName] = {}
1027+
// // make sure to have an array setup, if there is none, create a new empty one
1028+
// if (traitRestrictions[traitName].restrictedTraits == null) traitRestrictions[traitName].restrictedTraits = []
1029+
1030+
// // finally merge existing and new restrictions
1031+
// traitRestrictions[traitName].restrictedTraits = [...new Set([
1032+
// ...traitRestrictions[traitName].restrictedTraits ,
1033+
// ...[prop]])] // make sure to add prop as restriction
1034+
// })
1035+
1036+
// // do the same for the types
1037+
// getAsArray(traitRestrictions[prop].restrictedTypes).map((typeName)=>{
1038+
// //notice were adding the new data to typeRestrictions and not trait
1039+
// if (typeRestrictions[typeName] == null) typeRestrictions[typeName] = {}
1040+
// //create the restricted trait in this type
1041+
// if (typeRestrictions[typeName].restrictedTraits == null) typeRestrictions[typeName].restrictedTraits = []
1042+
1043+
// typeRestrictions[typeName].restrictedTraits = [...new Set([
1044+
// ...typeRestrictions[typeName].restrictedTraits ,
1045+
// ...[prop]])] // make sure to add prop as restriction
1046+
// })
1047+
// }
1048+
1049+
// // now merge defined type to type restrictions
1050+
// for (const prop in templateInfo.typeRestrictions){
1051+
// // check if it already exsits
1052+
// if (typeRestrictions[prop] == null) typeRestrictions[prop] = {}
1053+
// if (typeRestrictions[prop].restrictedTypes == null) typeRestrictions[prop].restrictedTypes = []
1054+
// typeRestrictions[prop].restrictedTypes = [...new Set([
1055+
// ...typeRestrictions[prop].restrictedTypes ,
1056+
// ...getAsArray(templateInfo.typeRestrictions[prop])])]
1057+
1058+
// // now that we have setup the type restrictions, lets counter create for the other traits
1059+
// getAsArray(templateInfo.typeRestrictions[prop]).map((typeName)=>{
1060+
// // prop = boots
1061+
// // typeName = pants
1062+
// if (typeRestrictions[typeName] == null) typeRestrictions[typeName] = {}
1063+
// if (typeRestrictions[typeName].restrictedTypes == null) typeRestrictions[typeName].restrictedTypes =[]
1064+
// typeRestrictions[typeName].restrictedTypes = [...new Set([
1065+
// ...typeRestrictions[typeName].restrictedTypes ,
1066+
// ...[prop]])] // make sure to add prop as restriction
1067+
// })
1068+
// }
1069+
9981070
// _filterRestrictedOptions(options){
9991071
// let removeTraits = [];
10001072
// for (let i =0; i < options.length;i++){
@@ -1055,6 +1127,21 @@ class TraitOption{
10551127

10561128
// return options;
10571129
// }
1130+
1131+
// const findTraitsWithTypes = (types) => {
1132+
// const typeTraits = [];
1133+
// for (const prop in avatar){
1134+
// for (let i = 0; i < types.length; i++){
1135+
// const t = types[i]
1136+
1137+
// if (avatar[prop].traitInfo?.type?.includes(t)){
1138+
// typeTraits.push(prop);
1139+
// break;
1140+
// }
1141+
// }
1142+
// }
1143+
// return typeTraits;
1144+
// }
10581145
// _loadOptions(options, filterRestrictions = true, useTemplateBaseDirectory = true, saveUserSel = true){
10591146

10601147
// // XXX I think this part was used to know which trait was selected

0 commit comments

Comments
 (0)