簡體   English   中英

Three.js 沒有從我的星球構造函數 function 渲染我的紋理

[英]Three.js is not rendering my textures from my planet constructor function

我有一個 function 從數據集中獲取軌道參數和紋理圖像並創建 3d object(行星)。 但是由於某種原因,沒有渲染紋理。 使用BasicMaterial它可以正常工作,但不能使用StandardMaterialPhongMaterial (場景中有一個點光源),我已經測試了循環外的紋理和 function,它們工作得很好。 我不知道還能做什么。 我把代碼放在這里。

for(var i=0;i < results.data.length; i++){
              
 const EC = Number(results.data[i]["Eccentricity"]); //Eccentricity
 const IN = Number(results.data[i]["Inclination [Rad]"]) ; //Inclination
 const OM = Number(results.data[i]["Orbit Rotation_Y [Rad]"]) ; //Longitude of ascending node
 const W = Number(results.data[i]["Orbit Rotation_X [Rad]"]); //Argument of periapsis
 const A = Number(results.data[i]["Orbit semi-major axis [UA]"]); //Semi-major axis
 const EcRadius = Number(results.data[i]["Relative Equatorial Radius"]); //Radius
 const NAM = results.data[i]["Name"]; //Name
 const textureUrl = results.data[i]["TextureFileUrl"]; //Texture image of the planet

 const loader = new THREE.TextureLoader();
 loader.load(textureUrl, function ( texture ) {
    // Create the material when the texture is loaded
    var tex = texture.clone();
    const PlanetMaterial = new THREE.MeshBasicMaterial( {
    map: tex
    } );
    scene.add(CreatePlanet( 0,0,0, EC,IN,OM,W,A,EcRadius, NAM, 0x4E4E4E, 0.5, PlanetMaterial ));
    },
  undefined,
  function ( err ) {
     console.error( 'An error happened.');
  }
  );
} 

CreatePlanet function 只是使用給定的材料創建一個網格。 喜歡:

const geometryPlanet = new THREE.SphereBufferGeometry(EcRadius, 300, 300);
const Planet = new THREE.Mesh(geometryPlanet, PlanetMaterial);
return Planet;

預先感謝您的幫助。

var tex = texture.clone();

這樣做時,您可以添加以下行嗎?

tex.needsUpdate = true;

在這種情況下,它是必需的,否則紋理的內容將永遠不會上傳到 GPU。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM