fix up axis

This commit is contained in:
Kurt Hutten IrevDev
2022-11-28 21:05:56 +11:00
parent 80f513401c
commit 1ed96ad7b6
4 changed files with 37 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import { Toolbar } from './Toolbar'
import { BasePlanes } from './components/BasePlanes' import { BasePlanes } from './components/BasePlanes'
import { SketchPlane } from './components/SketchPlane' import { SketchPlane } from './components/SketchPlane'
import { Logs } from './components/Logs' import { Logs } from './components/Logs'
import { AxisIndicator } from './components/AxisIndicator'
const OrrthographicCamera = OrthographicCamera as any const OrrthographicCamera = OrthographicCamera as any
@ -181,6 +182,7 @@ function App() {
)} )}
<BasePlanes /> <BasePlanes />
<SketchPlane /> <SketchPlane />
<AxisIndicator />
</Canvas> </Canvas>
</div> </div>
{guiMode.mode === 'codeError' && ( {guiMode.mode === 'codeError' && (

View File

@ -0,0 +1,16 @@
export const AxisIndicator = () => (
<>
<mesh position={[0.5, 0, 0]}>
<boxBufferGeometry args={[1, 0.05, 0.05]} />
<meshStandardMaterial color="red" />
</mesh>
<mesh position={[0, 0.5, 0]}>
<boxBufferGeometry args={[0.05, 1, 0.05]} />
<meshStandardMaterial color="blue" />
</mesh>
<mesh position={[0, 0, 0.5]}>
<boxBufferGeometry args={[0.05, 0.05, 1]} />
<meshStandardMaterial color="green" />
</mesh>
</>
)

View File

@ -2,6 +2,7 @@ import { useState } from 'react'
import { DoubleSide } from 'three' import { DoubleSide } from 'three'
import { useStore } from '../useStore' import { useStore } from '../useStore'
import { Intersection } from '@react-three/fiber' import { Intersection } from '@react-three/fiber'
import { Text } from '@react-three/drei'
import { addSketchTo, Program } from '../lang/abstractSyntaxTree' import { addSketchTo, Program } from '../lang/abstractSyntaxTree'
const opacity = 0.1 const opacity = 0.1
@ -51,11 +52,12 @@ export const BasePlanes = () => {
body: [], body: [],
} }
const { modifiedAst, id } = addSketchTo(_ast) const { modifiedAst, id } = addSketchTo(_ast)
const axis = axisIndex === 0 ? 'xy' : axisIndex === 1 ? 'xz' : 'yz'
setGuiMode({ setGuiMode({
mode: 'sketch', mode: 'sketch',
sketchMode: 'points', sketchMode: 'points',
axis: axisIndex === 0 ? 'yz' : axisIndex === 1 ? 'xy' : 'xz', axis,
id, id,
}) })
@ -86,6 +88,12 @@ export const BasePlanes = () => {
transparent transparent
opacity={opacity + (axisIndex === index ? 0.3 : 0)} opacity={opacity + (axisIndex === index ? 0.3 : 0)}
/> />
<Text fontSize={1} color="#555" position={[1, 1, 0.01]}>
{index === 0 ? 'xy' : index === 1 ? 'xz' : 'yz'}
</Text>
<Text fontSize={1} color="#555" position={[1, 1, -0.01]}>
{index === 0 ? 'xy' : index === 1 ? 'xz' : 'yz'}
</Text>
</mesh> </mesh>
))} ))}
</> </>

View File

@ -23,11 +23,11 @@ export const SketchPlane = () => {
const ninety = Math.PI / 2 const ninety = Math.PI / 2
const gridRotation: [number, number, number] = [0, 0, 0] const gridRotation: [number, number, number] = [0, 0, 0]
const clickDetectPlaneRotation: [number, number, number] = [0, 0, 0] const clickDetectPlaneRotation: [number, number, number] = [0, 0, 0]
if (guiMode.axis === 'yz') { if (guiMode.axis === 'xy') {
gridRotation[0] = ninety gridRotation[0] = ninety
} else if (guiMode.axis === 'xy') {
clickDetectPlaneRotation[0] = ninety
} else if (guiMode.axis === 'xz') { } else if (guiMode.axis === 'xz') {
clickDetectPlaneRotation[0] = ninety
} else if (guiMode.axis === 'yz') {
gridRotation[2] = ninety gridRotation[2] = ninety
clickDetectPlaneRotation[1] = ninety clickDetectPlaneRotation[1] = ninety
} }
@ -50,10 +50,13 @@ export const SketchPlane = () => {
end: 0, end: 0,
body: [], body: [],
} }
const { modifiedAst, id } = addLine(_ast, guiMode.id, [ let addLinePoint: [number, number] = [point.x, point.y]
point.x, if (guiMode.axis === 'xz') {
point.y, addLinePoint = [point.x, point.z]
]) } else if (guiMode.axis === 'yz') {
addLinePoint = [point.z, point.y]
}
const { modifiedAst, id } = addLine(_ast, guiMode.id, addLinePoint)
updateAst(modifiedAst) updateAst(modifiedAst)
}} }}
> >