Skip to content

Commit

Permalink
fix(three): use Vector3, so mouse can take a z value
Browse files Browse the repository at this point in the history
  • Loading branch information
setsun committed Apr 5, 2019
1 parent 89c04bf commit 04a96f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"dist/index.js": {
"bundled": 24023,
"minified": 11383,
"gzipped": 4170,
"bundled": 24014,
"minified": 11375,
"gzipped": 4166,
"treeshaked": {
"rollup": {
"code": 9441,
"import_statements": 578
"code": 9428,
"import_statements": 565
},
"webpack": {
"code": 11003
Expand All @@ -16,6 +16,6 @@
"dist/index.cjs.js": {
"bundled": 27112,
"minified": 13128,
"gzipped": 4391
"gzipped": 4390
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"homepage": "https://github.com/drcmda/react-three-fiber#readme",
"dependencies": {
"@babel/runtime": "^7.4.3",
"@types/three": "^0.93.30",
"lodash-es": "^4.17.11",
"pointer-events-polyfill": "^0.4.4-pre",
"react-reconciler": "^0.20.1",
Expand All @@ -75,7 +76,6 @@
"@babel/preset-typescript": "^7.3.3",
"@types/lodash-es": "^4.17.3",
"@types/react": "^16.8.12",
"@types/three": "^0.93.30",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
Expand Down
4 changes: 3 additions & 1 deletion src/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Canvas = React.memo(
const [bind, size] = useMeasure()
const [intersects, setIntersects] = useState([])
const [raycaster] = useState(() => new THREE.Raycaster())
const [mouse] = useState(() => new THREE.Vector2())
const [mouse] = useState(() => new THREE.Vector3())
const [defaultCam, setDefaultCamera] = useState(() => {
const cam = new THREE.PerspectiveCamera(75, 0, 0.1, 1000)
cam.position.z = 5
Expand Down Expand Up @@ -168,7 +168,9 @@ export const Canvas = React.memo(
const canvasRect = state.current.canvasRect
const x = ((event.clientX - canvasRect.left) / (canvasRect.right - canvasRect.left)) * 2 - 1
const y = -((event.clientY - canvasRect.top) / (canvasRect.bottom - canvasRect.top)) * 2 + 1

mouse.set(x, y, 0.5)

raycaster.setFromCamera(mouse, state.current.camera)
}, [])

Expand Down

0 comments on commit 04a96f9

Please sign in to comment.