我正在關注這個three.js示例(http://threejs.org/examples/#webgl_interactive_cubes),並試圖找到一種方法讓用戶添加指定X,Y,& Z位置的框。在使用three.js時使用JavaScript獲取用戶輸入?
我可以用一個javascript提示
var boxes = prompt("X Position", 500); // 500 = Default position
做到這一點。然而,我想有可能使用戶輸入多個字段(例如,X,Y,Z位置;箱子的大小等) ,所以我想添加輸入框。我知道如何做到這一點的唯一方法是使用HTML/CSS/JavaScript的像這樣的東西 -
<!-- CSS formating of Input Boxes -->
<style type = "text/css">
#x_pos {
position: absolute;
bottom: 120px;
left: 10px;
width: 130px;
background-color: #3c4543;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: 2px solid #000000;
font-family: Futura;
}
... Repeat for #y_pos & #z_pos
</style>
<!-- Adding a div for each Input Box -->
<div id="x_pos">
<input type="text" id="xpos">
</div>
... Repeat for #y_pos & #z_pos
<h1>Add Node here...</h1>
<!--Allowing user to add input to the Input Box and saving that value as the x, y, & z positions -->
<script text="text/javascript">
var xPosition;
$(document).ready(function(){
$('#xpos').val('Longitude');
$("#xpos").change(function(){
xPosition = $('#xpos').val();
})
... Repeat for #ypos & #zpos
});
然而,當我可以得到頁眉和輸入框出現,他們絕對沒有的功能。我無法在文本框中輸入任何內容,也無法將.click(function()...)功能添加到h1文本中。這幾乎就像我習慣的所有html和javascript功能已被其餘的three.js代碼禁用。我的最終目標是讓.click調用一個函數,使我可以將上面定義的div顯示在h1「Add Node here ...」下面(http://jsfiddle.net/zsfE3/9/)。
任何人都可以向我解釋這裏發生了什麼,以及我可以如何解決它?或者有沒有人有更好的方法來做到這一點?感謝球員的任何幫助!
爲什麼不使用DAT.GUI? – gaitat 2014-11-03 21:09:58