This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > VRML > December 2004 > Newbie - x3d (/VRML) and Java3d.....





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 Newbie - x3d (/VRML) and Java3d.....
bensmyth

2004-12-20, 12:21 pm

Dear all,

I'm currently working on an x3d project in the world of academia; I have
experience with various other languages, but I'm a complete newbie with x3d.

Is it possible to build my x3d application on top of Java3d (/Java)??

To me, it seems sensible to build all my proto's as Java3d objects and
handle all my scripting within Java3d??

I suppose my question is "How do Java3d and x3d work together?"
(This question could just as easily be phrased - "How do Java and VRML fit
together?")


Any help would be much appreciated!

Regards,

Ben


bensmyth

2004-12-20, 7:19 pm

Thanks for your suggestions so far....

Implementing the whole thing in Java3d seems like a possibility.....
however, I would then lose features such as PlaneSensor! And being academia,
I probably wouldn't get many marks.... seeing as my project is suppose to be
written in x3d! ;-)

My current line of thought.......

My scripting language must keep its own 'model' of the world in order to
manage it, this model can be created by any means (inc. Java3d for example).
In order to keep my script and VR world seperate, my script must be
dynamic......

By dynamic I mean: if the VR world were to change (ball sizes to increase,
for example), the script should not need to be altered. This is a reasonable
objective.... but it adds complexity to the script.


How do I go about accessing this kind of information from a script???

Simple VRML example:
#VRML V2.0 utf8

DEF myShape Transform{
translation 1 1 1
children[
Shape{
geometry Sphere{
radius 2
}
}

DEF myScript Script{
field SFNode thisShape USE myShape
url "java script:
function initialize() {
print(thisShape.translation); //SUCCESS
print(thisShape.children.Shape.Sphere.radius); //FAILS
}
"
}
]
}

How can I successfully get thisShape.children.Shape.Sphere.radius??


Cheers,

Ben


bensmyth

2004-12-20, 7:19 pm

> Try:
>
> thisShape.children[0].geometry.radius



I don't suppose you know the X3D conversion??

CODE:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN"
"http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile="Immersive">
<Scene>
<Transform translation="1 1 1">
<Shape>
<Sphere radius="2"/>
</Shape>

<Script>
<field name="thisShape" type="SFNode" accessType="initializeOnly"
USE="myShape"/>

<![CDATA[
ecmascript:
function initialize() {
Browser.print(thisShape.translation); //FAILS
Browser.print(thisShape.children[0].geometry.radius); //FAILS
}
]]>
</Script>
</Transform>
</Scene>
</X3D>


Thanks for your time.


Regards,

Ben


mdk

2004-12-20, 7:19 pm

> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN"
> "http://www.web3d.org/specifications/x3d-3.0.dtd">
> <X3D profile="Immersive">
> <Scene>
> <Transform translation="1 1 1">
> <Shape>
> <Sphere radius="2"/>
> </Shape>
>
> <Script>
> <field name="thisShape" type="SFNode" accessType="initializeOnly"
> USE="myShape"/>
>
> <![CDATA[
> ecmascript:
> function initialize() {
> Browser.print(thisShape.translation); //FAILS
> Browser.print(thisShape.children[0].geometry.radius); //FAILS
> }
> ]]>
> </Script>
> </Transform>
> </Scene>
> </X3D>
>
>



I don't know much about x3d, but I think you've just forgotten to define 'myShape' - i.e. there is
no DEF="myShape"

bye
md
Joerg Scheurich aka MUFTI

2004-12-21, 4:16 am

> I suppose my question is "How do Java3d and x3d work together?"

You should take a look at Xj3D which is a VRML/X3D browser/library
written in java. Currently it can use java3D...

