diff --git a/CONVERSION_NOTES.md b/CONVERSION_NOTES.md new file mode 100644 index 0000000..7fc1e8c --- /dev/null +++ b/CONVERSION_NOTES.md @@ -0,0 +1,80 @@ +# CONVERSION_NOTES.md + +The following conversion notes are provided to assist +in the conversion of the app from `three.js` to `react-three-fiber` and `drei` + +------------------------ + +## Console Component +**The following was output by chatGPT w/ attached docs from the relevant libraries.** + +------------------------ + +To convert this code to use `react-three-fiber` and `drei`, you would need to create a `React` component that uses `CanvasTexture` from `drei`. + +Here's how you could do it: + +```js +import React, { useRef, useEffect } from 'react'; +import { CanvasTexture } from '@react-three/drei'; + +function ConsoleTexture({ width, height, text }) { + // Create a ref to store the canvas element + const canvasRef = useRef(); + + // Use the useEffect hook to perform side effects + useEffect(() => { + // Get the canvas element from the ref + const canvas = canvasRef.current; + + // Get the 2D rendering context from the canvas + const context = canvas.getContext('2d'); + + // Set the fill style to black + context.fillStyle = '#000'; + + // Fill the entire canvas with the fill style + context.fillRect(0, 0, width, height); + + // Set the font style and color for the text + context.font = 'bold 24px Menlo,Lucida Console,Courier New'; + context.fillStyle = '#fff'; + + // Draw the text on the canvas at position (20, 40) + context.fillText(text, 20, 40); + + // Create a new texture from the canvas + const texture = new CanvasTexture(canvas); + + // Mark the texture as needing an update + texture.needsUpdate = true; + + // Return a cleanup function to dispose of the texture + // when the component unmounts + return () => { + texture.dispose(); + }; + }, [width, height, text]); // Run effect whenever width, height, or text changes + + // Render a hidden canvas element + return ( + + ) +} + +// Export the ConsoleTexture component +export default ConsoleTexture; +``` + +------------------------ + +## Index.html Application +**The following was output by chatGPT w/ attached docs from the relevant libraries.** + +------------------------ + +I have been trying to get chatGPT to spit out code for the main application but it does not seem to want to co-operate. It keeps spitting back boilerplate code that is unrelated to the code here. diff --git a/index.html b/index.html index 0638967..1f47b81 100644 --- a/index.html +++ b/index.html @@ -26,7 +26,6 @@ } - @@ -35,11 +34,10 @@ "imports": { "react": "https://esm.sh/react", "react-dom": "https://esm.sh/react-dom/client", - "react-use-measure": "https://esm.sh/react-use-measure@2.1.1", "three": "https://esm.sh/three", "three-addons/": "https://esm.sh/three@0.156/examples/jsm/", - "@react-three/fiber": "https://esm.sh/@react-three/fiber@8.13.7", - "@react-three/drei": "https://esm.sh/@react-three/drei@9.80.9" + "@react-three/fiber": "https://esm.sh/@react-three/fiber", + "@react-three/drei": "https://esm.sh/@react-three/drei" } } @@ -70,7 +68,7 @@ mesh.rotation.set(time / 1000, time / 2000, 0); } - + @@ -260,7 +258,7 @@ // Create a console texture for displaying output consoleTexture = new ConsoleTexture(512 * 2, 64 * 2); let consoleMesh = new THREE.Mesh( - new THREE.PlaneBufferGeometry(0.5, 0.0625), + new THREE.PlaneGeometry(0.5, 0.0625), new THREE.MeshBasicMaterial({ map: consoleTexture.getTexture() }) ); @@ -310,6 +308,43 @@ } } + // This function handles the start of a selection event + function onSelectStart(event) { + // Get the controller that triggered the event + let controller = event.target; + + // Get the intersections between the controller and the draggable objects + let intersections = getIntersections(controller); + + // If there are intersections + if (intersections.length > 0) { + // Get the first intersection + let intersection = intersections[0]; + + // Get the object from the intersection + let object = intersection.object; + + // If the controller is being squeezed and the object is not the code editor + if (controller.userData.isSqueezing && object.name !== "editor") { + // Clone the object + object = object.clone(); + + // Add the cloned object to the list of draggable objects and viewers + draggables.push(object); + viewers.push(object); + + // Compile the code + compile(); + } + + // Attach the object to the controller + controller.attach(object); + + // Set the selected object in the controller's user data + controller.userData.selected = object; + } + } + // Handle the end of controller selection function onSelectEnd(event) { // Get the controller diff --git a/package.json b/package.json deleted file mode 100644 index a48d27b..0000000 --- a/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "xrcode", - "version": "1.0.0", - "description": "Standalone R3F 100 percent clientside", - "main": "index.js", - "scripts": { - "dev": "vite", - "build": "vite build" - }, - "keywords": [], - "author": "", - "license": "ISC", - "devDependencies": { - "vite": "^4.4.9" - } -} diff --git a/vite.config.js b/vite.config.js deleted file mode 100644 index 63b8f25..0000000 --- a/vite.config.js +++ /dev/null @@ -1,8 +0,0 @@ -// vite.config.js -import { defineConfig } from "vite"; - -export default defineConfig({ - build: { - outDir: "dist", // Output directory for the built files - }, -});