Code Monkey home page Code Monkey logo

threejs-tutorial's Introduction

你好,我叫杨普晓,有 3 年 Threejs 开发经验,曾向 Three.js 贡献多个 PR,之前做过:

  • 3D点云立方体标注工具
  • 自动驾驶BEV联合标注工具
  • 2D拉框和多边形标注工具

目前就职于郑州某公司从事 基于浏览器的 3D标本解剖教学平台研发

我还会:React、Vue3、Nodejs、Electron、Taro、Uniapp...

若有交流需要,可通过下面方式与我联系:

threejs-tutorial's People

Contributors

5unnywind avatar kricn avatar puxiao avatar xsstomy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

threejs-tutorial's Issues

请教

大佬你是做3d开发么

膜拜大佬

膜拜奆佬,很清晰、详细的教程,期望复更!

03 编写HelloThreejs 章节发现文字书写有误

03 编写HelloThreejs 章节内发现有两处单词写错了,虽问题不大,但是看到了还是给楼主反馈下

位于:第3环节:创建Three.js基础3大元素、场景可见元素 > 基础3大元素:>场景 > Scen
位于:补充说明:你应该发现,除了 场景(Scen)、网格(Mesh) 之外,其他的元素我都注明 “本文示例采用的是...”。
Scene 误写成了 Scen 。

非常棒的教程

17节 对 requestAnimationFrame 的描述 有点点不同的见解哈
“也就是意味着,无论任何时候,我们都会在每一帧上进行场景渲染。”

setInterval 这类会一直定时执行
而 requestAnimationFrame 在浏览器标签页 或切换桌面的时候会自动停止 (电脑性能不足是也会 降帧率 > 16毫秒执行)

可以留个联系方式吗?

最近也在学习3d相关东西。(迫于需求不会写)希望留个联系方式 请教问题和某些实现思路

04 添加一些自适应.md

const handleResize = () => {
    const canvas = renderer.domElement
    camera.aspect = canvas.clientWidth / canvas.clientHeight
    camera.updateProjectionMatrix()

    renderer.setSize(canvas.clientWidth, canvas.clientHeight, false)
}
handleResize()

//我们不再添加 window resize 监控(观察)
- window.addEventListener('resize', handleResize)

//改为使用 ResizeObserver 来监控(观察)尺寸变化
+ const resizeObserver = new ResizeObserver(() => {
+     handleResize()
+ })
+ resizeObserver.observe(canvasRef.current)

//当我们卸载组件前,一定要 清除掉 监控(观察)
return () =>{
- window.removeEventListener('resize', resizeHandleRef.current)
+ resizeObserver.disconnect()
}

关于上段代码,是不是写的有一些问题,还是写的伪代码?。
resizeObserver 是在 useEffect 中创建的变量,需要使用 useRef 来勾住。 重新看了一下 useRef 的用法

需要在修改几处

const HelloThreejs: React.FC = () => {
    const canvasRef = useRef<HTMLCanvasElement>(null)
    - const resizeHandleRef = useRef<() => void>()
    + const resizeHandleRef = useRef<ResizeObserver>()
- resizeHandleRef.current = handleResize
//我们不再添加 window resize 监控(观察)
- window.addEventListener('resize', handleResize)

//改为使用 ResizeObserver 来监控(观察)尺寸变化
+ const resizeObserver = new ResizeObserver(() => {
+     handleResize()
+ })
+ resizeHandleRef.current = resizeObserver
+ resizeObserver.observe(canvasRef.current)

//当我们卸载组件前,一定要 清除掉 监控(观察)
return () =>{
-  window.removeEventListener('resize', resizeHandleRef.current)
+ resizeHandleRef.current?.disconnect()
}

关于示例代码中的小问题

大部分示例代码当中都会有诸如

useEffect(() => {
   // ...
}, [someRef])

<canvas ref={someRef}>

的代码

但实际上ref作为effect的dep并不安全。

官方建议使用

function MeasureExample() {
  const [height, setHeight] = useState(0);

  const measuredRef = useCallback(node => {
    if (node !== null) {
      setHeight(node.getBoundingClientRect().height);
    }
  }, []);

  return (
    <>
      <h1 ref={measuredRef}>Hello, world</h1>
      <h2>The above header is {Math.round(height)}px tall</h2>
    </>
  );
}

原文链接
is-it-safe-to-use-ref-current-as-useeffects-dependency-when-ref-points-to-a-dom
官网解释

并再次感谢你的教程

Feature | Translation needed 📋

About this issue

Hello @puxiao, I appreciated reading your tutorial and I believe many other people will think the same

But the main issue with your tutorial is that it's only in Chinese.
If an English version of this is released, I'm convinced it will help many ❤

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.