@@ -28,14 +28,19 @@ export class CharacterManager {
28
28
this . traitLoadManager = new TraitLoadingManager ( ) ;
29
29
}
30
30
31
-
31
+
32
+
32
33
getGroupTraits ( ) {
33
34
if ( this . manifestData ) {
34
35
return this . manifestData . getGroupModelTraits ( ) ;
35
36
}
36
37
}
37
38
38
-
39
+ // returns wether or not the trait group can be removed
40
+ isTraitGroupRemovable ( groupTraitID ) {
41
+
42
+ }
43
+
39
44
// manifest data requests
40
45
getTraits ( groupTraitID ) {
41
46
if ( this . manifestData ) {
@@ -89,6 +94,18 @@ export class CharacterManager {
89
94
this . _loadTraits ( getAsArray ( selectedTrait ) ) ;
90
95
}
91
96
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
+
92
109
async loadCustom ( url ) {
93
110
94
111
}
@@ -346,22 +363,22 @@ export class CharacterManager {
346
363
347
364
_addLoadedData ( itemData ) {
348
365
const {
349
- item ,
350
- trait ,
366
+ traitGroup ,
367
+ traitModel ,
351
368
textureTrait,
352
369
colorTrait,
353
370
models,
354
371
textures,
355
372
colors
356
373
} = itemData ;
357
374
console . log ( itemData ) ;
358
- const traitName = trait . name ;
375
+ const traitGroupName = traitGroup . name ;
359
376
360
377
// 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 ) {
363
380
// just dispose for now
364
- disposeVRM ( avatar [ traitData . name ] . vrm )
381
+ disposeVRM ( avatar [ traitGroupName ] . vrm )
365
382
// XXX restore effects without setTimeout
366
383
}
367
384
return ;
@@ -373,7 +390,7 @@ export class CharacterManager {
373
390
374
391
// basic vrm setup (only if model is vrm)
375
392
// send textures and colors
376
- vrm = this . _VRMBaseSetup ( m , item , trait , textures , colors ) ;
393
+ vrm = this . _VRMBaseSetup ( m , traitModel , traitGroup , textures , colors ) ;
377
394
378
395
this . _applyManagers ( vrm )
379
396
@@ -384,8 +401,8 @@ export class CharacterManager {
384
401
} )
385
402
386
403
// 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 )
389
406
// XXX restore effects
390
407
}
391
408
@@ -394,11 +411,11 @@ export class CharacterManager {
394
411
395
412
// and then add the new avatar data
396
413
// 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 ,
399
416
textureInfo : textureTrait ,
400
417
colorInfo : colorTrait ,
401
- name : item . name ,
418
+ name : traitModel . name ,
402
419
model : vrm && vrm . scene ,
403
420
vrm : vrm
404
421
}
@@ -487,8 +504,8 @@ class TraitLoadingManager{
487
504
const loadedColors = getAsArray ( option ?. traitColor ?. value ) . map ( ( colorValue ) => new THREE . Color ( colorValue ) ) ;
488
505
489
506
resultData [ index ] = new LoadedData ( {
490
- item : option ?. traitModel ,
491
- trait : option ?. traitModel . traitGroup ,
507
+ traitGroup : option ?. traitModel . traitGroup ,
508
+ traitModel : option ?. traitModel ,
492
509
textureTrait : option ?. traitTexture ,
493
510
colorTrait : option ?. traitColor ,
494
511
models : loadedModels ,
@@ -514,8 +531,8 @@ class TraitLoadingManager{
514
531
class LoadedData {
515
532
constructor ( data ) {
516
533
const {
517
- item ,
518
- trait ,
534
+ traitGroup ,
535
+ traitModel ,
519
536
textureTrait,
520
537
colorTrait,
521
538
models,
@@ -524,8 +541,8 @@ class LoadedData{
524
541
} = data ;
525
542
526
543
// Option base data
527
- this . item = item ;
528
- this . trait = trait ;
544
+ this . traitGroup = traitGroup ;
545
+ this . traitModel = traitModel ;
529
546
this . textureTrait = textureTrait ;
530
547
this . colorTrait = colorTrait ;
531
548
@@ -995,6 +1012,61 @@ class TraitOption{
995
1012
996
1013
// should be called within manifestData, as it is the one that holds this information
997
1014
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
+
998
1070
// _filterRestrictedOptions(options){
999
1071
// let removeTraits = [];
1000
1072
// for (let i =0; i < options.length;i++){
@@ -1055,6 +1127,21 @@ class TraitOption{
1055
1127
1056
1128
// return options;
1057
1129
// }
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
+ // }
1058
1145
// _loadOptions(options, filterRestrictions = true, useTemplateBaseDirectory = true, saveUserSel = true){
1059
1146
1060
1147
// // XXX I think this part was used to know which trait was selected
0 commit comments