diff --git a/public/scene.bin b/public/earth.bin similarity index 100% rename from public/scene.bin rename to public/earth.bin diff --git a/public/earth.gltf b/public/earth.gltf index 4669d87..b6b4f0e 100644 --- a/public/earth.gltf +++ b/public/earth.gltf @@ -91,7 +91,7 @@ "buffers": [ { "byteLength": 1840512, - "uri": "scene.bin" + "uri": "earth.bin" } ], "images": [ diff --git a/public/obj.bin b/public/obj.bin new file mode 100644 index 0000000..924dfee Binary files /dev/null and b/public/obj.bin differ diff --git a/public/obj.gltf b/public/obj.gltf new file mode 100644 index 0000000..f546fb2 --- /dev/null +++ b/public/obj.gltf @@ -0,0 +1,1004 @@ +{ + "accessors": [ + { + "bufferView": 2, + "componentType": 5126, + "count": 23398, + "max": [ + 0.9271886348724365, + 2.293333053588867, + 0.2006075382232666 + ], + "min": [ + -0.927188515663147, + -2.2933332920074463, + -0.2006075382232666 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 280776, + "componentType": 5126, + "count": 23398, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "componentType": 5126, + "count": 23398, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "componentType": 5126, + "count": 23398, + "max": [ + 1.0, + 1.0 + ], + "min": [ + 0.0, + 0.0 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "componentType": 5125, + "count": 138132, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 561552, + "componentType": 5126, + "count": 23908, + "max": [ + 0.927188515663147, + 2.293333053588867, + 0.200607568025589 + ], + "min": [ + -0.9271888136863708, + -2.293333053588867, + -0.2006075382232666 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 848448, + "componentType": 5126, + "count": 23908, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 374368, + "componentType": 5126, + "count": 23908, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 187184, + "componentType": 5126, + "count": 23908, + "max": [ + 0.9857445359230042, + 0.999355673789978 + ], + "min": [ + 0.00018692176672630012, + 0.00018690332944970578 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 552528, + "componentType": 5125, + "count": 138132, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 1135344, + "componentType": 5126, + "count": 24804, + "max": [ + 0.9808600544929504, + 2.293333053588867, + 0.2122199535369873 + ], + "min": [ + -0.9808601140975952, + -2.293333053588867, + -0.2122199535369873 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 1432992, + "componentType": 5126, + "count": 24804, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 756896, + "componentType": 5126, + "count": 24804, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 378448, + "componentType": 5126, + "count": 24804, + "max": [ + 1.0, + 1.0 + ], + "min": [ + 0.0, + 0.0 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 1105056, + "componentType": 5125, + "count": 146412, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 1730640, + "componentType": 5126, + "count": 8110, + "max": [ + 0.927188515663147, + 0.6582937240600586, + 0.2006075531244278 + ], + "min": [ + -0.927188515663147, + -0.6582937836647034, + -0.2006075382232666 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 1827960, + "componentType": 5126, + "count": 8110, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 1153760, + "componentType": 5126, + "count": 8110, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 576880, + "componentType": 5126, + "count": 8110, + "max": [ + 1.0, + 1.0 + ], + "min": [ + 0.0, + 0.0 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 1690704, + "componentType": 5125, + "count": 47028, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 1925280, + "componentType": 5126, + "count": 65532, + "max": [ + 0.9272224307060242, + 0.6583656668663025, + 0.2074504941701889 + ], + "min": [ + -0.9064251780509949, + -0.658829927444458, + -0.20060968399047852 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 2711664, + "componentType": 5126, + "count": 65532, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -0.8809476494789124, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 1283520, + "componentType": 5126, + "count": 65532, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 641760, + "componentType": 5126, + "count": 65532, + "max": [ + 0.9732668995857239, + 0.9996275305747986 + ], + "min": [ + 0.00017796149768400937, + 0.0008601666777394712 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 1878816, + "componentType": 5125, + "count": 381678, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 3498048, + "componentType": 5126, + "count": 12756, + "max": [ + 0.9252811670303345, + 0.6582937240600586, + 0.20667554438114166 + ], + "min": [ + -0.9279018640518188, + -0.6576156616210938, + -0.20107440650463104 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 3651120, + "componentType": 5126, + "count": 12756, + "max": [ + 0.98578941822052, + 0.9999775886535645, + 1.0 + ], + "min": [ + -1.0, + -0.9983597993850708, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 2332032, + "componentType": 5126, + "count": 12756, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 1166016, + "componentType": 5126, + "count": 12756, + "max": [ + 0.972216010093689, + 0.9991939067840576 + ], + "min": [ + 0.010160223580896854, + 0.0031535394955426455 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 3405528, + "componentType": 5125, + "count": 67260, + "type": "SCALAR" + }, + { + "bufferView": 2, + "byteOffset": 3804192, + "componentType": 5126, + "count": 8308, + "max": [ + 0.927188515663147, + 0.6582937240600586, + 0.2006075382232666 + ], + "min": [ + -0.9271884560585022, + -0.6582937240600586, + -0.2006075382232666 + ], + "type": "VEC3" + }, + { + "bufferView": 2, + "byteOffset": 3903888, + "componentType": 5126, + "count": 8308, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 3, + "byteOffset": 2536128, + "componentType": 5126, + "count": 8308, + "max": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "min": [ + 0.1921568661928177, + 0.24705882370471954, + 0.3843137323856354, + 1.0 + ], + "type": "VEC4" + }, + { + "bufferView": 1, + "byteOffset": 1268064, + "componentType": 5126, + "count": 8308, + "max": [ + 0.8767929077148438, + 0.9995442628860474 + ], + "min": [ + 0.00045574468094855547, + 0.0006871276418678463 + ], + "type": "VEC2" + }, + { + "bufferView": 0, + "byteOffset": 3674568, + "componentType": 5125, + "count": 47028, + "type": "SCALAR" + } + ], + "asset": { + "extras": { + "author": "SerDante (https://sketchfab.com/streetvolf69)", + "license": "CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/)", + "source": "https://sketchfab.com/3d-models/qs-acbfa9e466034e2fa8b3be687da1c29a", + "title": "Qs" + }, + "generator": "Sketchfab-16.28.0", + "version": "2.0" + }, + "bufferViews": [ + { + "buffer": 0, + "byteLength": 3862680, + "name": "floatBufferViews", + "target": 34963 + }, + { + "buffer": 0, + "byteLength": 1334528, + "byteOffset": 3862680, + "byteStride": 8, + "name": "floatBufferViews", + "target": 34962 + }, + { + "buffer": 0, + "byteLength": 4003584, + "byteOffset": 5197208, + "byteStride": 12, + "name": "floatBufferViews", + "target": 34962 + }, + { + "buffer": 0, + "byteLength": 2669056, + "byteOffset": 9200792, + "byteStride": 16, + "name": "floatBufferViews", + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 11869848, + "uri": "obj.bin" + } + ], + "materials": [ + { + "doubleSided": true, + "name": "material_0", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + }, + { + "doubleSided": true, + "name": "material_1", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + }, + { + "doubleSided": true, + "name": "material_2", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + }, + { + "doubleSided": true, + "name": "material_3", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + }, + { + "doubleSided": true, + "name": "material_4", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + }, + { + "doubleSided": true, + "name": "material_5", + "pbrMetallicRoughness": { + "metallicFactor": 0.0, + "roughnessFactor": 0.25 + } + } + ], + "meshes": [ + { + "name": "Object_0", + "primitives": [ + { + "attributes": { + "COLOR_0": 2, + "NORMAL": 1, + "POSITION": 0, + "TEXCOORD_0": 3 + }, + "indices": 4, + "material": 0, + "mode": 4 + } + ] + }, + { + "name": "Object_1", + "primitives": [ + { + "attributes": { + "COLOR_0": 7, + "NORMAL": 6, + "POSITION": 5, + "TEXCOORD_0": 8 + }, + "indices": 9, + "material": 1, + "mode": 4 + } + ] + }, + { + "name": "Object_2", + "primitives": [ + { + "attributes": { + "COLOR_0": 12, + "NORMAL": 11, + "POSITION": 10, + "TEXCOORD_0": 13 + }, + "indices": 14, + "material": 2, + "mode": 4 + } + ] + }, + { + "name": "Object_3", + "primitives": [ + { + "attributes": { + "COLOR_0": 17, + "NORMAL": 16, + "POSITION": 15, + "TEXCOORD_0": 18 + }, + "indices": 19, + "material": 3, + "mode": 4 + } + ] + }, + { + "name": "Object_4", + "primitives": [ + { + "attributes": { + "COLOR_0": 22, + "NORMAL": 21, + "POSITION": 20, + "TEXCOORD_0": 23 + }, + "indices": 24, + "material": 4, + "mode": 4 + } + ] + }, + { + "name": "Object_5", + "primitives": [ + { + "attributes": { + "COLOR_0": 27, + "NORMAL": 26, + "POSITION": 25, + "TEXCOORD_0": 28 + }, + "indices": 29, + "material": 4, + "mode": 4 + } + ] + }, + { + "name": "Object_6", + "primitives": [ + { + "attributes": { + "COLOR_0": 32, + "NORMAL": 31, + "POSITION": 30, + "TEXCOORD_0": 33 + }, + "indices": 34, + "material": 5, + "mode": 4 + } + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 0.0, + -1.0, + 0.0, + 0.0, + -1.0, + 4.930380657631324e-32, + -2.220446049250313e-16, + 0.0, + 2.220446049250313e-16, + 0.0, + -1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ], + "name": "Sketchfab_model" + }, + { + "children": [ + 2 + ], + "name": "root" + }, + { + "children": [ + 3, + 5, + 8, + 10, + 12, + 15 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 2.220446049250313e-16, + 1.0, + 0.0, + 0.0, + -1.0, + 2.220446049250313e-16, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ], + "name": "GLTF_SceneRootNode" + }, + { + "children": [ + 4 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + -0.427188515663147, + 1.7933330535888672, + -0.2993924021720886, + 1.0 + ], + "name": "Box_0" + }, + { + "mesh": 0, + "name": "Object_4" + }, + { + "children": [ + 6 + ], + "matrix": [ + 0.0, + 1.3116586208343506, + 1.563618923228205e-07, + 0.0, + 0.10756995528936386, + -1.1920931797249068e-07, + 0.9941977858543396, + 0.0, + 0.9941975474357605, + 0.0, + -0.10756993293762207, + 0.0, + -1.5239461660385132, + 2.409820795059204, + -0.0030484506860375404, + 1.0 + ], + "name": "_nomad_unskew_1" + }, + { + "children": [ + 7 + ], + "matrix": [ + -0.0055626630783081055, + -0.9939767718315125, + 0.10945022106170654, + 0.0, + 0.9999749660491943, + -0.006008147727698088, + -0.003740358864888549, + 0.0, + 0.0043754130601882935, + 0.10942667722702026, + 0.9939852356910706, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ], + "name": "Box 4_2" + }, + { + "mesh": 1, + "name": "Object_7" + }, + { + "children": [ + 9 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + -0.427188515663147, + 1.7933330535888672, + -0.7007943391799927, + 1.0 + ], + "name": "Box 3_3" + }, + { + "mesh": 2, + "name": "Object_9" + }, + { + "children": [ + 11 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + -0.39584922790527344, + 4.769798278808594, + -0.2993924021720886, + 1.0 + ], + "name": "Box 1_4" + }, + { + "mesh": 3, + "name": "Object_11" + }, + { + "children": [ + 13, + 14 + ], + "matrix": [ + -1.5497207641601563e-06, + -0.9999999403953552, + -2.562999725341797e-06, + 0.0, + 0.4999985098838806, + 1.430511474609375e-06, + -0.8660262227058411, + 0.0, + 0.8660321831703186, + -2.622622560011223e-06, + 0.5000019669532776, + 0.0, + -0.9344461560249329, + 0.36328479647636414, + 0.6094061732292175, + 1.0 + ], + "name": "Box 5_5" + }, + { + "mesh": 4, + "name": "Object_13" + }, + { + "mesh": 5, + "name": "Object_14" + }, + { + "children": [ + 16 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + -0.38581031560897827, + 4.769798278808594, + -0.7205871343612671, + 1.0 + ], + "name": "Box 2_6" + }, + { + "mesh": 6, + "name": "Object_16" + } + ], + "scene": 0, + "scenes": [ + { + "name": "Sketchfab_Scene", + "nodes": [ + 0 + ] + } + ] +} diff --git a/src/App.tsx b/src/App.tsx index e2fd3c2..e643be6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,10 +2,12 @@ import {useCallback, useRef, useState} from "react"; import {Camera} from "react-camera-pro"; import "./App.css"; import {EarthCanvas} from "./EarchCanvas"; +import {ObjCanvas} from "./ObjCanvas"; function App() { const [view, setView] = useState<'3d' | 'camera'>('3d'); const [image, setImage] = useState(null); + const [model, setModel] = useState<'earth' | 'sofa'>('earth'); const onOpenCamera = () => { setView(view === 'camera' ? '3d' : 'camera'); @@ -15,12 +17,20 @@ function App() { webcamRef.current.switchCamera(); } + const onChangeObject = (val: any) => { + setModel(val); + }; + const webcamRef = useRef(null); const cameraCanvasRef = useRef(null); const overlayCanvasRef = useRef(null); const resultCanvasRef = useRef(null); const downloadLinkRef = useRef(null); + const onBack = () => { + setView('3d'); + }; + const handleTakePhoto = useCallback(() => { const imageSrc = webcamRef.current.takePhoto(); const cameraCanvas = cameraCanvasRef.current; @@ -52,13 +62,31 @@ function App() { }; }, [webcamRef, cameraCanvasRef, overlayCanvasRef, resultCanvasRef]); + let Component: any = null; + if (model === 'earth') { + Component = EarthCanvas; + } + if (model === 'sofa') { + Component = ObjCanvas; + } + return (

Example of 3d model on the Canvas

- +
+
+ + +
+
+ +
+ +
+
- +
+ + +
+ { - - +
) } diff --git a/src/Obj.tsx b/src/Obj.tsx new file mode 100644 index 0000000..62eadd6 --- /dev/null +++ b/src/Obj.tsx @@ -0,0 +1,50 @@ +/* +Auto-generated by: https://github.com/pmndrs/gltfjsx +Command: npx gltfjsx@6.5.0 obj.gltf +Author: SerDante (https://sketchfab.com/streetvolf69) +License: CC-BY-4.0 (http://creativecommons.org/licenses/by/4.0/) +Source: https://sketchfab.com/3d-models/qs-acbfa9e466034e2fa8b3be687da1c29a +Title: Qs +*/ + +import {useRef} from 'react' +import {useGLTF} from '@react-three/drei' +import {useFrame} from "@react-three/fiber"; + +export function Obj(props: any) { + const {nodes, materials}: any = useGLTF(import.meta.env.BASE_URL + 'obj.gltf'); + + const objRef = useRef(); + + useFrame((_, delta) => { + objRef.current.rotation.y += 0.2 * delta + }) + + return ( + + + + + + + + + + + + + + + + + + ) +} + +useGLTF.preload(import.meta.env.BASE_URL + '/obj.gltf') diff --git a/src/ObjCanvas.tsx b/src/ObjCanvas.tsx new file mode 100644 index 0000000..aeab062 --- /dev/null +++ b/src/ObjCanvas.tsx @@ -0,0 +1,19 @@ +import {Canvas} from "@react-three/fiber"; +import {Environment, OrbitControls} from "@react-three/drei"; +import {forwardRef, Suspense} from "react"; +import {Obj} from "./Obj"; + + +export const ObjCanvas = forwardRef(function (props: any, ref) { + return ( + + + + + + + + + ); +}); \ No newline at end of file