Skip to content
cccskills
FreePublished on GitHub

webgl-3d-object

Add a real 3D object to a web page using Three.js. Combine geometric depth, materials that respond to light, perspective, and subtle rotation or floating motion for hero sections and product visuals.

OriginalShow the original description

Create a real 3D WebGL object with geometric mesh depth, physically based material, directional and ambient lighting, perspective camera, subtle rotation, and floating motion. Use when a page needs a faceted 3D hero object or product-like visual with real lighting instead of CSS transform tricks.

See how to install

Good for

  • Adding a faceted 3D object to a hero section
  • Creating metal or ceramic-looking product visuals
  • Adding subtle rotation and floating motion to web layouts
  • Handling resizing and cleanup for embedded 3D visuals

Files included (12)

  • SKILL.md6.4 KB
  • demo/assets/page-01-4734259a-bad7-422f-981e-ce01e79184f2-1600w.jpg43.7 KB
  • demo/assets/page-02-724142aa-44a6-48d3-9cf3-761e00d05b78-1600w.jpg966.2 KB
  • demo/assets/page-03-fa51902b-c2a4-4c33-a96e-a8f1ef67edc6-1600w.jpg46.4 KB
  • demo/assets/page-04-005600e5-f6ab-4e59-bc86-eaeb02797dfa-1600w.jpg711.5 KB
  • demo/assets/page-05-5ee0a38a-b5d3-4531-8793-98beed4af162-1600w.jpg519.5 KB
  • demo/assets/page-06-5ee0a38a-b5d3-4531-8793-98beed4af162-1600w.jpg519.5 KB
  • demo/assets/source-preview.jpg53.5 KB
  • demo/index.html58.2 KB
  • demo/preview.jpg61.2 KB
  • demo/PROMPT.md3.2 KB
  • demo/source.json3.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

WebGL 3D Object

Use When

  • A hero, feature block, or product moment needs one strong 3D object.
  • The visual should show real geometry, lighting, highlights, and edges.
  • A faceted mesh should float or rotate subtly inside a web layout.
  • CSS transforms, SVG illusions, or flat gradients are not enough.

Rules

  1. Use real 3D geometry: IcosahedronGeometry, DodecahedronGeometry, BoxGeometry, custom BufferGeometry, or a glTF mesh.
  2. Use a perspective camera so the object has depth and scale.
  3. Use PBR material: MeshStandardMaterial or MeshPhysicalMaterial.
  4. Tune metalness, roughness, and emissive to match the brand mood.
  5. Light the object with at least one directional light plus ambient or hemisphere fill.
  6. Animate transforms only: subtle rotation, bobbing, or parallax.
  7. Handle resize and dispose geometry/material/renderer on teardown.

HTML And CSS

<div class="webgl-object-shell">
  <canvas class="webgl-object-canvas" data-webgl-3d-object></canvas>
</div>
.webgl-object-shell {
  position: relative;
  width: min(100%, 720px);
  aspect-ratio: 1 / 1;
}

.webgl-object-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

Three.js Object Recipe

import * as THREE from "three";

function initWebGL3DObject(canvas, options = {}) {
  if (!canvas) return () => {};

  const renderer = new THREE.WebGLRenderer({
    canvas,
    antialias: true,
    alpha: true,
  });
  renderer.setClearColor(0x000000, 0);
  renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, options.maxDpr || 1.75));
  renderer.outputColorSpace = THREE.SRGBColorSpace;
  renderer.toneMapping = THREE.ACESFilmicToneMapping;
  renderer.toneMappingExposure = options.exposure || 1.05;
  renderer.shadowMap.enabled = true;
  renderer.shadowMap.type = THREE.PCFSoftShadowMap;

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
  camera.position.set(0, 0.15, 5.2);

  const geometry = new THREE.IcosahedronGeometry(options.radius || 1.35, options.detail || 1);
  const material = new THREE.MeshStandardMaterial({
    color: options.color || 0x8aa4ff,
    metalness: options.metalness ?? 0.48,
    roughness: options.roughness ?? 0.34,
    emissive: options.emissive || 0x101833,
    emissiveIntensity: options.emissiveIntensity ?? 0.22,
    flatShading: true,
  });

  const object = new THREE.Mesh(geometry, material);
  object.castShadow = true;
  object.receiveShadow = true;
  scene.add(object);

  const ambient = new THREE.AmbientLight(0xffffff, 0.38);
  scene.add(ambient);

  const key = new THREE.DirectionalLight(0xffffff, 2.15);
  key.position.set(3.4, 4.2, 4.8);
  key.castShadow = true;
  key.shadow.mapSize.set(1024, 1024);
  scene.add(key);

  const rim = new THREE.DirectionalLight(options.rimColor || 0x7dd3fc, 0.82);
  rim.position.set(-4.2, 1.2, -2.8);
  scene.add(rim);

  const shadowPlane = new THREE.Mesh(
    new THREE.PlaneGeometry(5.2, 5.2),
    new THREE.ShadowMaterial({ opacity: 0.18 })
  );
  shadowPlane.position.set(0, -1.65, 0);
  shadowPlane.rotation.x = -Math.PI / 2;
  shadowPlane.receiveShadow = true;
  scene.add(shadowPlane);

  const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  let rafId = 0;

  function resize() {
    const width = Math.max(1, canvas.clientWidth);
    const height = Math.max(1, canvas.clientHeight);
    renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, options.maxDpr || 1.75));
    renderer.setSize(width, height, false);
    camera.aspect = width / height;
    camera.updateProjectionMatrix();
  }

  function render(time = 0) {
    const t = time * 0.001;
    object.rotation.x = -0.16 + Math.sin(t * 0.45) * 0.06;
    object.rotation.y = t * 0.28;
    object.rotation.z = Math.sin(t * 0.32) * 0.08;
    object.position.y = reduceMotion ? 0 : Math.sin(t * 0.8) * 0.08;

    renderer.render(scene, camera);
    if (!reduceMotion) rafId = requestAnimationFrame(render);
  }

  function handleResize() {
    cancelAnimationFrame(rafId);
    resize();
    render();
  }

  resize();
  render();
  window.addEventListener("resize", handleResize);

  return () => {
    cancelAnimationFrame(rafId);
    window.removeEventListener("resize", handleResize);
    geometry.dispose();
    material.dispose();
    shadowPlane.geometry.dispose();
    shadowPlane.material.dispose();
    renderer.dispose();
  };
}

