🎉Ultra yayında · %50 indirim — sınırlı süreliğine
Web 3D Görüntüleme Performans Rehberi - Three.js ve Babylon.js Uygulama Stratejileri
2025/08/09

Web 3D Görüntüleme Performans Rehberi - Three.js ve Babylon.js Uygulama Stratejileri

Kapsamlı rehberimizle web 3D görüntüleyici performansında ustalaş. Three.js ve Babylon.js uygulamalarını karşılaştır, yükleme sürelerini optimize et ve şeffaf arka planlar, otomatik döndürme ve aydınlatma için profesyonel teknikleri öğren.

3D Web Çatınızı Seçmek: Önce Performans

Web üzerinde 3D görüntüleyici uygularken Three.js ile Babylon.js arasındaki seçim sadece özelliklerle ilgili değildir; bu seçim performans, paket boyutu ve kullanıcı deneyimi ile ilgilidir. Bu rehber, kod örnekleri ve gerçek dünya kıyaslamalarıyla birlikte 3D görüntüleme performansını optimize etmek için savaş alanında test edilmiş stratejiler sunar.

Çatı Karşılaştırması: Performans Perspektifi

Hızlı Karar Matrisi

AspectThree.jsBabylon.js
Bundle Size~130KB (core)~2.5MB (630KB gzipped)
Learning CurveSteeperGentler
Built-in FeaturesMinimalComprehensive
Performance ControlMaximumAutomated
Best ForCustom solutionsRapid development

Felsefe Farkları

  • Three.js: Ayrıntılı kontrol sunan hafif bir render motoru
  • Babylon.js: Pille birlikte gelen eksiksiz bir 3D motoru

Minimal Uygulama Örnekleri

Three.js: Otomatik Döndürmeli Şeffaf Arka Plan

import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';

// Minimal Three.js viewer setup
function initThreeViewer(canvas, modelUrl) {
  // Scene setup with transparent background
  const scene = new THREE.Scene();
  scene.background = null; // Transparent

  // Camera
  const camera = new THREE.PerspectiveCamera(
    75,
    canvas.width / canvas.height,
    0.1,
    1000
  );
  camera.position.z = 5;

  // Renderer with alpha channel
  const renderer = new THREE.WebGLRenderer({
    canvas,
    alpha: true,
    antialias: true,
    powerPreference: "high-performance"
  });
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));

  // Optimized lighting
  const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
  const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
  directionalLight.position.set(10, 10, 5);
  scene.add(ambientLight, directionalLight);

  // Load GLB with auto-rotation
  const loader = new GLTFLoader();
  let model;

  loader.load(modelUrl, (gltf) => {
    model = gltf.scene;
    scene.add(model);

    // Center and scale model
    const box = new THREE.Box3().setFromObject(model);
    const center = box.getCenter(new THREE.Vector3());
    model.position.sub(center);

    const size = box.getSize(new THREE.Vector3());
    const maxDim = Math.max(size.x, size.y, size.z);
    model.scale.multiplyScalar(2 / maxDim);
  });

  // Animation loop with auto-rotation
  function animate() {
    requestAnimationFrame(animate);

    if (model) {
      model.rotation.y += 0.01;
    }

    renderer.render(scene, camera);
  }
  animate();

  // Handle resize
  window.addEventListener('resize', () => {
    camera.aspect = canvas.width / canvas.height;
    camera.updateProjectionMatrix();
    renderer.setSize(canvas.width, canvas.height);
  });
}

Babylon.js: Gölgelerle Eksiksiz Görüntüleyici

import * as BABYLON from '@babylonjs/core';
import '@babylonjs/loaders/glTF';

// Babylon.js viewer with full features
function initBabylonViewer(canvas, modelUrl) {
  // Engine setup
  const engine = new BABYLON.Engine(canvas, true, {
    preserveDrawingBuffer: true,
    stencil: true,
    powerPreference: "high-performance"
  });

  // Scene with transparent background
  const scene = new BABYLON.Scene(engine);
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 0);

  // Camera with auto-rotation
  const camera = new BABYLON.ArcRotateCamera(
    "camera",
    BABYLON.Tools.ToRadians(45),
    BABYLON.Tools.ToRadians(60),
    10,
    BABYLON.Vector3.Zero(),
    scene
  );
  camera.attachControl(canvas, true);
  camera.wheelDeltaPercentage = 0.01;

  // Optimized lighting with shadows
  const light = new BABYLON.DirectionalLight(
    "light",
    new BABYLON.Vector3(-1, -2, -1),
    scene
  );
  light.position = new BABYLON.Vector3(20, 40, 20);
  light.intensity = 0.7;

  const ambientLight = new BABYLON.HemisphericLight(
    "ambient",
    new BABYLON.Vector3(0, 1, 0),
    scene
  );
  ambientLight.intensity = 0.3;

  // Shadow generator
  const shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
  shadowGenerator.useExponentialShadowMap = true;

  // Load model with optimization
  BABYLON.SceneLoader.LoadAssetContainer(
    "",
    modelUrl,
    scene,
    (container) => {
      container.addAllToScene();

      // Apply shadows to all meshes
      container.meshes.forEach(mesh => {
        mesh.receiveShadows = true;
        shadowGenerator.addShadowCaster(mesh);
      });

      // Auto-rotation
      scene.registerBeforeRender(() => {
        container.meshes[0].rotation.y += 0.01;
      });
    }
  );

  // Render loop
  engine.runRenderLoop(() => {
    scene.render();
  });

  // Handle resize
  window.addEventListener('resize', () => {
    engine.resize();
  });
}

