This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > January 2004 > removeChildren in Cortona





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author removeChildren in Cortona
Unregistered

2004-01-24, 11:23 am

Hi,

I would like to check is anyone out using Cortona and experience problems with removeChildren? I tried sending this question to parallelgraphics but yet get any reply so thought of trying my luck here. I know there are successful examples using removeChildren but the problem is they have a
different scenario as mine. They create only a single children. Furthermore, for some of the examples, once they
remove the children, they no longer create new ones. In this case the problem will not be seen. My observations:

1. If you create a single children through addChildren and if you delete it using removeChildren, no problem
2. or if you create a single children and then remove it and re-create another new node as children, this also works fine

But if you create an array of children and then delete it and re-create another array of new children (less number of children this time), then you will start to see the old nodes being display.

For example:

1. first round, you create red box, green box and blue box and display them side by side
2. After that you delete using removeChildren, no problem
3. then you create yellow box and cyan box
4. you will see yellow box, cyan box and blue box.

To illustrate my points, these are fragments of my code:


DEF ShowShape Transform {
translation 2 0 0
children[]
}


This section of code is in vrmlscript:

while (index < num_of_shape)
{
newvrml = 'DEF ' + transform_def + ' Transform {';
newvrml +=' translation ' + new_translation;
newvrml +=' children [';

newvrml +=' Shape {';
newvrml +=' appearance Appearance {}';
newvrml +=' geometry Box {';
newvrml += 'size 0.6 0.38 0.1';
newvrml += '}';
newvrml +=' }';
newvrml +=']';
newvrml +='}';

newpic = Browser.createVrmlFromString(newvrml);
accumulatedNode [index] = newpic[0];
}

then ROUTE accumulatedNode to ShowShape.addChildren

num_of_shape is a variable that gets its value from user. If you set num_of_shape is 3, you will see 3 boxes. When you do removeChildren, all boxes will be deleted. But after that if you set num_of_shape to 2 you will see 3 boxes. The last box is from
previous creation. Can anyone confirm if this is a bug?
I know some plugins are having problem with this.
Bill Angel

2004-01-25, 10:29 am

Hi:

I rearranged and revised your code a bit.
The result now seems to work find under Cortona.

The test program creates three nodes, removes the three nodes, and
then creates two nodes. The end result is that only two nodes are
displayed.

Hope this helps,

--- Bill Angel


#VRML V2.0 utf8

DEF ShowShape Transform {
translation 2 0 0
children []
}

DEF display_Message Script {
field SFNode ShowShape USE ShowShape
field MFString new_translation ["0 0 0", "0 1 0", "0 2 0"]
url [
"java script:

function initialize () {

// create and display 3 nodes
newNodes = createNodes(3);

print('node count = ' + newNodes.length);

ShowShape.removeChildren = newNodes;

// create and display 2 nodes
newNodes = createNodes(2);

print('node count = ' + newNodes.length);

}

function createNodes(num_of_shape) {

accumulatedNode = new MFNode();

index = 0;
while (index < num_of_shape)
{

newvrml = 'Transform {';
newvrml +=' translation ' + new_translation[index];
newvrml +=' children [';

newvrml +=' Shape {';
newvrml +=' appearance Appearance {}';
newvrml +=' geometry Box {';
newvrml += 'size 0.6 0.38 0.1';
newvrml += '}';
newvrml +=' }';
newvrml +=']';
newvrml +='}';

newpic = Browser.createVrmlFromString(newvrml);
accumulatedNode [index] = newpic[0];
index++;

}

ShowShape.addChildren = accumulatedNode;
return(accumulatedNode);
} "
]
}





Unregistered <Guest.10jo4n@mail.forum4designers.com> wrote in message news:<Guest.10jo4n@mail.forum4designers.com>...
quote:

> Hi,
>
> I would like to check is anyone out using Cortona and experience
> problems with removeChildren?.... <Stuff Deleted>


Unregistered

2004-01-26, 12:26 pm

Hi Bill

Thankyou for your suggestion. I tried your example and also modified a little to see the result. I find that even if you comment off the removeChildren, it will still show 2 boxes. Kind of strange because I expect to see 3 boxes if I don't do a removechildren.

Also, I modified the code:

