Skip to content

Commit

Permalink
Merge pull request #22 from memelotsqui/main
Browse files Browse the repository at this point in the history
Add Debug Mode
  • Loading branch information
madjin authored Oct 3, 2023
2 parents a478910 + b20f666 commit 154c2f3
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/components/Selector.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useContext, useEffect, useState } from "react"
import * as THREE from "three"
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader"
import { VRMLoaderPlugin } from "@pixiv/three-vrm"
import { MToonMaterial, VRMLoaderPlugin } from "@pixiv/three-vrm"
import cancel from "../../public/ui/selector/cancel.png"
import { addModelData, disposeVRM } from "../library/utils"
import { computeBoundsTree, disposeBoundsTree, acceleratedRaycast, SAH } from 'three-mesh-bvh';
Expand Down Expand Up @@ -42,6 +42,7 @@ export default function Selector({confirmDialog, templateInfo, animationManager,
removeOption,
saveUserSelection,
setIsChangingWholeAvatar,
debugMode
} = useContext(SceneContext)
const {
playSound
Expand Down Expand Up @@ -523,9 +524,50 @@ export default function Selector({confirmDialog, templateInfo, animationManager,
// basic setup
child.frustumCulled = false
if (child.isMesh) {

// XXX Setup MToonMaterial for shader

// Set Wireframe material with random colors for each material the object has
child.origMat = child.material;

const getRandomColor = () => {
const minRGBValue = 0.1; // Minimum RGB value to ensure colorful colors
const r = minRGBValue + Math.random() * (1 - minRGBValue);
const g = minRGBValue + Math.random() * (1 - minRGBValue);
const b = minRGBValue + Math.random() * (1 - minRGBValue);
return new THREE.Color(r, g, b);
}

const debugMat = new THREE.MeshBasicMaterial( {
color: getRandomColor(),
wireframe: true,
wireframeLinewidth:0.2
} );

const origMat = child.material;
child.setDebugMode = (debug) => {
if (debug){
if (child.material.length){
child.material[0] = debugMat;
child.material[1] = debugMat;
}
else{
child.material = debugMat;
}
}
else{
child.material = origMat;
}
}

if (debugMode){
child.setDebugMode(true);
}
if (child.material.length){
effectManager.setCustomShader(child.material[0]);
effectManager.setCustomShader(child.material[1]);


}
else{
effectManager.setCustomShader(child.material);
Expand Down
18 changes: 18 additions & 0 deletions src/context/SceneContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,25 @@ export const SceneProvider = (props) => {

const [isChangingWholeAvatar, setIsChangingWholeAvatar] = useState(false)

const [debugMode, setDebugMode] = useState(false);

const setAvatar = (state) => {
_setAvatar(state)
}

const toggleDebugMNode = (isDebug) => {
if (isDebug == null)
isDebug = !debugMode;

setDebugMode(isDebug);
scene.traverse((child) => {
if (child.isMesh) {
if (child.setDebugMode){
child.setDebugMode(isDebug);
}
}
});
}
const loadAvatar = (avatarData) =>{
const data = getOptionsFromAvatarData(avatarData,manifest)
if (data != null){
Expand Down Expand Up @@ -203,6 +218,9 @@ export const SceneProvider = (props) => {
saveAvatarToLocalStorage,
loadAvatarFromLocalStorage,

debugMode,
toggleDebugMNode,

setCurrentOptions,
setSelectedOptions,
getRandomCharacter,
Expand Down
1 change: 1 addition & 0 deletions src/library/effectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
transitionEffectTypeNumber,

} from "./constants.js";
import { MToonMaterial } from "@pixiv/three-vrm";


const textureLoader = new THREE.TextureLoader()
Expand Down
13 changes: 13 additions & 0 deletions src/pages/Appearance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Appearance({
getRandomCharacter,
isChangingWholeAvatar,
setIsChangingWholeAvatar,
toggleDebugMNode
} = React.useContext(SceneContext)

const { playSound } = React.useContext(SoundContext)
Expand All @@ -30,6 +31,7 @@ function Appearance({
resetAvatar()
setViewMode(ViewMode.CREATE)
}


const next = () => {
!isMute && playSound('backNextButton');
Expand All @@ -43,6 +45,10 @@ function Appearance({
}
}

const debugMode = () =>{
toggleDebugMNode()
}

useEffect(() => {
const setIsChangingWholeAvatarFalse = () => setIsChangingWholeAvatar(false)

Expand Down Expand Up @@ -104,6 +110,13 @@ function Appearance({
className={styles.buttonCenter}
onClick={randomize}
/>
<CustomButton
theme="light"
text={"debug"}
size={14}
className={styles.buttonCenter}
onClick={debugMode}
/>
</div>
</div>
)
Expand Down

0 comments on commit 154c2f3

Please sign in to comment.