我終於找到了解決方案。根本不存在three.js的問題,實際的問題是我偶爾會將幾架飛機添加到一個場景中,而不是一個。這是因爲我的initScene()方法被調用的次數不止一次,因爲當所有着色器等仍在加載時(我正通過異步AJAX請求加載我的着色器),我沒有檢查大小寫。我剛剛檢查'沒有加載'和'已完全加載並準備使用'。
這是現在工作:
/**
* Adds geometry to the scene and attaches previously loaded material.
*
* @param {Number} wavelength of the first octave of the height map
* @param {Number} frequency of the first octave of the height map
* @param {Number} number of octaves (has to be an integer)
*/
HeightMap.prototype.initScene = function(wavelength, frequency, lacunarity, persistency, octaves) {
this.material = HeightMap.settings.templateMaterial.clone();
this.updateUniforms(wavelength, frequency, lacunarity, persistency, octaves);
HeightMapOctave.prototype.addPlane.call(this);
this.initialized = true;
};
/**
* Updates values for HeightMap.
*
* @param {Number} wavelength of the first octave of the height map
* @param {Number} frequency of the first octave of the height map
* @param {Number} number of octaves (has to be an integer)
*/
HeightMap.prototype.updateScene = function(wavelength, frequency, lacunarity, persistency, octaves) {
if (this.initialized) {
this.updateUniforms(wavelength, frequency, lacunarity, persistency, octaves);
Canvas3D.prototype.render.call(this);
} else if (!this.initializing) {
this.initializing = true;
this.loadShaders(function() {
this.initScene(wavelength, frequency, lacunarity, persistency, octaves);
Canvas3D.prototype.render.call(this);
});
}
};
我知道這是一個非常具體的問題,但也許這個職位仍然可能是其他人誰犯同樣的錯誤有幫助。我花了我基本上一個星期來跟蹤這個bug ...
任何代碼顯示? – ThisIsSparta
這是'基類的用於控制所有帆布: https://github.com/heartdisease/HeightMapGenerator/blob/master/js/Canvas3D.js 此類呈現高度圖的八度: https://github.com/heartdisease/HeightMapGenerator/blob/master/js/HeightMapOctave.js – heartdisease