Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions CONVERSION_NOTES.md
Original file line number Diff line number Diff line change
@@ -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 (
<canvas
ref={canvasRef}
width={width}
height={height}
style={{ display: 'none' }} />
)
}

// 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.
47 changes: 41 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
}
</style>
<!-- Babel + Shim + Imports -->
<!-- ! Consider switching to HTM instead of using Babel ?
<!-- ! (https://docs.pmnd.rs/react-three-fiber/getting-started/installation#without-build-tools) -->
<script src="https://unpkg.com/@babel/standalone@7.22.14/babel.min.js"></script>
<!-- * * ESM.sh gives us a great CDN for ESM modules w/ lots of options! **/ -->
Expand All @@ -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"
}
}
</script>
Expand Down Expand Up @@ -70,7 +68,7 @@
mesh.rotation.set(time / 1000, time / 2000, 0);
}
</pre>
<!-- Include code editor dependcies for the 3D environment -->
<!-- Include code editor dependcies -->
<script src="js/textor/texteditor.js"></script>
<script src="js/textor/javascript.js"></script>

Expand Down Expand Up @@ -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() })
);

Expand Down Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions package.json

This file was deleted.

8 changes: 0 additions & 8 deletions vite.config.js

This file was deleted.