简体   繁体   English

仅部分 gltf model 出现使用 three.js

[英]only part of gltf model appearing using three.js

I have been trying to add this gltf model ( https://poly.google.com/view/28RBIWE8jzc ) using threeJS'.我一直在尝试使用threeJS'添加这个gltf model( https://poly.google.com/view/28RBIWE8jzc )。 The code below is the only way that I have been able to see anything and I only see a small part of the object.下面的代码是我能够看到任何东西的唯一方法,我只看到 object 的一小部分。 If anyone knows what needs to be changed I would appreciate some help.如果有人知道需要更改什么,我将不胜感激。

import * as THREE from 'three';
import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';
import OrbitControls from 'three/examples/jsm/controls/OrbitControls.js'
import { Color } from 'three';




var camera, scene, renderer;

init();
animate();

function init() {

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
camera.position.set(0,10,20);

scene = new THREE.Scene();

// Instantiate a loader
var loader = new GLTFLoader();

// Load a glTF resource
loader.load( 'styles/baseball/Baseball.gltf', function ( gltf ) {
    scene.add( gltf.scene );
} );

scene.background = new Color('blue')

var light = new THREE.AmbientLight(0x404040);
scene.add(light);

const light2 = new THREE.PointLight( 0xff0000, 1, 100 );
light2.position.set( 50, 50, 50 );
scene.add( light2 );

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
document.body.addEventListener( 'keydown', onKeyDown, false );

}

function animate() {
  requestAnimationFrame( animate );
  renderer.render( scene, camera );

}

function onKeyDown(){
  console.log("press")
  switch( event.keyCode ) {
     case 83: // w
     camera.position.z += 5;
     break;
     case 87: // s
     camera.position.z -= 5;
     break;
     case 40: // down
     camera.position.y -= 5;
     break;
     case 38: // up
     camera.position.y += 5;
     break;
  }
}

The baseball asset is quite large so I suggest you change your camera configuration.棒球资产非常大,因此我建议您更改相机配置。 Try it with:试试看:

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set( 0, 150, 350 );

Alternatively, you could also consider to scale down the baseball after the loading process.或者,您也可以考虑在加载过程后缩小棒球的尺寸。 Try it with:试试看:

gltf.scene.scale.setScalar( 0.01 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM