threejs-core-scene-graph

Manages Three.js scene graphs, object hierarchies, traversal, layers, and fog configuration.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-core-scene-graph-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-core-scene-graph
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-core-scene-graph
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-core-scene-graph-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three, and includes references (resource) components.

What problem does it solve? Building Three.js scenes involves subtle pitfalls: objects jumping position when reparented with add() instead of attach(), stale matrixWorld reads, GPU memory leaks from undisposed geometries, and skipped objects when mutating children during traversal. This Skill provides the correct patterns and API references to avoid these mistakes. ## Core Features & Use Cases - Hierarchy Management: Correct usage of add(), remove(), attach(), clear(), and traversal methods for Object3D, Scene, Group, and Mesh. - Matrix & Coordinate Systems: Guidance on matrixAutoUpdate, updateWorldMatrix, and local-to-world coordinate conversion without stale reads. - Scene Configuration: Setup of Scene background, environment IBL, linear and exponential Fog, and the 32-bit Layers bitmask for selective rendering. - Use Case: When moving a mesh between two transformed groups, use attach() instead of add() so the object preserves its world position instead of visually jumping. ## Quick Start Ask the AI to create a Three.js scene with grouped objects, fog, and layer-based selective rendering following the scene graph best practices.

Frequently Asked Questions about threejs-core-scene-graph

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What is the difference between add() and attach() in Three.js?

add() preserves the object's local transform, so reparenting changes its world position and the object visually jumps. attach() recalculates the local transform to preserve the world position, keeping the object in place when moved to a new parent.

How do I remove all children from a Three.js Group?

Call group.clear() to remove all children safely. Avoid forward for-loop removal, which skips elements due to index shifting; if selectively removing, iterate backwards or collect targets first then remove them.

Why does my Three.js object render at the wrong position after changing position?

matrixWorld is only recalculated during render or explicit updates, so reading it mid-frame returns stale values. Call updateWorldMatrix(true, false) before reading, or use getWorldPosition() which updates internally.

Does removing a mesh from the scene free GPU memory in Three.js?

No. remove() and clear() only detach objects from the scene graph. You must explicitly call dispose() on geometries, materials, and textures to free GPU memory, and clear any Three.js objects stored in userData.

How do Three.js Layers work for selective rendering?

Layers are a 32-bit bitmask; objects render only when their layers overlap the camera's layers. Use layers.enable(n) to add a layer without removing others, since layers.set(n) replaces the entire bitmask with only that layer.

Why is my custom ShaderMaterial not affected by scene fog?

ShaderMaterial and RawShaderMaterial default to fog: false. You must set fog: true in the material options and manually include the fog shader chunks in your custom shader code for fog to apply.