|
@@ -29,46 +29,46 @@ export default {
|
|
|
methods: {
|
|
methods: {
|
|
|
init() {
|
|
init() {
|
|
|
const scene = new THREE.Scene();
|
|
const scene = new THREE.Scene();
|
|
|
- scene.background = new THREE.Color('#181818');
|
|
|
|
|
|
|
+ // scene.background = new THREE.Color('#fff');
|
|
|
const canvas = this.$refs.three;
|
|
const canvas = this.$refs.three;
|
|
|
- const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
|
|
|
|
|
- const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
|
|
|
|
|
- camera.position.z = 90;
|
|
|
|
|
|
|
+ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
|
|
|
|
|
+ const camera = new THREE.PerspectiveCamera(45, canvas.innerWidth / canvas.innerHeight, 0.1, 1000);
|
|
|
|
|
+ renderer.setSize(canvas.innerWidth, canvas.innerHeight);
|
|
|
|
|
+ camera.position.z = 150;
|
|
|
this.scene = scene;
|
|
this.scene = scene;
|
|
|
this.camera = camera;
|
|
this.camera = camera;
|
|
|
this.renderer = renderer;
|
|
this.renderer = renderer;
|
|
|
const fbxLoader = new FBXLoader();
|
|
const fbxLoader = new FBXLoader();
|
|
|
var mesh = null;
|
|
var mesh = null;
|
|
|
- fbxLoader.load('https://zhirongip.oss-cn-hangzhou.aliyuncs.com/cs_xong.FBX', fbx => {
|
|
|
|
|
|
|
+ // const axesHelper = new THREE.AxesHelper(50);
|
|
|
|
|
+ // scene.add(axesHelper);
|
|
|
|
|
+ fbxLoader.load('https://zhirongip.oss-cn-hangzhou.aliyuncs.com/matilda/source/sketchfab_v002.fbx', fbx => {
|
|
|
console.log(fbx);
|
|
console.log(fbx);
|
|
|
mesh = fbx;
|
|
mesh = fbx;
|
|
|
- mesh.scale.multiplyScalar(0.3);
|
|
|
|
|
- mesh.position.set(0, 0, 0);
|
|
|
|
|
- // mesh.rotation.x = -45;
|
|
|
|
|
- //添加这段代码
|
|
|
|
|
- //遍历模型每部分
|
|
|
|
|
- // mesh.traverse(o => {
|
|
|
|
|
- // //将图片作为纹理加载
|
|
|
|
|
- // let explosionTexture = new THREE.TextureLoader().load(
|
|
|
|
|
- // 'https://zhirongip.oss-cn-hangzhou.aliyuncs.com/matilda/textures/color.2.1001.png'
|
|
|
|
|
- // );
|
|
|
|
|
- // //调整纹理图的方向
|
|
|
|
|
- // explosionTexture.flipY = true;
|
|
|
|
|
- // //将纹理图生成基础网格材质(MeshBasicMaterial)
|
|
|
|
|
- // const material = new THREE.MeshBasicMaterial({
|
|
|
|
|
- // map: explosionTexture
|
|
|
|
|
- // });
|
|
|
|
|
- // //给模型每部分上材质
|
|
|
|
|
- // o.material = material;
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+ mesh.scale.multiplyScalar(0.45);
|
|
|
|
|
+ // mesh.position.y = -40;
|
|
|
|
|
+ console.log(mesh.size);
|
|
|
|
|
+ mesh.traverse(o => {
|
|
|
|
|
+ //将图片作为纹理加载
|
|
|
|
|
+ let explosionTexture = new THREE.TextureLoader().load(
|
|
|
|
|
+ 'https://zhirongip.oss-cn-hangzhou.aliyuncs.com/matilda/textures/color.2.1001.png'
|
|
|
|
|
+ );
|
|
|
|
|
+ //调整纹理图的方向
|
|
|
|
|
+ explosionTexture.flipY = true;
|
|
|
|
|
+ //将纹理图生成基础网格材质(MeshBasicMaterial)
|
|
|
|
|
+ const material = new THREE.MeshBasicMaterial({
|
|
|
|
|
+ map: explosionTexture
|
|
|
|
|
+ });
|
|
|
|
|
+ //给模型每部分上材质
|
|
|
|
|
+ o.material = material;
|
|
|
|
|
+ });
|
|
|
scene.add(fbx);
|
|
scene.add(fbx);
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- const controls = new OrbitControls(camera, renderer.domElement);
|
|
|
|
|
- controls.enableDamping = true;
|
|
|
|
|
|
|
+ // const controls = new OrbitControls(camera, renderer.domElement);
|
|
|
|
|
+ // controls.enableDamping = true;
|
|
|
const clock = new THREE.Clock();
|
|
const clock = new THREE.Clock();
|
|
|
function animate() {
|
|
function animate() {
|
|
|
- controls.update();
|
|
|
|
|
|
|
+ // controls.update();
|
|
|
renderer.render(scene, camera);
|
|
renderer.render(scene, camera);
|
|
|
requestAnimationFrame(animate);
|
|
requestAnimationFrame(animate);
|
|
|
|
|
|