我在Z轴上重建同一个物体时遇到了麻烦,它们之间的空间错误,我看不出问题出在哪里。
我希望对象之间没有空格。
这是Tabua.wrl对象的代码
#VRML V2.0 utf8
Transform
{
translation 0 0 0
children
[
Shape
{
appearance Appearance
{
texture ImageTexture
{
url "Imagens/madeira1.jpg"
}
}
geometry Box
{
size 2 0.05 0.5
}
}
]
}
这是创建对象重复的代码
quant =对象重复的次数
compri =空间跳跃
#VRML V2.0 utf8
Transform
{
rotation 0 1 0 3.14
translation 0 0 0
children
[
DEF Ponte Group
{
}
]
}
DEF pont Script
{
field SFNode pt USE Ponte
field SFNode me USE pont
field SFInt32 CTRL 0
field SFInt32 quant 5
field MFFloat compri 0.5
field MFString wrlTab "Tabua.wrl"
eventIn MFNode set_node
field SFBool inic TRUE
url "javascript:
function initialize()
{
Browser.createVrmlFromURL(wrlTab, me, 'set_node');
}
function set_node (node, t)
{
node[0].translation[2]= -compri*CTRL;
pt.addChildren = node;
CTRL+=1;
if(inic)
{
if(CTRL < quant)
{
Browser.createVrmlFromURL(wrlTab, me, 'set_node');
}
else
{
inic = false;
}
}
}
"
}
正在做的事情的形象
答案 0 :(得分:1)
我建议您使用PROTO
代替Browser.createVrmlFromURL
,因为您要重新下载外部.wrl文件五次,而这只会下载一次。
Tabua.wrl:
#VRML V2.0 utf8
PROTO Tabua[
exposedField SFVec3f translation 0 0 0
]{
Transform {
translation IS translation
children Shape {
appearance Appearance {
texture ImageTexture{
url "Imagens/madeira1.jpg"
}
}
geometry Box {
size 2 0.05 0.5
}
}
}
}
主要场景:
#VRML V2.0 utf8
Viewpoint {
position 1.888 1.912 4.417
orientation -0.652 0.735 0.185 0.679
fieldOfView 0.716
}
DEF Ponte Group {}
Script {
field SFInt32 quant 5
field SFString protoDefinition "
EXTERNPROTO Tabua [
exposedField SFVec3f translation
] \"Tabua.wrl\"
"
field SFNode Ponte USE Ponte
directOutput TRUE
url "javascript:
function initialize(){
var vrml = protoDefinition;
for (var i = 0; i < quant; i++){
var z = i * -0.5;
vrml += 'Tabua{translation 0 0 ' + z + '}';
}
Ponte.addChildren = Browser.createVrmlFromString(vrml);
}
"
}
答案 1 :(得分:0)
似乎它不是“读取”变量“compri”,所以我切换了值并完美地工作。
#VRML V2.0 utf8
Transform
{
rotation 0 1 0 3.14
translation 0 0 0
children
[
DEF Ponte Group
{
}
]
}
DEF pont Script
{
field SFNode pt USE Ponte
field SFNode me USE pont
field SFInt32 CTRL 0
field SFInt32 quant 5
#field MFFloat compri 0.7
field MFString wrlTab "Tabua.wrl"
eventIn MFNode set_node
field SFBool inic TRUE
url "javascript:
function initialize()
{
Browser.createVrmlFromURL(wrlTab, me, 'set_node');
}
function set_node (node, t)
{
node[0].translation[2]= -0.5*CTRL;
pt.addChildren = node;
CTRL += 1;
if(inic)
{
if(CTRL < quant)
{
Browser.createVrmlFromURL(wrlTab, me, 'set_node');
}
else
{
inic = false;
}
}
}
"
}
我首先想要的结果。