Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
Can't control rotation(Three.js GLTFLoader)

Problem

Why can't I rotate the angle of an object? (scene.rotation.x += 0.03;)

Camera can ,but scene object can't.

I've been looking for a long time and still can't find the answer.

Here is the myCode:

import * as THREE from 'https://unpkg.com/three@0.126.1/build/three.module.js'
import { OrbitControls } from 'https://unpkg.com/three@0.126.1/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from 'https://unpkg.com/three@0.126.1/examples/jsm/loaders/GLTFLoader.js'

const canvas = document.querySelector('.fan1') // it is my class
const scene = new THREE.Scene()
var ourObj;

const loader = new GLTFLoader()
//load glb file
loader.load('assets/fan.glb', function (glb) {
    const root = glb.scene;
    root.scale.set(10,10,10)
    scene.add(root);
}, function (xhr) {  //xhr
    console.log("xhr");
}, function (error) { //error
    console.log("error");
})

const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(2, 2, 5);
scene.add(light);

const size = {
    width: window.innerWidth,
    height: window.innerHeight
}

const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100); 
camera.position.set(0, 1, 3);
scene.add(camera);


const renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: true,
    canvas: canvas
})

renderer.setClearColor("#DDDDDD");
renderer.setSize(size.width, size.height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
var render = function () {
    requestAnimationFrame(render);
    scene.rotation.x += 0.03;
    renderer.render(scene, camera);
};

render()

Control _x is invalid

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem is that you're adding the camera to the scene with scene.add(camera); This means that when you rotate the scene the camera rotates with it, so you won't notice much movement in the final render.

You don't need to add your camera to your scene. Just remove the line

scene.add(camera);

so that your camera is "free" and independent of any scene transformations.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda