我正在关注这个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