2017-09-30 36 views
0

如何從Javascript爲a-frame a面板設置材質,使紋理變爲雙面?使用Javascript的雙面a-框a面板

我已經設法從外部使用Javascript與 <a-plane src="image.jpg" material="side: double">但我不能讓它與JavaScript一起使用。

這是一個非工作的例子,其中只有前可見:

<html> 
<head> 
    <script src="aframe.min.js"></script> 
    <script type="text/javascript"> 
    function setup() { 
     scene = document.querySelector('a-scene'); 

     var entity = document.createElement('a-entity'); 
     entity.setAttribute('position', '0 1.6 -1'); 

     var plane = document.createElement('a-plane'); 
     var planeMaterial = document.createElement('material'); 
     planeMaterial.setAttribute('side', 'double'); 
     plane.appendChild(planeMaterial); 
     plane.setAttribute('src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Jubilee_and_Munin%2C_Ravens%2C_Tower_of_London_2016-04-30.jpg/240px-Jubilee_and_Munin%2C_Ravens%2C_Tower_of_London_2016-04-30.jpg') 
     entity.appendChild(plane); 

     scene.appendChild(entity); 
    } 
    window.onload = setup; 
    </script> 
</head> 

<body> 
    <a-scene></a-scene> 
</body> 
</html> 

回答

2

去您所提供的HTML,這是你所需要的。

plane.setAttribute('material','side:double');

你已經發布的代碼生成

<a-plane src="image.jpg"><material side="double"></material></a-plane>


function setup() { 
 
    scene = document.querySelector('a-scene'); 
 

 
    var entity = document.createElement('a-entity'); 
 
    entity.setAttribute('position', '0 1.6 -1'); 
 

 
    var plane = document.createElement('a-plane'); 
 
    plane.setAttribute('material', 'side: double;'); 
 
    plane.setAttribute('src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Jubilee_and_Munin%2C_Ravens%2C_Tower_of_London_2016-04-30.jpg/240px-Jubilee_and_Munin%2C_Ravens%2C_Tower_of_London_2016-04-30.jpg') 
 
    entity.appendChild(plane); 
 

 
    scene.appendChild(entity); 
 
} 
 
window.onload = setup;
<html> 
 

 
<head> 
 
    <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script> 
 
</head> 
 

 
<body> 
 
    <a-scene></a-scene> 
 
</body> 
 

 
</html>

+0

我覺得這工作。我確實嘗試過'plane.setAttribute('material','side:double;');'之前沒有用,但現在已經更新到您對版本0.7.0的建議,並且該版本可以工作。 –