DEF display_Message Script {
field SFNode ShowShape USE ShowShape
field MFString new_translation ["0 0 0", "0 1 0", "0 2 0"]
eventOut MFNode three_nodes
url [
"java script:

function initialize () {

// create and display 3 nodes
newNodes = createNodes(3);

print('node count = ' + newNodes.length);

print('test node');

print(ShowShape.children[0]);
print(ShowShape.children[1]);
print(ShowShape.children[2]);

}


At the point of 'test node', I expect to see Transform{} when I do a print but I don't any idea? I did this because in my code, I cannot delete the dyamically created node in the same script node. Deletion is done in another script node and I have no means of keep a reference to the node create by createVrmlFromString. I have to use ShowShape.children to find out what are the nodes created. Thanks once again!
Bill Angel

2004-01-27, 12:30 pm

Hi:

I did some reworking to the code to overcome the problems you mentioned. The nodes are now created in one Script, and
examined in another Script. You will note the use of a "polling" timer to check when the Nodes which are the children of
the Transform Node have been updated. Also, instead of utilizing "removeChildren" followed by "addChildren" to modify
the Nodes attached to the Transform node, I utilized the Transform Node's "set_children" method.


--- Regards,

Bill Angel


#VRML V2.0 utf8

DEF ShowShape Transform {
translation 2 0 0
children []
}

DEF TIMER TimeSensor { loop TRUE}

DEF display_Message Script {
field SFNode ShowShape USE ShowShape
field SFNode timer USE TIMER
field MFString new_translation ["0 0 0", "0 1 0", "0 2 0"]
field SFBool pause TRUE
eventIn MFNode displayChildren
eventIn SFInt32 createNodes
directOutput TRUE
url [
"java script:

function initialize () {

// create and display 3 nodes
newNodes = createNodes(3);

// start the polling timer
timer.set_enabled = true;
}

function createNodes(num_of_shape) {

accumulatedNode = new MFNode();

index = 0;
while (index < num_of_shape)
{

newvrml = 'Transform {';
newvrml +=' translation ' + new_translation[index];
newvrml +=' children [';

newvrml +=' Shape {';
newvrml +=' appearance Appearance {}';
newvrml +=' geometry Box {';
newvrml += 'size 0.6 0.38 0.1';
newvrml += '}';
newvrml +=' }';
newvrml +=']';
newvrml +='}';

newpic = Browser.createVrmlFromString(newvrml);
accumulatedNode [index] = newpic[0];
index++;

}

ShowShape.set_children = accumulatedNode;
return(accumulatedNode);
} "

]
}

DEF Process_Nodes Script {
field SFNode ShowShape USE ShowShape
field SFNode timer USE TIMER
field SFNode display_Message USE display_Message
field SFInt32 currentNodeCount 0
eventIn SFTime displayChildren
directOutput TRUE
url [
"java script:

function displayChildren() {

children = ShowShape.children_changed;

print(children.length + ' nodes created: ');

currentNodeCount = children.length;

for (i = 0; i < currentNodeCount; i++)
print(children[i].getType());

if(currentNodeCount == 2) {

// stop the polling timer
timer.set_enabled = false;
}

else if(currentNodeCount == 3) {

// create and display 2 nodes
display_Message.createNodes = 2;
}


}
"
]
}

ROUTE TIMER.cycleTime TO Process_Nodes.displayChildren

####<END OF CODE>####


"Unregistered" <Guest.10ng8n@mail.forum4designers.com> wrote in message news:Guest.10ng8n@mail.forum4designers.com...
quote:

>
> Hi Bill
>
> Thankyou for your suggestion. I tried your example and also modified a
> little to see the result. I find that even if you comment off the
> removeChildren, it will still show 2 boxes. Kind of strange because I
> expect to see 3 boxes if I don't do a removechildren.
>
> Also, I modified the code:
>
> DEF display_Message Script {
> field SFNode ShowShape USE ShowShape
> field MFString new_translation ["0 0 0", "0 1 0", "0 2 0"]
> eventOut MFNode three_nodes
> url [
> "java script:
>
> function initialize () {
>
> // create and display 3 nodes
> newNodes = createNodes(3);
>
> print('node count = ' + newNodes.length);
>
> print('test node');
>
> print(ShowShape.children[0]);
> print(ShowShape.children[1]);
> print(ShowShape.children[2]);
>
> }
>
>
> At the point of 'test node', I expect to see Transform{} when I do a
> print but I don't any idea? I did this because in my code, I cannot
> delete the dyamically created node in the same script node. Deletion is
> done in another script node and I have no means of keep a reference to
> the node create by createVrmlFromString. I have to use
> ShowShape.children to find out what are the nodes created. Thanks once
> again!
>
>
> Unregistered -
> ------------------------------------------------------------------------
> Posted via http://www.forum4designers.com
> ------------------------------------------------------------------------
> View this thread: http://www.forum4designers.com/message36789.html
>




Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews