From 5afa5d953c8eaaaaa2926e1a003fe861d416a180 Mon Sep 17 00:00:00 2001 From: Kurt Hutten Date: Tue, 10 Aug 2021 20:36:30 +1000 Subject: [PATCH] Add edges to models --- .../src/components/IdeViewer/IdeViewer.tsx | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/app/web/src/components/IdeViewer/IdeViewer.tsx b/app/web/src/components/IdeViewer/IdeViewer.tsx index 068defa..222768a 100644 --- a/app/web/src/components/IdeViewer/IdeViewer.tsx +++ b/app/web/src/components/IdeViewer/IdeViewer.tsx @@ -1,7 +1,14 @@ import { useIdeContext } from 'src/helpers/hooks/useIdeContext' +import * as THREE from 'three' import { useRef, useState, useEffect } from 'react' import { Canvas, useThree } from '@react-three/fiber' -import { PerspectiveCamera, useEdgeSplit, GizmoHelper, GizmoViewport, OrbitControls } from '@react-three/drei' +import { + PerspectiveCamera, + useEdgeSplit, + GizmoHelper, + GizmoViewport, + OrbitControls, +} from '@react-three/drei' import { Vector3 } from 'three' import { requestRender } from 'src/helpers/hooks/useIdeState' import texture from './dullFrontLitMetal.png' @@ -14,6 +21,11 @@ const colorMap = loader.load(texture) function Asset({ geometry: incomingGeo }) { const mesh = useEdgeSplit((12 * Math.PI) / 180, true) + const edges = React.useMemo( + () => + incomingGeo.length ? null : new THREE.EdgesGeometry(incomingGeo, 15), + [incomingGeo] + ) if (!incomingGeo) return null if (incomingGeo.length) @@ -22,9 +34,14 @@ function Asset({ geometry: incomingGeo }) { )) return ( - - - + + + + + + + + ) } @@ -99,11 +116,7 @@ function Controls({ onCameraChange, onDragStart, onInit }) { }, [camera, controls]) return ( - + ) } @@ -207,18 +220,11 @@ const IdeViewer = ({ Loading }) => { material-transparent rotation-x={Math.PI / 2} /> - - + + {state.objectData?.type === 'png' && ( <>