var width = $('#models-container').width();
var height = $('#models-container').height();
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, width / (height - 4), 0.1, 1000);
camera.position.set(30, 40, 30);
var ambient = new THREE.AmbientLight(0xffffff, 0.5); //AmbientLight,影响整个场景的光源
ambient.position.set(0, 0, 0);
scene.add(ambient);
var renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, logarithmicDepthBuffer: true });
renderer.setSize(width, (height - 4));
// 设置背景颜色
//renderer.setClearColor(0xffffff, 1); //0是完全透明,1是不透明
document.getElementById('models-container').appendChild(renderer.domElement);
var composer = new THREE.EffectComposer(renderer);
window.composer = composer;
var controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.autoRotate = true;
controls.autoRotateSpeed = 0.1;
controls.enableDamping = true; //将其设置为true以启用阻尼(惯性),这将给控制器带来重量感。默认值为false
controls.dampingFactor = 0.5; //阻尼惯性有多大。 Default is 0.05。要使得这一值生效,你必须在你的动画循环里调用.update()。
// 视角最小距离
controls.minDistance = 50;
// 视角最远距离
controls.maxDistance = 200;
// 最大角度
//controls.maxPolarAngle = Math.PI / 2.2;
//controls.target = new THREE.Vector3(50, 50, 0);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
// controls.update();
if (composer) {
composer.render();
}
//if (textMesh) {
// textMesh.lookAt(camera.position)
//}
scene.traverse(function (obj) {
});
}
function loadSceneModel() {
var fbxLoader = new THREE.FBXLoader();
fbxLoader.load("../Content/models/scene.fbx", function (object) {
// 设置模型比例
//object.scale.set(0.3, 0.3, 0.3);
// 设置模型位置
//object.position.set(0, -5, 0);
//object.rotateY(agvTopRotateAngle + 0.5);
//var brick = object.getObjectByName('立方体_60');
//bonding_model = brick.parent;
//brick.userData.direction = 'left';
//object.rotateY(-0.1);
//brick_backup = brick.clone();
// 添加模型到场景
scene.add(object);
});
}
loadSceneModel();
camera.lookAt(scene.position);
animate();
标签:模型,THREE,controls,scene,renderer,var,new,3d,加载
From: https://www.cnblogs.com/duixue/p/18556247