Skip to content

Commit

Permalink
question Block init
Browse files Browse the repository at this point in the history
  • Loading branch information
smarthug committed Oct 28, 2022
1 parent 95c670a commit 39d8a66
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 4 deletions.
Binary file added public/QuestionBlock.glb
Binary file not shown.
21 changes: 21 additions & 0 deletions public/assets/wasm/basis_transcoder.js

Large diffs are not rendered by default.

Binary file added public/assets/wasm/basis_transcoder.wasm
Binary file not shown.
48 changes: 48 additions & 0 deletions public/assets/wasm/draco_decoder.js

Large diffs are not rendered by default.

Binary file added public/assets/wasm/draco_decoder.wasm
Binary file not shown.
104 changes: 104 additions & 0 deletions public/assets/wasm/draco_wasm_wrapper.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body,
}

body {
background: lightblue;
/* background: lightblue; */
}


Expand Down
4 changes: 3 additions & 1 deletion src/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export * as kaijiPubUpgrade from './kaijiPubUpgrade'

export * as Multiplay from './multiplay'

export * as Theatre from './theatre'
export * as Theatre from './theatre'

export * as QuestionBlock from './questionBlock'
69 changes: 69 additions & 0 deletions src/page/questionBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as THREE from 'three'
import React, { useRef, useState } from 'react'
import { Canvas, useFrame, useThree } from '@react-three/fiber'

import { useEffect } from 'react'

import { OrbitControls, useGLTF, } from '@react-three/drei'

import GLTFLoader from '../util/gltfLoader'



export default function App() {
return (
<Canvas camera={{ position: [5, 5, -5] }} gl={{ preserveDrawingBuffer: true }}>
<Scene />
</Canvas>
)
}

function Scene() {

useEffect(() => {

}, [])
return (
<>
<hemisphereLight intensity={0.45} />
<spotLight angle={0.4} penumbra={1} position={[20, 30, 2.5]} castShadow shadow-bias={-0.00001} />
<directionalLight color="red" position={[-10, -10, 0]} intensity={1.5} />
<OrbitControls />

<Model />
</>

)
}






function Model(props) {
const group = useRef()
// const { nodes, materials } = useGLTF('https://vazxmixjsiawhamofees.supabase.co/storage/v1/object/public/models/star/model.gltf')
// const { scene } = useThree()
const { scene } = useGLTF('QuestionBlock.glb')



function handleClick() {
console.log("clicked");
}

useEffect(() => {
// GLTFLoader('QuestionBlock.glb').then((glb) => {
// glb.scale.set(0.1,0.1,0.1)
// scene.add(glb)
// })
}, [])
return (
<group ref={group} {...props} dispose={null}>
<primitive onClick={handleClick} object={scene}/>
</group>
)
}

useGLTF.preload('QuestionBlock.glb')
4 changes: 2 additions & 2 deletions src/page/theatre.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { useEffect } from 'react'

// create-react-app
if (process.env.NODE_ENV === 'development') {
studio.initialize()
studio.extend(extension)
// studio.initialize()
// studio.extend(extension)
}
// studio.initialize()
// studio.extend(extension)
Expand Down
27 changes: 27 additions & 0 deletions src/util/gltfLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import { KTX2Loader } from "three/examples/jsm/loaders/KTX2Loader.js";
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader.js";
import { MeshoptDecoder } from "three/examples/jsm/libs/meshopt_decoder.module.js";


export default function Loader(path) {
const loader = new GLTFLoader().setDRACOLoader(new DRACOLoader().setDecoderPath("assets/wasm/"))
.setKTX2Loader(new KTX2Loader().setTranscoderPath("assets/wasm/"))
.setMeshoptDecoder(MeshoptDecoder);

return new Promise((resolve) => {
loader.load(path, (gltf) => {
// console.log(gltf)
const scene = gltf.scene || gltf.scenes[0];
if (!scene) {
throw new Error(
"This model contains no scene, and cannot be viewed here. However," +
" it may contain individual 3D resources."
);
}

resolve(scene);
// resolve(gltf);
});
});
}

1 comment on commit 39d8a66

@vercel
Copy link

@vercel vercel bot commented on 39d8a66 Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

r3f-lab – ./

r3f-lab.vercel.app
r3f-lab-git-master-chunghosuk.vercel.app
r3f-lab-chunghosuk.vercel.app

Please sign in to comment.