惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security Affairs
Hacker News: Ask HN
Hacker News: Ask HN
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cyber Attacks, Cyber Crime and Cyber Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MyScale Blog
MyScale Blog
月光博客
月光博客
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
Martin Fowler
Martin Fowler
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recorded Future
Recorded Future
The GitHub Blog
The GitHub Blog
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
F
Full Disclosure
U
Unit 42
Jina AI
Jina AI
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
T
Troy Hunt's Blog
腾讯CDC
T
Threatpost
H
Hacker News: Front Page
P
Palo Alto Networks Blog
博客园 - 聂微东
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
Help Net Security
Help Net Security
L
LINUX DO - 热门话题
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy

博客园 - xgqfrms

xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs Remotion Video Maker All In One git worktree All In One Tesla 的车机使用什么技术来渲染汽车模型的? 宜家 VEVELSTAD 维维斯托床架 All In One macOS sysmond bug All In One The COF of LCD Monitor All In One Dell 显示器 S2419HM 灰屏 &花屏 All In One AI Harness Engineering All In One 电脑外接显示器天梯榜 All In One How to change the speed display unit of GSP from mph to km/h using GoPro Labs All In One WHCA 白宫记者协会 All In One Pascal Editor All In One 主流犬种图解指南 All In One 泡沫喷雾 & 辣椒喷雾 All In One 如何给身份证照片添加水印 All In One GoPro MISSION 1 PRO price All In One 杭州历史天气数据 All In One Pandoc All In One GoPro MISSION 1 SERIES All In One GoPro telemetry 中的 GPS5 与 GPS9 是什么 All In One xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs xgqfrms, cnblogs, blogs OpenCode All In One OpenClaw 设置 cron 定时任务 All In One free MongoDB Cloud API All In One 如何在 Raspberry Pi 安装 OpenClaw All In One free cloud LLM models API All In One Claude Code Free Video Tutorials All In One 如何解决 OpenClaw 升级后导致 feishu plugin 无法使用的问题 All In One Claude Code skills & plugins All In One LLM Benchmark All In One How to fix use the FileZilla FTP upload file error All In One
Three.js All In One
xgqfrms · 2026-06-04 · via 博客园 - xgqfrms

Three.js All In One

https://github.com/xgqfrms/three.js-all-in-one

3D renderer / 渲染器

Three.CanvasRenderer、Three.WebGLRenderer 和 Three.WebGPURenderer

THREE.CanvasRenderer ❌ (CanvasRenderingContext2D, HTML5 Canvas 2D)

image

const canvas = document.getElementById("myCanvas");
// Canvas 2D
const c2d = canvas.getContext("2d");

https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D

getContext(contextType)
getContext(contextType, contextAttributes)

image

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext

THREE.WebGLRenderer ✅ (WebGPU / WebGL 2)

image

const canvas = document.getElementById("myCanvas");
// WebGL
const gl = canvas.getContext("webgl");

https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API

https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext

image

const canvas = document.getElementById("myCanvas");
// WebGL 2
const gl2 = canvas.getContext("webgl2");

https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API#webgl_2

https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext

image

const canvas = document.querySelector("#gpuCanvas");
// WebGPU
const context = canvas.getContext("webgpu");

context.configure({
  device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  alphaMode: "premultiplied",
});

https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API

https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext

async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  let adapter;
  try {
    adapter = await navigator.gpu.requestAdapter();
  } catch (error) {
    console.error(error);
  }
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  const device = await adapter.requestDevice();

  // …
}

image

new generation of native GPU APIs have appeared — the most popular being Microsoft's Direct3D 12, Apple's Metal, and The Khronos Group's Vulkan.

image

three.js renderer ✅ (WebGPU / WebGL 2)

image

https://threejs.org/docs/#Renderer

https://threejs.org/docs/?q=Renderer#WebGPURenderer

https://threejs.org/docs/?q=Renderer#WebGLRenderer

image

https://chatgpt.com/c/6a28d448-cde4-83ea-a1f8-043190dcec61

How to use the modern renderer:

  1. Target an existing canvas:
    You can pass an existing HTML <canvas> element directly to the renderer's configuration to avoid having Three.js automatically inject one.
  2. Setup the render loop:
    Use requestAnimationFrame to continually draw the scene from the perspective of the camera.
