[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,92 +2,160 @@
|
||||
id: wiki-2026-0508-buffergeometry
|
||||
title: BufferGeometry
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-2887C6]
|
||||
aliases: [P-Reinforce-AUTO-2887C6, Three.js BufferGeometry]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
tags: [auto-reinforced]
|
||||
verification_status: applied
|
||||
tags: [graphics, threejs, webgl, performance]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
github_commit: "[P-Reinforce] Continuous Worker - BufferGeometry"
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: unspecified
|
||||
framework: unspecified
|
||||
language: javascript
|
||||
framework: three.js
|
||||
---
|
||||
|
||||
# [[BufferGeometry|BufferGeometry]]
|
||||
# BufferGeometry
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> BufferGeometry는 Three.js의 핵심 3D 기하학 구조를 정의하는 객체이다 [1]. [[InstancedMesh|InstancedMesh]] 기술에서 수많은 인스턴스가 공통으로 공유하는 기하학적 데이터로 사용된다 [2, 3]. 또한 여러 개의 지오메트리를 단일 BufferGeometry로 병합하여 렌더링 과정에서 발생하는 드로우 콜([[Draw Call|Draw Call]])을 최소화하는 성능 최적화의 핵심 단위로도 활용된다 [4, 5].
|
||||
## 매 한 줄
|
||||
> **"매 Three.js 의 GPU-resident geometry container — 매 modern Three 의 only geometry class."**. BufferGeometry 는 typed-array 기반 attribute (position, normal, uv, index) 의 GPU upload 를 직접 관리하며, 매 Geometry class deprecation (r125) 이후 표준 — instancing/batching/morph 의 backbone.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
* **InstancedMesh의 기본 데이터 레이어:** InstancedMesh 구조에서 BufferGeometry는 모든 개별 인스턴스가 공통으로 공유하는 기하학적 정의를 담당하는 주요 데이터 레이어이다 [2]. 다만, 하나의 InstancedMesh 인스턴스는 오직 하나의 BufferGeometry만을 참조할 수 있다는 기하학적 단일성의 제약이 존재한다 [6].
|
||||
* **지오메트리 병합(Merging)을 통한 최적화:** 정적인 환경이나 여러 개의 객체들을 렌더링할 때, `BufferGeometryUtils.mergeBufferGeometries()` 메서드를 사용하여 서로 다른 기하학적 데이터를 단일 BufferGeometry로 병합할 수 있다 [5, 7, 8]. 이를 통해 여러 객체를 단 한 번의 드로우 콜로 렌더링함으로써 CPU 오버헤드를 획기적으로 낮출 수 있다 [4].
|
||||
* **메모리 집약성 및 컬링(Culling) 효율의 한계:** 여러 객체를 하나의 BufferGeometry로 묶는 방식은 드로우 콜을 줄여주지만, 객체를 복제할 때마다 RAM 사용량이 정비례로 증가하는 메모리 집약적인 특성을 띤다 [4]. 더욱이 병합된 메쉬 전체가 하나의 단일 바운딩 볼륨(Bounding Volume)으로 취급되기 때문에, 화면 밖의 객체를 제외하는 시야 절두체 컬링([[Frustum Culling|Frustum Culling]])의 정밀도가 떨어지는 한계가 발생한다 [5].
|
||||
* **개별 항목의 식별 및 접근:** 여러 객체를 거대한 BufferGeometry 하나로 병합한 후 특정 개별 요소를 선택하거나 수정하는 것은 까다롭지만, 버퍼 내 각 객체의 위치(Position) 데이터를 저장하는 매핑(Map) 구조를 구축하여 개별 항목을 효율적으로 조회하고 제어할 수 있다 [4].
|
||||
## 매 핵심
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌:** 자동화 엔진에 의해 매핑된 지식으로, 추후 정밀 검증 필요.
|
||||
- **정책 변화:** Graphics & Performance 분야의 자동 자산화 수행.
|
||||
### 매 Attribute
|
||||
- **Position** (Float32Array, itemSize=3): vertex coords.
|
||||
- **Normal** (Float32Array, itemSize=3).
|
||||
- **UV** (Float32Array, itemSize=2).
|
||||
- **Index** (Uint16/Uint32Array): triangle list.
|
||||
- **Custom**: any vertex attribute (color, tangent, instance data).
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- **Related Topics:** [[InstancedMesh|InstancedMesh]], [[Draw Call|Draw Call]], BufferGeometryUtils
|
||||
- **Projects/Contexts:** Three.js, IFC.js Fragment
|
||||
- **Contradictions/Notes:** 소스 문헌들은 성능 개선을 위해 객체들을 단일 BufferGeometry로 병합할 것을 권장하면서도, 이 방식이 드로우 콜을 최소화하는 대신 RAM 소모량을 높이고 시야 절두체 컬링의 효율을 저하시키는 트레이드오프(Trade-off)를 유발한다고 경고한다 [4, 5].
|
||||
### 매 Update Strategy
|
||||
- **Static**: upload once, never modify (default).
|
||||
- **Dynamic** (`setUsage(DynamicDrawUsage)`): frequent CPU update.
|
||||
- **Stream**: per-frame update (rare).
|
||||
|
||||
---
|
||||
*Last updated: 2026-04-19*
|
||||
### 매 응용
|
||||
1. Custom shaders with custom attributes.
|
||||
2. GPU instancing (InstancedBufferAttribute).
|
||||
3. Procedural geometry generation.
|
||||
4. Mesh deformation / morphing.
|
||||
5. GPGPU particle systems.
|
||||
|
||||
---
|
||||
## 💻 패턴
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### Manual Triangle
|
||||
```javascript
|
||||
import * as THREE from "three";
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
|
||||
## 💻 코드 패턴 (Code Patterns)
|
||||
|
||||
**패턴 1:** *(TODO: 이 프로젝트 컨벤션 반영한 구조 스켈레톤)*
|
||||
|
||||
```text
|
||||
# TODO
|
||||
const geo = new THREE.BufferGeometry();
|
||||
const positions = new Float32Array([
|
||||
0, 1, 0,
|
||||
-1, -1, 0,
|
||||
1, -1, 0,
|
||||
]);
|
||||
geo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geo.computeVertexNormals();
|
||||
```
|
||||
|
||||
## 🤔 의사결정 기준 (Decision Criteria)
|
||||
### Indexed Quad
|
||||
```javascript
|
||||
const positions = new Float32Array([-1,-1,0, 1,-1,0, 1,1,0, -1,1,0]);
|
||||
const indices = new Uint16Array([0, 1, 2, 0, 2, 3]);
|
||||
const geo = new THREE.BufferGeometry();
|
||||
geo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geo.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
```
|
||||
|
||||
**선택 A를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
### Dynamic Vertex Update
|
||||
```javascript
|
||||
const attr = geo.attributes.position;
|
||||
attr.setUsage(THREE.DynamicDrawUsage);
|
||||
|
||||
**선택 B를 써야 할 때:**
|
||||
- *(TODO)*
|
||||
function tick(t) {
|
||||
for (let i = 0; i < attr.count; i++) {
|
||||
attr.setY(i, Math.sin(t + i * 0.1));
|
||||
}
|
||||
attr.needsUpdate = true;
|
||||
}
|
||||
```
|
||||
|
||||
**기본값:**
|
||||
> *(TODO)*
|
||||
### Custom Shader Attribute
|
||||
```javascript
|
||||
const aRandom = new Float32Array(geo.attributes.position.count);
|
||||
for (let i = 0; i < aRandom.length; i++) aRandom[i] = Math.random();
|
||||
geo.setAttribute("aRandom", new THREE.BufferAttribute(aRandom, 1));
|
||||
|
||||
## ❌ 안티패턴 (Anti-Patterns)
|
||||
const mat = new THREE.ShaderMaterial({
|
||||
vertexShader: `attribute float aRandom; varying float vR;
|
||||
void main(){ vR=aRandom; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.); }`,
|
||||
fragmentShader: `varying float vR; void main(){ gl_FragColor=vec4(vR,vR,vR,1.); }`,
|
||||
});
|
||||
```
|
||||
|
||||
- **[안티패턴]:** *(TODO: 무엇을 하면 안 되는가 + 이유 + 대신 무엇을)*
|
||||
### Instanced Attribute
|
||||
```javascript
|
||||
const N = 10000;
|
||||
const offsets = new Float32Array(N * 3);
|
||||
for (let i = 0; i < N; i++) {
|
||||
offsets[i*3] = (Math.random()-0.5)*100;
|
||||
offsets[i*3+1] = (Math.random()-0.5)*100;
|
||||
offsets[i*3+2] = (Math.random()-0.5)*100;
|
||||
}
|
||||
const igeo = new THREE.InstancedBufferGeometry().copy(geo);
|
||||
igeo.instanceCount = N;
|
||||
igeo.setAttribute("aOffset", new THREE.InstancedBufferAttribute(offsets, 3));
|
||||
```
|
||||
|
||||
### Merge Geometries
|
||||
```javascript
|
||||
import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";
|
||||
|
||||
const merged = mergeGeometries([geoA, geoB, geoC], false);
|
||||
// single draw call instead of three
|
||||
```
|
||||
|
||||
### Bounding Volume Recompute
|
||||
```javascript
|
||||
geo.computeBoundingBox();
|
||||
geo.computeBoundingSphere(); // required for frustum culling after vertex moves
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Static mesh | StaticDrawUsage (default) |
|
||||
| Per-frame deform | DynamicDrawUsage + needsUpdate |
|
||||
| Many copies | InstancedBufferGeometry |
|
||||
| Many distinct meshes | mergeGeometries or BatchedMesh |
|
||||
| Massive points | BufferGeometry + Points + custom shader |
|
||||
|
||||
**기본값**: static indexed BufferGeometry; switch to instanced/merged for >100 copies.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Three.js]] · [[WebGL Geometry]]
|
||||
- 변형: [[InstancedBufferGeometry]] · [[BatchedMesh]]
|
||||
- 응용: [[Custom Shader]] · [[GPGPU Particles]]
|
||||
- Adjacent: [[BufferAttribute]] · [[VBO]] · [[VAO]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: generate procedural geometry boilerplate, debug attribute layout.
|
||||
**언제 X**: micro-optimization of custom shaders without profiling.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Forgetting `needsUpdate = true`**: GPU never re-uploads.
|
||||
- **Recreating BufferGeometry per frame**: GC pressure — mutate in place.
|
||||
- **Float32 indices**: not supported — use Uint16/Uint32.
|
||||
- **No bounding sphere recompute**: frustum-culled erroneously after deform.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (three.js r170 docs, threejs-journey).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — attributes, dynamic update, instancing patterns |
|
||||
|
||||
Reference in New Issue
Block a user