Performans Optimizasyon Stratejileri

1. Model Optimizasyonu

Dosya Boyutu Kontrolü

// Compression comparison
const modelSizes = {
  uncompressed: "26MB",
  draco: "5MB (-80%)",
  meshopt: "4MB (-85%)",
  quantized: "8MB (-70%)"
};

Doku Sıkıştırma

// Three.js texture optimization
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('texture.jpg');
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = true;

// Basis Universal compression (50-75% smaller)
import { BasisTextureLoader } from 'three/examples/jsm/loaders/BasisTextureLoader';
const basisLoader = new BasisTextureLoader();
basisLoader.setTranscoderPath('basis/');
basisLoader.load('texture.basis', (texture) => {
  material.map = texture;
});

Mesh Sadeleştirme

// LOD (Level of Detail) implementation
const lod = new THREE.LOD();

// High detail (close up)
const highDetail = await loadModel('model-300k.glb');
lod.addLevel(highDetail, 0);

// Medium detail
const mediumDetail = await loadModel('model-60k.glb');
lod.addLevel(mediumDetail, 50);

// Low detail (far away)
const lowDetail = await loadModel('model-15k.glb');
lod.addLevel(lowDetail, 100);

scene.add(lod);

2. Tembel Yükleme Uygulaması

// Progressive loading with placeholder
class LazyModel {
  constructor(placeholderUrl, highQualityUrl) {
    this.placeholder = placeholderUrl;
    this.highQuality = highQualityUrl;
    this.loaded = false;
  }

  async load(scene, callback) {
    // Load low-res placeholder immediately
    const placeholder = await this.loadGLB(this.placeholder);
    scene.add(placeholder);
    callback(placeholder);

    // Load high-res in background
    const highQuality = await this.loadGLB(this.highQuality);

    // Smooth transition
    highQuality.visible = false;
    scene.add(highQuality);

    // Fade transition
    this.fadeTransition(placeholder, highQuality, () => {
      scene.remove(placeholder);
      this.loaded = true;
    });
  }

  fadeTransition(out, in, complete) {
    const duration = 500; // ms
    const start = performance.now();

    function animate() {
      const elapsed = performance.now() - start;
      const progress = Math.min(elapsed / duration, 1);

      out.material.opacity = 1 - progress;
      in.material.opacity = progress;

      if (progress < 1) {
        requestAnimationFrame(animate);
      } else {
        in.visible = true;
        complete();
      }
    }
    animate();
  }
}

3. Performans İzleme

// FPS counter and performance metrics
class PerformanceMonitor {
  constructor(renderer) {
    this.renderer = renderer;
    this.fps = 0;
    this.frame = 0;
    this.lastTime = performance.now();

    // GPU memory monitoring
    this.memory = {
      geometries: 0,
      textures: 0,
      programs: 0
    };
  }

  update() {
    this.frame++;
    const currentTime = performance.now();

    if (currentTime >= this.lastTime + 1000) {
      this.fps = (this.frame * 1000) / (currentTime - this.lastTime);
      this.frame = 0;
      this.lastTime = currentTime;

      // Update memory stats
      const info = this.renderer.info;
      this.memory = {
        geometries: info.memory.geometries,
        textures: info.memory.textures,
        programs: info.programs.length
      };

      console.log(`FPS: ${this.fps.toFixed(1)} | ` +
                  `Geometries: ${this.memory.geometries} | ` +
                  `Textures: ${this.memory.textures}`);
    }
  }
}

SEO ve Erişilebilirlik Optimizasyonu

SEO için Yer Tutucu Görseller

<div class="model-viewer-container">
  <!-- SEO-friendly placeholder -->
  <img
    src="model-preview.jpg"
    alt="3D model of Product Name"
    loading="lazy"
    style="position: absolute; width: 100%; height: 100%;"
    id="placeholder"
  />

  <!-- 3D canvas (hidden initially) -->
  <canvas
    id="viewer-canvas"
    style="display: none;"
    aria-label="Interactive 3D model viewer"
  />

  <!-- Loading indicator -->
  <div class="loading-spinner" style="display: none;">
    Loading 3D model...
  </div>
</div>

<script>
// Progressive enhancement
if (WebGL2RenderingContext) {
  // Load 3D viewer
  loadViewer().then(() => {
    document.getElementById('placeholder').style.display = 'none';
    document.getElementById('viewer-canvas').style.display = 'block';
  });
} else {
  // Fallback to static image
  console.log('WebGL not supported');
}
</script>