// 1. Get a reference to your HTML canvas
const canvas = document.getElementById('myCanvas');

// 2. Set up the Scene, Camera, and Renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
// 复用已经存在的 canvas 画布,作为渲染器的容器 ✅
// 避免 three.js 自动插入一个新的 canvas 
const renderer = new THREE.WebGLRenderer({ canvas: canvas });

renderer.setSize(window.innerWidth, window.innerHeight);

// 3. Create a basic mesh and add it to the scene
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

camera.position.z = 5;

// 4. Create your render loop
function animate() {
    // renderer.setAnimationLoop 设置高性能循环动画,避免使用手动 requestAnimationFrame ✅
    // requestAnimationFrame(animate);
    cube.rotation.x += 0.01;
    cube.rotation.y += 0.01;
   renderer.render(scene, camera);
   // render();
}


// ✅
renderer.setAnimationLoop(animate);

// ❌
// animate();

// function render() {
//   renderer.render(scene, camera)
// }

image

image

https://threejs.org/docs/?q=animat#WebGLRenderer.setAnimationLoop

https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame

https://discourse.threejs.org/t/is-there-a-performance-difference-between-requestanimationframe-and-setanimationloop/27771

https://threejs-journey.com/lessons/animations

https://sbcode.net/threejs/animation-loop/
https://sbcode.net/threejs/render-loop/

The THREE.CanvasRenderer was a legacy module that allowed Three.js to render 3D scenes using the 2D Canvas API (CanvasRenderingContext2D) instead of WebGL.
It was officially removed from the core Three.js library over a decade ago.
If you are looking for how to render Three.js scenes into an HTML canvas today, you should use the modern THREE.WebGLRenderer instead.
It operates much faster by utilizing hardware acceleration.

THREE.CanvasRenderer 是一个旧模块,它允许 Three.js 使用 2D Canvas API (CanvasRenderingContext2D) 而非 WebGL 来渲染 3D 场景。
它已于十多年前从 Three.js 核心库中正式移除。
如果您现在想知道如何将 Three.js 场景渲染到 HTML Canvas 中,则应该使用现代的 THREE.WebGLRenderer
它利用硬件加速,运行速度更快。

image

Canvas - React Three Fiber

https://r3f.docs.pmnd.rs/api/canvas

· TresJS

https://docs.tresjs.org/api/components/tres-canvas

three.js

https://threejs.org/

https://threejs.org/manual/

https://threejs.org/docs/

https://threejs.org/editor/

https://github.com/mrdoob/three.js

versions

https://github.com/mrdoob/three.js/releases

latest version

https://github.com/mrdoob/three.js/releases/tag/r184

https://github.com/mrdoob/three.js/releases/tag/r137

https://github.com/mrdoob/three.js/releases/tag/r95

demos

https://jsfiddle.net/w43x5Lgh/

import * as THREE from 'three';

const width = window.innerWidth, height = window.innerHeight;

// init

const camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );
camera.position.z = 1;

const scene = new THREE.Scene();

const geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );
const material = new THREE.MeshNormalMaterial();

const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );

const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( width, height );
renderer.setAnimationLoop( animate );
document.body.appendChild( renderer.domElement );

// animation

function animate( time ) {

	mesh.rotation.x = time / 2000;
	mesh.rotation.y = time / 1000;

	renderer.render( scene, camera );

}

https://github.com/xgqfrms/WebGL

https://github.com/josdirksen/learning-threejs-third

https://www.cnblogs.com/xgqfrms/p/13765798.html

优秀案例

https://bruno-simon.com/

https://my-room-in-3d.vercel.app/

https://github.com/brunosimon/my-room-in-3d

https://www.cnblogs.com/xgqfrms/p/15869578.html

Blender

Blender 编辑器 修改语言

image

image

https://www.youtube.com/watch?v=wPhA0imjvVs

refs

https://github.com/web-full-stack/WebGPU

https://github.com/xgqfrms?tab=repositories&q=webgl&type=&language=&sort=

https://github.com/settings/organizations



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!