const cleanupObject = initWebGL3DObject(
  document.querySelector("[data-webgl-3d-object]"),
  {
    color: 0x8aa4ff,
    rimColor: 0x7dd3fc,
    metalness: 0.48,
    roughness: 0.34,
    emissive: 0x101833,
  }
);

Material Defaults

  • Premium metal: metalness: 0.45-0.7, roughness: 0.25-0.45.
  • Soft ceramic: metalness: 0.0-0.15, roughness: 0.38-0.62.
  • Glow-tinted tech object: low emissive with emissiveIntensity: 0.12-0.35.
  • Faceted object: set flatShading: true; smooth product object: set it to false.

Lighting Defaults

  • Key light: directional, high front-side angle, strongest source.
  • Ambient fill: low intensity so shadows stay visible.
  • Rim light: brand-tinted or cool light from behind to reveal edges.
  • Shadows: enable only when the object needs grounded depth; keep map size moderate.

Motion Defaults

  • Rotation: slow, continuous, and secondary to the page content.
  • Floating: 0.04 to 0.12 units on Y.
  • Reduced motion: render a still frame or only allow direct interaction.
  • Avoid camera movement unless the object is the main interaction.

Avoid

  • CSS 3D transforms pretending to be WebGL.
  • Unlit materials when the ask is real lighting and depth.
  • Flat planes with gradients instead of actual geometry.
  • Strong bloom or particles that hide the form.
  • High DPR, huge shadow maps, or too many lights on mobile.
  • Letting the object compete with foreground copy or CTAs.

Quick Checks

  • The object has visible form, edges, highlights, and shadows.
  • The material uses metalness, roughness, and optional emissive.
  • Directional and ambient lights are both present.
  • The camera is perspective, not orthographic by accident.
  • Resize does not stretch the object.
  • Geometry, material, event listeners, RAF, and renderer are cleaned up.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Build woven fabric in Three.js with visible threads, realistic sheen, seams, and thick hems. The skill covers folds that preserve texture proportions, light passing through thin cloth, and variations in dye and wear.

  • Creating backlit curtains
  • Differentiating linen, silk, and wool
  • Adding hems and stitches for close-up views
MengTo/Skills6.8KUpdated Oct 18, 2026

Build falling leaves in Three.js and similar 3D scenes, with visible front, edge, and back views as they tumble and drift. Coordinate wind, scene depth, camera-aware recycling, and performance checks for a convincing autumn effect.

  • Adding falling autumn leaves to a 3D scene
  • Coordinating leaf tumble, sideways drift, and wind
  • Managing leaves around buildings and camera movement
MengTo/Skills6.8KUpdated Oct 18, 2026

3d-four-seasons

FreeSummary

Add coordinated seasonal transitions to an existing 3D scene. Blend foliage, lighting, sky, ground, snow, and particles from one shared state while preserving camera controls and interactions, so the same place remains recognizable throughout spring, summer, fall, and winter.

  • Add a four-season selector to an outdoor 3D scene
  • Show seasonal changes in an architectural walkthrough
  • Coordinate foliage, sunlight, sky, and ground appearance
MengTo/Skills6.8KUpdated Oct 18, 2026

Create or integrate detailed 3D models with smooth outlines and believable edges for close-up views. Prepare lower-detail versions for distant viewing, prioritize loading, and measure rendering costs in the actual scene.

  • Creating a detailed 3D model for close-up views
  • Replacing visibly faceted curves with smoother geometry
  • Preparing detailed architectural assets for rendering
MengTo/Skills6.8KUpdated Oct 18, 2026

Prepare detailed 3D materials that remain clear in close-up views. The skill guides texture resolution, physically based material maps, surface mapping, filtering, and progressive loading while checking download size and GPU memory use.

  • Prepare wood, stone, and fabric materials for close-up views
  • Fix texture seams, grain direction, and normal map orientation
  • Preserve floor and foliage detail at oblique or distant views
MengTo/Skills6.8KUpdated Oct 18, 2026

Build hyperrealistic PBR metal in Three.js: steel, brass, gold, copper and iron as true conductors (metalness 1, measured F0 tint, no albedo) with roughness-varied finishes (polished, brushed anisotropic, aged with patina and worn edges) lit by a dark HDR studio of real bright window cards prefiltered with PMREM. Use when metal looks like grey plastic, a dull blur, or a black hole; when blades, tools, rings, ingots, hardware or product metal need reflections with edges and structure; or when a finish needs scratches, streaks, fingerprints and bevels that catch light.

The English summary is being prepared. Showing the original description.

MengTo/Skills6.8KUpdated Oct 18, 2026

See all skills by MengTo

Report a problem with this skill