简体   繁体   English

我正在尝试制作Skybox,但我必须缺少一些基本知识

[英]I'm trying to make a skybox, but I must be missing something fundamental

I am trying to make a skybox, and every tutorial I have tried will not work. 我正在尝试制作一个Skybox,但我尝试过的每个教程都无法正常工作。 I thought I could make an array and pass it as a param for the material like I saw in an earlier example, but the method has apparently changed to TextureLoader() since then. 我以为我可以制作一个数组并将其作为参数的参数传递,就像我在前面的示例中看到的那样,但是此后方法显然已更改为TextureLoader()。 Below is my code: 下面是我的代码:

// Adds a skybox around the content
    var skyBoxMaterials = [
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky1.jpg') }),
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky2.jpg') }),
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky3.jpg') }),
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky4.jpg') }),
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky5.jpg') }),
    new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader( 'images/skybox/sky6.jpg') }),
  ];
  var skyBoxGeom = new THREE.CubeGeometry( 10000, 10000, 10000, 1, 1, 1);
    skyBox = new THREE.Mesh( skyBoxGeom, skyBoxMaterials );
    skyBox.position.set(0, 25.1, 0);
    scene.add( skyBox );

When I run it currently, I get the error "Uncaught TypeError: Cannot read property 'x' of undefined" in the console infinitely looping until the server is killed. 当前运行它时,在控制台中无限循环直到服务器被终止之前,都会出现错误“ Uncaught TypeError:无法读取未定义的属性'x'”。 I could not find the exact answer in the examples, docs, or in another question, here. 我在此处的示例,文档或其他问题中找不到确切的答案。 Any suggestions? 有什么建议么?

UPDATE: After some more digging, I finally found the example I needed in the docs under cubeGeometry, but it still does not render. 更新:经过更多的挖掘,我终于在cubeGeometry下的文档中找到了所需的示例,但仍无法呈现。 My code is below: 我的代码如下:

// Adds a skybox around the content
  var loader = new THREE.CubeTextureLoader();
  loader.setPath( 'images/skybox/' );

  var textureCube = loader.load( [
       'sky1.jpg', 'sky2.jpg',
        'sky3.jpg', 'sky4.jpg',
         'sky5.jpg', 'sky6.jpg'
     ] );

  var skyMaterials = new THREE.MeshBasicMaterial( { color: 0xffffff, envMap: 
  textureCube } );
  var skyBoxGeom = new THREE.CubeGeometry( 10000, 10000, 10000, 1, 1, 1);
  skyBox = new THREE.Mesh( skyBoxGeom, skyMaterials );
  skyBox.position.set(0, 25.1, 0);
  scene.add( skyBox );

I do not have any error messages in the console, but the cube is not rendering at all. 我在控制台中没有任何错误消息,但是多维数据集根本没有呈现。 The other objects in the scene render normally. 场景中的其他对象正常渲染。

Have you downloaded the Three.js Master file ? 您是否已下载Three.js Master文件 It has all the examples in working order. 它按工作顺序列出了所有示例。 So all the examples you see on the Examples Page are there along with support files, textures assets etc. This way, you can start your project with a working example and build from there. 因此,您可以在“ 示例”页面上看到的所有示例以及支持文件,纹理资产等。通过这种方式,您可以从一个有效的示例开始您的项目并从那里构建。 You will need to run them from your local server (from your post, I gather you already know this). 您将需要从本地服务器运行它们(从您的帖子中,我知道您已经知道这一点)。 There are a few examples that may help you like Panorama Cube . 有一些示例可以帮助您喜欢Panorama Cube In the examples directory of the download, you will find a file called ' webgl_panorama_cube.html ' that will be your local copy of this example. 在下载的示例目录中,您将找到一个名为“ webgl_panorama_cube.html ”的文件,它将作为此示例的本地副本。

You can use .background property of THREE.Scene() straight, as it accepts cube textures. 您可以直接使用.background THREE.Scene() .background属性,因为它可以接受立方体纹理。

 var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 ); camera.position.set( 0, 0, 300 ); var renderer = new THREE.WebGLRenderer(); renderer.setSize( window.innerWidth, window.innerHeight ); document.body.appendChild( renderer.domElement ); var controls = new THREE.OrbitControls( camera, renderer.domElement ); var loader = new THREE.CubeTextureLoader(); loader.setCrossOrigin( "" ); loader.setPath( 'https://threejs.org/examples/textures/cube/skybox/' ); var cubeTexture = loader.load( [ 'px.jpg', 'nx.jpg', 'py.jpg', 'ny.jpg', 'pz.jpg', 'nz.jpg' ] ); scene.background = cubeTexture; render(); function render() { requestAnimationFrame(render); renderer.render( scene, camera ); } 
 body { overflow: hidden; margin: 0; } 
 <script src="https://threejs.org/build/three.min.js"></script> <script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script> 

暂无
暂无

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

相关问题 无法解释的参数传递给JavaScript函数,这是我所缺少的基本知识 - Unexplained parameters passed into JavaScript functions, something fundamental I am missing LearnYouNode - Jugglling Async(#9) - 我一定是在遗漏某些东西 - LearnYouNode - Jugglling Async (#9) - I Must be Missing Something 我不确定是否要滥用SwitchNavigator或只是缺少一些东西 - I'm unsure if I'm misusing the SwitchNavigator or just missing something 我正在尝试制作此幻灯片内容的javascript函数,但某些方法无法正常工作 - I'm trying to make this slide-content javascript functions but something is not working right 我正在尝试在浏览器中制作 javascript 绘图程序,但事情未对齐。 我的代码有问题吗? - I'm trying to make a javascript drawing program within the browser and things are misaligned. Is there something wrong with my code? Chrome中的Javascript错误:我,我缺少的东西或Chrome中的错误? - Javascript Error in Chrome: Me, something I'm missing or a bug in Chrome? 我缺少一些小东西:未捕获的ReferenceError:未定义$(匿名函数) - I`m missing something small: Uncaught ReferenceError: $ is not defined(anonymous function) 我正在尝试将功能绑定到按钮,但是出现故障 - I'm trying to bind functionality to a button, but something is failing 尝试找出jQuery中是否有错误或我在做什么 - Trying to figure out if there is a bug in jQuery or if it's something I'm doing 我正在尝试刷新PHP变量 - I'm trying to make a PHP variable refresh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM