From acf57854bab3d14b3947e988d6f2d24037f3cf1f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 16 May 2026 07:53:09 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20MicrotubuleTorus=20rende?= =?UTF-8?q?ring=20with=20InstancedMesh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimized the `MicrotubuleTorus` component in `components/QuantumScene.tsx` by replacing individual mesh rendering with `THREE.InstancedMesh`. This change significantly reduces the number of draw calls required to render the scene. - Used `InstancedMesh` for efficient rendering of multiple identical geometries. - Implemented a shared `THREE.Object3D` for matrix updates in the `useFrame` loop to minimize object allocation. - Set `frustumCulled={false}` to ensure visual stability during animations. - Set `args={[undefined, undefined, count]}` on `InstancedMesh` to follow React Three Fiber conventions. Co-authored-by: jason420247 <44763042+jason420247@users.noreply.github.com> --- components/QuantumScene.tsx | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 components/QuantumScene.tsx diff --git a/components/QuantumScene.tsx b/components/QuantumScene.tsx new file mode 100644 index 0000000..4ae1b69 --- /dev/null +++ b/components/QuantumScene.tsx @@ -0,0 +1,78 @@ +import React, { useMemo, useRef } from "react"; +import { useFrame } from "@react-three/fiber"; +import * as THREE from "three"; + +/** + * MicrotubuleTorus models hypothesized quantum-coherent structures within neurons. + * This component is optimized using InstancedMesh to minimize draw calls. + */ +const MicrotubuleTorus = ({ + radius, + count = 360, + offset = 0, + color = "#C5A059", + speed = 1, +}: { + radius: number; + count?: number; + offset?: number; + color?: string; + speed?: number; +}) => { + const meshRef = useRef(null); + const tempObject = useMemo(() => new THREE.Object3D(), []); + + const cubes = useMemo(() => { + const arr = []; + for (let i = 0; i < count; i++) { + const angle = (i / count) * Math.PI * 2 + offset; + const x = Math.cos(angle) * radius; + const y = Math.sin(angle) * radius; + arr.push({ x, y, angle }); + } + return arr; + }, [radius, count, offset]); + + useFrame((state) => { + if (!meshRef.current) return; + + const time = state.clock.getElapsedTime() * speed; + + for (let i = 0; i < cubes.length; i++) { + const cube = cubes[i]; + tempObject.position.set(cube.x, cube.y, Math.sin(time + i * 0.1) * 0.2); + tempObject.rotation.set(0, 0, cube.angle + time); + tempObject.updateMatrix(); + meshRef.current.setMatrixAt(i, tempObject.matrix); + } + meshRef.current.instanceMatrix.needsUpdate = true; + }); + + return ( + + + + + ); +}; + +export const QuantumScene = () => { + return ( + + + + + + + ); +};