> (This question could just as easily be phrased - "How do Java and VRML fit
> together?")


.... but the authors are building now a OpenGL based version too...

VRML and java also fit together as a scripting language from "inside"
VRML (VRML script node) or a language to access VRML object from "outside"
(EAI)

so long
MUFTI
--
How to Remove Linux and Install Windows XP
NOTE: Windows XP and Linux can coexist on the same computer.
For additional information, refer to your Linux documentation.
Microsoft Knowledge Base Article - Q314458
bensmyth

2004-12-22, 7:15 am

> try this:
>
> <<SNIP>>
>


Any ideas on this variant??

I'm trying to use inheritance within VRML


#VRML V2.0 utf8

PROTO ball[
field SFFloat radius 1.0
] {
Shape{
geometry Sphere{
radius IS radius
}
}
}

PROTO colorBall[] {
ball{}
}

DEF balls Transform{
children[
Transform { children[colorBall{}] }
Transform { children[colorBall{}] }
Transform { children[ball{}] }
Transform { children[ball{radius 3}] }
]
}

DEF myScript Script{
field SFNode balls USE balls

directOutput TRUE
url "java script:
function initialize() {
print(balls.children[0].children[0].radius);
print(balls.children[1].children[0].radius);
print(balls.children[2].children[0].radius);
print(balls.children[3].children[0].radius);
}"
}


Any ideas??


bensmyth

2004-12-22, 7:15 am

> > <?xml version="1.0" encoding="UTF-8"?>
accessType="initializeOnly"[color=darkred]
//FAILS[color=darkred]
>
>
> I don't know much about x3d, but I think you've just forgotten to define

'myShape' - i.e. there is
> no DEF="myShape"


The Translation node was supposed to contain the DEF, just didn't type it!

I get a "Attempt to get value of unknown property 'translation'" error.


Cheers,

Ben


bensmyth

2004-12-22, 12:16 pm

I think I'm getting there..... but I'm still slightly stuck....

Slight variation of the problem:

#VRML V2.0 utf8

PROTO ball[] {
Shape{
geometry Sphere{
radius 5
}
}
}

DEF balls Transform{
children[
Transform { children[ball{}] }
Transform { children[ball{}] }
Transform { children[ball{}] }
]
}

DEF myScript Script{
field SFNode balls USE balls

directOutput TRUE
url "java script:
function initialize() {
print(balls.children[0].children[0]); //STUCK HERE... How do I
access radius??
}"
}


How do I access radius in the above example??

balls.children[0].children[0] is as far as I can get....



Cheers,

Ben


bensmyth

2004-12-22, 12:16 pm

> I think I'm getting there..... but I'm still slightly stuck....

I've solved it.... But in x3d, and the source is in some 3-5 files... Hence
I won't post! Unless anyone wants it.


Braden McDaniel

2004-12-22, 12:16 pm

On Wed, 2004-12-22 at 10:09 +0000, bensmyth wrote:
>
> Any ideas on this variant??
>
> I'm trying to use inheritance within VRML


It doesn't have it; only composition.

> #VRML V2.0 utf8
>
> PROTO ball[
> field SFFloat radius 1.0
> ] {
> Shape{
> geometry Sphere{
> radius IS radius
> }
> }
> }
>
> PROTO colorBall[] {
> ball{}
> }
>
> DEF balls Transform{
> children[
> Transform { children[colorBall{}] }
> Transform { children[colorBall{}] }
> Transform { children[ball{}] }
> Transform { children[ball{radius 3}] }
> ]
> }
>
> DEF myScript Script{
> field SFNode balls USE balls
>
> directOutput TRUE
> url "java script:
> function initialize() {
> print(balls.children[0].children[0].radius);
> print(balls.children[1].children[0].radius);
> print(balls.children[2].children[0].radius);
> print(balls.children[3].children[0].radius);
> }"
> }
>
>
> Any ideas??


You can read exposedField and eventOut values from a script (and you
don't need directOutput for that; you just need it when sending an event
to a node's eventIn (e.g., via assignment)). ball's radius is a field,
so it can't be read; and the colorBall nodes don't have any radius field
whatsoever. (ball's interfaces are not inherited.)

--
Braden McDaniel e-mail: <braden@endoframe.com>
<http://endoframe.com> Jabber: <braden@jabber.org>

bensmyth

2004-12-22, 7:19 pm

> You can read exposedField and eventOut values from a script (and you
> don't need directOutput for that; you just need it when sending an event
> to a node's eventIn (e.g., via assignment)). ball's radius is a field,
> so it can't be read; and the colorBall nodes don't have any radius field
> whatsoever. (ball's interfaces are not inherited.)


I shouldn't have left directOutput in the code I posted (I simplified my
code prior to posting and failed to remove).


The script outputs:

undefined
undefined
1
3

Hence the balls radius is read?


Is there anyway I can read balls radius from colorBall??


Regards,

Ben


Richard Kennaway

2004-12-22, 7:19 pm

In article <cqc7gg$1tqd$1@soapbox.cs.bham.ac.uk> bensmyth,
noreply@test.com writes:
>Is there anyway I can read balls radius from colorBall??


Only if you change its PROTO definition. As written, it has no fields:

> PROTO colorBall[] {
> ball{}
> }


You need to write something like this:

PROTO colorBall [
field SFFloat radius 2.0 # Or whatever you want the default to be
] {
ball{ radius IS radius }
}

--
Richard Kennaway, jrk@cmp.uea.ac.uk, http://www.cmp.uea.ac.uk/~jrk/
School of Computing Sciences,
University of East Anglia, Norwich NR4 7TJ, U.K.
Braden McDaniel

2004-12-22, 11:15 pm

On Wed, 2004-12-22 at 16:31 +0000, bensmyth wrote:
>
> I shouldn't have left directOutput in the code I posted (I simplified my
> code prior to posting and failed to remove).
>
>
> The script outputs:
>
> undefined
> undefined
> 1
> 3
>
> Hence the balls radius is read?


Then your browser is broken.

> Is there anyway I can read balls radius from colorBall??


Not without exposing it in the colorBall interface set via an IS
mapping.

--
Braden McDaniel e-mail: <braden@endoframe.com>
<http://endoframe.com> Jabber: <braden@jabber.org>

mdk

2004-12-23, 4:15 am

try this:


#VRML V2.0 utf8

PROTO ball[
field SFFloat radius 5
] {
Shape{
geometry Sphere{
radius IS radius
}
}
}

DEF balls Transform{
children[
Transform { children[ball{}] }
Transform { children[ball{}] }
Transform { children[ball{radius 2}] }
]
}

DEF myScript Script{
field SFNode balls USE balls

directOutput TRUE
url "java script:
function initialize() {
print(balls.children[0].children[0].radius);
print(balls.children[2].children[0].radius);
}"
}




bye
md
bensmyth

2004-12-23, 7:14 am

> >Is there anyway I can read balls radius from colorBall??
>
> Only if you change its PROTO definition. As written, it has no fields:



>
> You need to write something like this:
>
> PROTO colorBall [
> field SFFloat radius 2.0 # Or whatever you want the default to be
> ] {
> ball{ radius IS radius }
> }


Is there a way to 'fetch' the radius of the ball node?? ie.
> field SFFloat radius 2.0 # Or whatever you want the default to be

field SFFloat radius <BALL_NODE_REF>


Cheers for your help,

Ben


bensmyth

2004-12-25, 7:14 am

> try this:
>
> <<SNIP>>
>


Any ideas on this variant??

I'm trying to use inheritance within VRML


#VRML V2.0 utf8

PROTO ball[
field SFFloat radius 1.0
] {
Shape{
geometry Sphere{
radius IS radius
}
}
}

PROTO colorBall[] {
ball{}
}

DEF balls Transform{
children[
Transform { children[colorBall{}] }
Transform { children[colorBall{}] }
Transform { children[ball{}] }
Transform { children[ball{radius 3}] }
]
}

DEF myScript Script{
field SFNode balls USE balls

directOutput TRUE
url "java script:
function initialize() {
print(balls.children[0].children[0].radius);
print(balls.children[1].children[0].radius);
print(balls.children[2].children[0].radius);
print(balls.children[3].children[0].radius);
}"
}


Any ideas??


Braden McDaniel

2004-12-25, 12:14 pm

On Wed, 2004-12-22 at 10:09 +0000, bensmyth wrote:
>
> Any ideas on this variant??
>
> I'm trying to use inheritance within VRML


It doesn't have it; only composition.

> #VRML V2.0 utf8
>
> PROTO ball[
> field SFFloat radius 1.0
> ] {
> Shape{
> geometry Sphere{
> radius IS radius
> }
> }
> }
>
> PROTO colorBall[] {
> ball{}
> }
>
> DEF balls Transform{
> children[
> Transform { children[colorBall{}] }
> Transform { children[colorBall{}] }
> Transform { children[ball{}] }
> Transform { children[ball{radius 3}] }
> ]
> }
>
> DEF myScript Script{
> field SFNode balls USE balls
>
> directOutput TRUE
> url "java script:
> function initialize() {
> print(balls.children[0].children[0].radius);
> print(balls.children[1].children[0].radius);
> print(balls.children[2].children[0].radius);
> print(balls.children[3].children[0].radius);
> }"
> }
>
>
> Any ideas??


You can read exposedField and eventOut values from a script (and you
don't need directOutput for that; you just need it when sending an event
to a node's eventIn (e.g., via assignment)). ball's radius is a field,
so it can't be read; and the colorBall nodes don't have any radius field
whatsoever. (ball's interfaces are not inherited.)

--
Braden McDaniel e-mail: <braden@endoframe.com>
<http://endoframe.com> Jabber: <braden@jabber.org>

bensmyth

2004-12-25, 12:14 pm

> You can read exposedField and eventOut values from a script (and you
> don't need directOutput for that; you just need it when sending an event
> to a node's eventIn (e.g., via assignment)). ball's radius is a field,
> so it can't be read; and the colorBall nodes don't have any radius field
> whatsoever. (ball's interfaces are not inherited.)


I shouldn't have left directOutput in the code I posted (I simplified my
code prior to posting and failed to remove).


The script outputs:

undefined
undefined
1
3

Hence the balls radius is read?


Is there anyway I can read balls radius from colorBall??


Regards,

Ben


Braden McDaniel

2004-12-28, 7:17 pm

On Wed, 2004-12-22 at 16:31 +0000, bensmyth wrote:
>
> I shouldn't have left directOutput in the code I posted (I simplified my
> code prior to posting and failed to remove).
>
>
> The script outputs:
>
> undefined
> undefined
> 1
> 3
>
> Hence the balls radius is read?


Then your browser is broken.

> Is there anyway I can read balls radius from colorBall??


Not without exposing it in the colorBall interface set via an IS
mapping.

--
Braden McDaniel e-mail: <braden@endoframe.com>
<http://endoframe.com> Jabber: <braden@jabber.org>

bensmyth

2004-12-28, 7:17 pm

> try this:
>
> <<SNIP>>
>


Any ideas on this variant??

I'm trying to use inheritance within VRML


#VRML V2.0 utf8

PROTO ball[
field SFFloat radius 1.0
] {
Shape{
geometry Sphere{
radius IS radius
}
}
}

PROTO colorBall[] {
ball{}
}

DEF balls Transform{
children[
Transform { children[colorBall{}] }
Transform { children[colorBall{}] }
Transform { children[ball{}] }
Transform { children[ball{radius 3}] }
]
}

DEF myScript Script{
field SFNode balls USE balls

directOutput TRUE
url "java script:
function initialize() {
print(balls.children[0].children[0].radius);
print(balls.children[1].children[0].radius);
print(balls.children[2].children[0].radius);
print(balls.children[3].children[0].radius);
}"
}


Any ideas??


Sponsored Links


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