You can install easy-three using npm or yarn.
This method is not recommended for beginners.
npm install @masabando/easy-threeimport { init } from "@masabando/easy-three";import { init } from "@masabando/easy-three";
import { useEffect, useRef } from "react";
export function MyComponent(props) {
const ref = useRef();
useEffect(() => {
const { camera, create, animate, destroy } = init(ref.current);
camera.position.set(0, 0, 2);
create.ambientLight();
create.directionalLight();
create.cube();
animate();
return () => {
destroy();
};
}, []);
return <div
ref={ref}
style={{ width: "300px", height: "300px" }}
/>;
}You can use the template to create a new project.
The template includes the necessary settings for easy-three.
※ Be sure to extract the zip file before use.
You can display it by dragging and dropping the index.html file into a web browser.
To edit the code, use an editor like VSCode.
For more information on how to use the template, see the Reference .
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.185.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.185.1/examples/jsm/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.min.js",
"@masabando/easy-three": "https://cdn.jsdelivr.net/gh/masabando/easy-three@1.15.0/dist/easy-three.js",
"three-mesh-bvh": "https://cdn.jsdelivr.net/npm/three-mesh-bvh@0.9.10/build/index.module.js",
"three-bvh-csg": "https://cdn.jsdelivr.net/npm/three-bvh-csg@0.0.18/build/index.module.js"
}
}
</script>import { init } from "@masabando/easy-three";<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>easy-three template</title>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.185.1/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.185.1/examples/jsm/",
"@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.min.js",
"@masabando/easy-three": "https://cdn.jsdelivr.net/gh/masabando/easy-three@1.15.0/dist/easy-three.js",
"three-mesh-bvh": "https://cdn.jsdelivr.net/npm/three-mesh-bvh@0.9.10/build/index.module.js",
"three-bvh-csg": "https://cdn.jsdelivr.net/npm/three-bvh-csg@0.0.18/build/index.module.js"
}
}
</script>
</head>
<body>
<script type="module">
import { init } from "@masabando/easy-three";
const { camera, create, animate, controls } = init();
controls.connect()
camera.position.set(-2, 2, 2)
create.ambientLight()
create.directionalLight()
create.cube()
animate()
</script>
</body>
</html>npx servepython3 -m http.server