-
Notifications
You must be signed in to change notification settings - Fork 26
Optimizer
The Optimizer
component is a part of a React application that provides an interface for users to optimize their 3D character models. Users can drop their character files into the component, which then processes the file, optimizes it, and allows the user to download the optimized version. The component also provides options for merging and creating texture atlases, and displays information about the current model.
In layman's terms, this component is like a workshop for 3D character models. Users can bring their models in, tweak some settings, and then get a more optimized version of their model to use in their projects.
Imports
The component imports various hooks from React, styles, contexts, components, and utility functions from different modules.
import React, { useContext, useEffect, useState } from "react"
import styles from "./Optimizer.module.css"
import { ViewMode, ViewContext } from "../context/ViewContext"
import { SceneContext } from "../context/SceneContext"
import CustomButton from "../components/custom-button"
import { LanguageContext } from "../context/LanguageContext"
import { SoundContext } from "../context/SoundContext"
import { AudioContext } from "../context/AudioContext"
import FileDropComponent from "../components/FileDropComponent"
import { getFileNameWithoutExtension, disposeVRM, getAtlasSize } from "../library/utils"
import { loadVRM, addVRMToScene } from "../library/load-utils"
import { downloadVRM } from "../library/download-utils"
import ModelInformation from "../components/ModelInformation"
import MergeOptions from "../components/MergeOptions"
import { local } from "../library/store"
Component Definition
The Optimizer
component is defined as a functional component that takes animationManager
as a prop.
function Optimizer({
animationManager,
}) {
// Component body
}
State and Context
The component uses several pieces of state and context to manage its behavior and data.
const { isLoading, setViewMode } = React.useContext(ViewContext)
const { model } = React.useContext(SceneContext)
const [currentVRM, setCurrentVRM] = useState(null);
const [lastVRM, setLastVRM] = useState(null);
const [nameVRM, setNameVRM] = useState("");
const { playSound } = React.useContext(SoundContext)
const { isMute } = React.useContext(AudioContext)
Helper Functions
Several helper functions are defined within the component to handle various tasks such as getting options, downloading the VRM, handling file drops, and more.
const back = () => { /* Function body */ }
const getOptions = () => { /* Function body */ }
const download = () => { /* Function body */ }
const handleAnimationDrop = async (file) => { /* Function body */ }
const handleVRMDrop = async (file) => { /* Function body */ }
const handleFilesDrop = async(files) => { /* Function body */ };
useEffect Hook
A useEffect
hook is used to perform side effects when the currentVRM
state changes.
useEffect(() => {
const fetchData = async () => { /* Function body */ }
fetchData();
}, [currentVRM])
Render
The component returns a JSX structure that includes a loading indicator, a section title, a FileDropComponent
, a MergeOptions
component, a ModelInformation
component, and a set of CustomButton
components.
return (
<div className={styles.container}>
{/* JSX structure */}
</div>
)
Export
Finally, the Optimizer
component is exported for use in other parts of the application.
export default Optimizer