Skip to content

Commit

Permalink
start old code removal from react
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Dec 5, 2023
1 parent 82b9f2a commit 6a8f51e
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 108 deletions.
8 changes: 8 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import Appearance from "./pages/Appearance"
import Optimizer from "./pages/Optimizer"
import LanguageSwitch from "./components/LanguageSwitch"

import { CharacterManager } from "./library/characterManager"


// dynamically import the manifest
const assetImportPath = import.meta.env.VITE_ASSET_PATH + "/manifest.json"
Expand Down Expand Up @@ -104,6 +106,9 @@ async function fetchAll() {
const personality = await fetchPersonality()
const sceneModel = await fetchScene()

// const characterManager = new CharacterManager({createAnimationManager : true});
// characterManager.loadManifest(initialManifest[0].manifest,{createAnimationManager:true});

const blinkManager = new BlinkManager(0.1, 0.1, 0.5, 5)
const lookatManager = new LookAtManager(80, "editor-scene")
const effectManager = new EffectManager()
Expand All @@ -117,6 +122,7 @@ async function fetchAll() {
lookatManager,
effectManager,
screenshotManager,
//characterManager
}
}

Expand Down Expand Up @@ -159,6 +165,7 @@ export default function App() {
lookatManager,
effectManager,
screenshotManager,
//characterManager
} = resource.read()