3D İçerik için Yapılandırılmış Veri

<script type="application/ld+json">
{
  "@context": "https://schema.org/",
  "@type": "3DModel",
  "name": "Product Name 3D Model",
  "description": "Interactive 3D view of Product Name",
  "image": "https://example.com/model-preview.jpg",
  "encoding": {
    "@type": "3DModelEncoding",
    "encodingFormat": "model/gltf-binary",
    "contentUrl": "https://example.com/model.glb"
  }
}
</script>

Platforma Özel Optimizasyonlar

Mobil Performans

// Adaptive quality based on device
function getQualitySettings() {
  const isMobile = /iPhone|iPad|Android/i.test(navigator.userAgent);
  const gpu = detectGPUTier();

  if (isMobile) {
    return {
      pixelRatio: Math.min(window.devicePixelRatio, 2),
      shadowMapSize: 512,
      textureSize: 1024,
      antialias: false,
      modelQuality: 'standard' // 30k polygons
    };
  }

  // Desktop settings
  return {
    pixelRatio: window.devicePixelRatio,
    shadowMapSize: 2048,
    textureSize: 2048,
    antialias: true,
    modelQuality: gpu.tier > 2 ? 'ultra' : 'pro'
  };
}

Gömme Kodu Üretici

// One-click embed code for Modelfy 3D models
function generateEmbedCode(modelId, options = {}) {
  const defaults = {
    width: '100%',
    height: '500px',
    autoRotate: true,
    background: 'transparent',
    controls: true,
    quality: 'auto'
  };

  const settings = { ...defaults, ...options };

  return `
<!-- Modelfy 3D Viewer -->
<iframe
  src="https://modelfy3d.com/embed/${modelId}"
  width="${settings.width}"
  height="${settings.height}"
  frameborder="0"
  allow="autoplay; fullscreen; xr-spatial-tracking"
  data-auto-rotate="${settings.autoRotate}"
  data-background="${settings.background}"
  data-controls="${settings.controls}"
  data-quality="${settings.quality}"
  loading="lazy"
></iframe>
  `.trim();
}

// Copy to clipboard functionality
function copyEmbedCode() {
  const code = generateEmbedCode('your-model-id', {
    width: '800px',
    height: '600px'
  });

  navigator.clipboard.writeText(code).then(() => {
    alert('Embed code copied to clipboard!');
  });
}

Performans Kıyaslamaları

Gerçek Dünya Yükleme Süreleri

Model QualityFile SizeThree.js LoadBabylon.js LoadFPS (Mobile)FPS (Desktop)
Fast (15K)0.5MB0.8s1.2s6060
Standard (30K)1.2MB1.5s2.0s5560
Pro (60K)2.5MB2.8s3.5s4560
Ultra (300K)5MB5.2s6.8s2555

Optimizasyonun Etkisi

// Before optimization
const unoptimized = {
  fileSize: "26MB",
  loadTime: "18s",
  fps: "15 (mobile)",
  memory: "450MB"
};

// After optimization
const optimized = {
  fileSize: "2.5MB (-90%)",
  loadTime: "2.8s (-84%)",
  fps: "45 (mobile)",
  memory: "95MB (-79%)"
};

Hızlı Uygulama Kontrol Listesi

3D görüntüleyicini dağıtmadan önce:

  • Model Draco veya Meshopt ile sıkıştırıldı
  • Dokular optimize edildi (WEBP/Basis)
  • Büyük modeller için LOD uygulandı
  • Mobilde piksel oranı sınırlandı
  • Daha iyi UX için tembel yükleme eklendi
  • SEO yer tutucu görseli eklendi
  • Erişilebilirlik etiketleri dahil edildi
  • Performans izleme aktif
  • Gömme kodu test edildi

Bugün Optimize Etmeye Başla

Yüksek performanslı 3D görüntüleyiciler uygulamaya hazır mısın? Modelfy 3D şunları sunar:

  • Önceden optimize edilmiş GLB dışa aktarımları
  • LOD için çok katmanlı kalite seviyeleri
  • Gömme kodu üreteci
  • CDN üzerinde barındırılan görüntüleyici kütüphaneleri

Hemen Başla →

Geliştirici Kaynakları

Kapsamlı entegrasyon rehberleri ve performans en iyi uygulama dokümantasyonu yakında geliyor. Three.js ve Babylon.js entegrasyonuna dair detaylı eğitimler ve örnek uygulamalar için bizi takip etmeye devam et.

Bu teknikleri ustaca kullan ve 3D içeriğin tüm cihazlarda daha hızlı yüklensin, daha akıcı çalışsın ve olağanüstü deneyimler sunsun. Web 3D'nin geleceği önce performans odaklı; uygulamanın bu hıza ayak uyduğundan emin ol.

Bülten

Topluluğa katıl

En son haberler ve güncellemeler için bültenimize abone ol