const [hideUi, setHideUi] = useState(false)
Expand Down Expand Up @@ -313,6 +320,7 @@ export default function App() {
lookatManager={lookatManager}
effectManager={effectManager}
confirmDialog={confirmDialog}
//characterManager = {characterManager}
/>
),
[ViewMode.OPTIMIZER]: (
Expand Down
50 changes: 46 additions & 4 deletions src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default function Editor({uploadTextureURL, uploadVRMURL,confirmDialog,ani
avatar,
setDisplayTraitOption,
currentVRM,
setCurrentVRM
setCurrentVRM,
characterManager
} = useContext(SceneContext);

const { isMute } = useContext(AudioContext)
Expand All @@ -51,6 +52,9 @@ export default function Editor({uploadTextureURL, uploadVRMURL,confirmDialog,ani

const [cameraFocused, setCameraFocused] = React.useState(false)

//const [groupTraits, setGroupTraits] = React.useState([])
const [traits, setTraits] = React.useState(null)

// options are selected by random or start
useEffect(() => {
if (awaitDisplay){
Expand Down Expand Up @@ -91,8 +95,25 @@ export default function Editor({uploadTextureURL, uploadVRMURL,confirmDialog,ani
)
moveCamera({ targetY: option.cameraTarget.height, distance: option.cameraTarget.distance})
setCurrentOptions(getTraitOptions(option, templateInfo))
setCurrentTraitName(option.name)







// XXX character manager -- setTraits
console.log("Selected option: ",option.name);
console.log(characterManager.getTraits(option.name));








setCurrentTraitName(option.name)
// for item display
setDisplayTraitOption(avatar[option.name]?.traitInfo)
setCurrentVRM(avatar[option.name]?.vrm);
Expand All @@ -105,7 +126,27 @@ export default function Editor({uploadTextureURL, uploadVRMURL,confirmDialog,ani
<div className={styles["bottomLine"]} />
<div className={styles["scrollContainer"]}>
<div className={styles["selector-container"]}>
{templateInfo.traits &&
{
characterManager.getGroupTraits().map((item, index) => (
<div key={"options_" + index} className={styles["selectorButton"]}>
<TokenBox
size={56}
resolution={2048}
numFrames={128}
icon={ item.fullIconSvg }
rarity={currentTraitName !== item.name ? "none" : "mythic"}
onClick={() => {
//console.log(characterManager.getTraits(item.trait))
// console.log(item.fullIconSvg);
setTraits(characterManager.getTraits(item.trait));
console.log(traits);
//selectOption(item)
}}
/>
</div>
))
}
{/* {templateInfo.traits &&
templateInfo.traits.map((item, index) => (
<div key={index} className={styles["selectorButton"]}>
<TokenBox
Expand All @@ -116,10 +157,11 @@ export default function Editor({uploadTextureURL, uploadVRMURL,confirmDialog,ani
rarity={currentTraitName !== item.name ? "none" : "mythic"}
onClick={() => {
selectOption(item)
console.log((templateInfo.assetsLocation || "") + templateInfo.traitIconsDirectorySvg + item.iconSvg)
}}
/>
</div>
))}
))} */}
</div>
</div>
</div>
Expand Down
36 changes: 26 additions & 10 deletions src/components/Selector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
setIsChangingWholeAvatar,
debugMode,
setDisplayTraitOption,
vrmHelperRoot
vrmHelperRoot,
characterManager
} = useContext(SceneContext)
const {
playSound
Expand All @@ -66,6 +67,7 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
}

useEffect(() => {
console.log(templateInfo)
setRestrictions(getRestrictions());
},[templateInfo])

Expand All @@ -80,7 +82,7 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani

const getRestrictions = () => {

const traitRestrictions = templateInfo.traitRestrictions
const traitRestrictions = templateInfo.traitRestrictions // can be null
const typeRestrictions = {};

for (const prop in traitRestrictions){
Expand Down Expand Up @@ -159,16 +161,22 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani

// options are selected by random or start
useEffect(() => {
console.log("test")
if (selectedOptions.length > 0){
setIsChangingWholeAvatar(true);
if (selectedOptions.length > 1){
effectManager.setTransitionEffect('fade_out_avatar');
effectManager.playFadeOutEffect();
resetCurrentTraitMap();
}
loadSelectedOptions(selectedOptions)
characterManager.setParentModel(model);
// characterManager.loadTraits(selectedOptions);
setSelectedOptions([]);
}
// if (selectedOptions.length > 0){
// setIsChangingWholeAvatar(true);
// if (selectedOptions.length > 1){
// effectManager.setTransitionEffect('fade_out_avatar');
// effectManager.playFadeOutEffect();
// resetCurrentTraitMap();
// }
// loadSelectedOptions(selectedOptions)
// setSelectedOptions([]);
// }

},[selectedOptions])

Expand Down Expand Up @@ -219,6 +227,7 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
}
// user selects an option
const selectTraitOption = (option) => {
console.log(option);
const addOption = option != null
if (isLoading) return;

Expand Down Expand Up @@ -275,6 +284,8 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
}
// filter options by restrictions

console.log(options);

if (filterRestrictions)
options = filterRestrictedOptions(options);

Expand Down Expand Up @@ -620,7 +631,7 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
cullingMeshes.push(child)

if (child.isSkinnedMesh) {
createBoneDirection(child)
//createBoneDirection(child)
if (vrm.meta?.metaVersion === '0'){
VRMUtils.rotateVRM0( vrm );
console.log("Loaded VRM0 file ", vrm);
Expand Down Expand Up @@ -782,6 +793,11 @@ export default function Selector({confirmDialog, uploadVRMURL, templateInfo, ani
styles["selector-button"]
} ${active ? styles["active"] : ""}`}
onClick={() => {
console.log("clicky")
console.log(characterManager)
console.log(option.trait.trait);
console.log(option.item.id)
characterManager.loadTrait(option.trait.trait, option.item.id)
if (effectManager.getTransitionEffect('normal')){
selectTraitOption(option)
setLoadPercentage(1)
Expand Down
11 changes: 11 additions & 0 deletions src/context/SceneContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {

import gsap from "gsap"
import { local } from "../library/store"
import { CharacterManager } from "../library/characterManager"

export const SceneContext = createContext()

export const SceneProvider = (props) => {

const [vrmHelperRoot, setVrmHelperRoot] = useState(null);
const [characterManager, setCharacterManager] = useState(null)

const initializeScene = () => {
const scene = new THREE.Scene()
Expand All @@ -30,10 +32,18 @@ export const SceneProvider = (props) => {
scene.add( helperRoot );
setVrmHelperRoot(helperRoot);

setCharacterManager(new CharacterManager({parentModel: scene, createAnimationManager : true}))

return scene;
}


// const initializeCharacterManifest = () => {
// return new CharacterManager({createAnimationManager : true});
// }

const [scene, setScene] = useState(initializeScene)
//const [characterManifest, setCharacterManifest] = useState(initializeCharacterManifest)


const [currentTraitName, setCurrentTraitName] = useState(null)
Expand Down Expand Up @@ -227,6 +237,7 @@ export const SceneProvider = (props) => {
setLipSync,
scene,
setScene,
characterManager,
currentTraitName,
setCurrentTraitName,
displayTraitOption,
Expand Down
Loading

0 comments on commit 6a8f51e

Please sign in to comment.