Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Multiple copy of a shape3D  (Read 2832 times)
0 Members and 1 Guest are viewing this topic.
Offline mksingh1

Senior Newbie





« Posted 2006-11-16 12:39:17 »

Hey Guys...!!!
if i need to make multiple copy of a shape3D object..then how can i do that?? For example...if there is an shape 3D object Sphere and i want to make 20 copies of that object then what should i do....Huh is there any method in Xith ,which can help me....
plzzz let me know......
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« Reply #1 - Posted 2006-11-16 20:06:29 »

Hey Guys...!!!
if i need to make multiple copy of a shape3D object..then how can i do that?? For example...if there is an shape 3D object Sphere and i want to make 20 copies of that object then what should i do....Huh is there any method in Xith ,which can help me....
plzzz let me know......

I guess, you're talking about displaying one Shape3D multiple times in a scene, aren't you?

If you want to do so, then Links and SharedGroups are your friends. The Shape must be put into an instance of SharedGroup and this can be put into any number og Link instances.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
Shape3D shape = new Shape3D(); ....
SharedGroup sg = new SharedGroup();
sg.addChild( shape );

Link link1 = new Links( sg );
anyGroupABC1.addChild( link1 );

Link link2 = new Links( sg );
anyGroupABC2.addChild( link2 );

Link link3 = new Links( sg );
anyGroupABC3.addChild( link3 );


If you were talking about actually copying the shapes, then you'll have to do it by hand, since the close methods don't work so far. But it's not too heavy. You can even reuse the Geometry, Appearance, Meterial, etc. instances.

Hope, this helps you Smiley

Marvin
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #2 - Posted 2006-11-17 15:23:47 »

Welcome back, mksingh1! So you using Xith? Cool!  Cool

If you were talking about actually copying the shapes, then you'll have to do it by hand, since the close methods don't work so far
You mean the "clone" methods ? No use ! It's rubbish to use clone() anyway (well that's what I found out, having tried to). sharedCopy() works very well, if you want a *real* copy then.. there are some, can't remember which (if you're interested let me know).
Just as a side-note : shared copies use less memory and are faster to make. Links are even better.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mksingh1

Senior Newbie





« Reply #3 - Posted 2006-11-20 05:39:22 »

thanks Wenger... Smiley
as you have mentioned that if i want to make real copies,then there are some methods in Xith,which can help....
actually i didn't get the idea of  "real" copies...can u plz tell what does you mean by REAL copiesand what are the methods to create them....
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #4 - Posted 2006-11-20 20:42:47 »

thanks Wenger... Smiley
as you have mentioned that if i want to make real copies,then there are some methods in Xith,which can help....
actually i didn't get the idea of  "real" copies...can u plz tell what does you mean by REAL copiesand what are the methods to create them....
sorry I didn't explained acceptably.

So our scenegraph is acyclic. That does mean that nodes can't have more than one parents (that is, they cannot be added twice, cannot exists in two places of the scenegraph).

So you can not just make :
1  
2  
3  
4  
5  
Shape3D sphere = new Sphere(10, 10, 2f); // Create a sphere with a radius of 2f, and a precision of 10
// Add 20 spheres
for(int i = 0; i < 20; i++) {
  scene.addChild((new Transform(model)).setTranslationX(model)); // ILLEGAL ! Shape added more than once
}


However, what you can make is to clone the Shape3D
1  
2  
3  
4  
5  
Shape3D sphere = new Sphere(10, 10, 2f); // Create a sphere with a radius of 2f, and a precision of 10
// Add 20 spheres
for(int i = 0; i < 20; i++) {
  scene.addChild((new Transform((Shape3D)model.clone())).setTranslationX(model)); // Notice the clone() method
}


This makes a "real" copy of the shape, which means everything is copied (Shape3D, Appearance, Material, all Attributes, + Geometry, all vertex data, texture UV, and so on).
This is bad from a memory and loading time / run time point of view, because all data is duplicated.

What you can do to reduce memory usage and load/run time is to make shared copies :
1  
2  
3  
4  
5  
Shape3D sphere = new Sphere(10, 10, 2f); // Create a sphere with a radius of 2f, and a precision of 10
// Add 20 spheres
for(int i = 0; i < 20; i++) {
  scene.addChild((new Transform((Shape3D)model.sharedCopy())).setTranslationX(model)); // Notice the sharedCopy() method
}


This won't copy e.g. vertex data, UV, but just creates a new Shape3D and assign the same Material & Appearance objects.

Even better is creating links :
1  
2  
3  
4  
5  
6  
7  
8  
Shape3D sphere = new Sphere(10, 10, 2f); // Create a sphere with a radius of 2f, and a precision of 10
SharedGroup sg = new SharedGroup(); // Shared group creation
sg.addChild(sphere); // Add the sphere to the shared group
// Add 20 spheres
for(int i = 0; i < 20; i++) {
  Link l = new Link(sg);
  scene.addChild((new Transform(l).setTranslationX(model)); // Notice the clone() method
}

In this case, the Link points to a SharedGroup which can be rendered any number of times. The benefit is that no duplicate Shape3D objects are created, just links... and anything can be added to Links..

A last thing : beware of shared copies : if you change something in the geometry of one it will change every other.. but it's probably not a problem.

I hope you got my point, if it was clear enough I'll make a code example in W3G for that..

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« Reply #5 - Posted 2006-11-20 21:08:41 »

... and anything can be added to Links..

Well, only one SharedGroup can be set to a Link Grin. Anything can be added to a SharedGroup Wink.

In most cases you'll want to add only one Node (a model, etc...) to a SharedGroup. I've just created a convenience constructor to make this:
1  
2  
SharedGroup sg = new SharedGroup();
sg.addChild( myModel );

possible in one line:
1  
SharedGroup sg = new SharedGroup( myModel );


I think it could be worthy Smiley.

Marvin
Offline mksingh1

Senior Newbie





« Reply #6 - Posted 2006-11-21 05:18:49 »

Thanks Wenger...thanks for sharing your knowledge with me...its reall gonna help me alot..... Smiley
Offline mksingh1

Senior Newbie





« Reply #7 - Posted 2006-11-21 05:34:11 »

i know i m being greedy... Wink but i m very new into this...so plzzzzzz....

if i have copied any shape3D object and now i want to paste it on mouseclick position,then how i can u do it.....n i dont want to delete the original copy...its like normal copy-paste functionality...
for ex- i have copied a rectangle and now i want to paste it on mouseclick position ,then how can i do it?Huh
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« Reply #8 - Posted 2006-11-21 18:44:02 »

for ex- i have copied a rectangle and now i want to paste it on mouseclick position ,then how can i do it?Huh

Have a look at org.xith3d.picking.PickRay
It creates a ray from canvas coordiantes to world coordinates starting at the mouse position and points ortogonally into the depth. You just need to set the depth component and you'll have the 3d-coordinate in space.

Marvin
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #9 - Posted 2006-11-21 19:17:20 »

i know i m being greedy... Wink but i m very new into this...so plzzzzzz....

if i have copied any shape3D object and now i want to paste it on mouseclick position,then how i can u do it.....n i dont want to delete the original copy...its like normal copy-paste functionality...
for ex- i have copied a rectangle and now i want to paste it on mouseclick position ,then how can i do it?Huh

So I assume you infact work on a 2D plane.

When working with a mouse in 3D, you must understand that your mouse position (point : x,y) on your 2D screen is infact a ray in your 3D world (x,y,z). So if you want to restrict your objects to a plane, then you can do picking on a specific plane..

Just create a plane for example if your "up" vector is +Z do :

1  
2  
3  
Quad workPlane = new Quad(80000f, 80000f);
BranchGroup pickable = new BranchGroup();
pickable.add(workPlane);

1  
Shape shape = new Sphere(10, 10, 3f);

1  
2  
3  
4  
5  
6  
7  
8  
// When you want to add a copied shape
mouseReleased(int button, int x, int y) {
  PickResult pr = PickingLibrary.pickNearest(pickable, x, y);
  if(pr != null) {
    Transform t = (new Transform(shape)).setTranslation(pr.getPosition());
    scene.addChild(t);
  }
}


And that's it !

Be aware, though, that this does not provide a way to remove them.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Marvin Fröhlich

Senior Member




May the 4th, be with you...


« Reply #10 - Posted 2006-11-21 19:55:25 »

Well, keep in mind, that picking needs to be synchronized with the rendering thread. That can be done by wrapping the pikcing code with
1  
2  
3  
4  
synchronized ( env.getUniverse() )
{
    // your picking code...
}

or scheduled with
1  
env.pick*(...);

Please refer to org.xith3d.test.picking.ScheduledPickingTest for exact syntax.

Marvin
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Reply #11 - Posted 2006-11-21 21:51:52 »

Yeah, sure but I was assuming he did that in the loopIteration() method...

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (64 views)
2014-04-15 18:08:23

BurntPizza (62 views)
2014-04-15 03:46:01

UprightPath (75 views)
2014-04-14 17:39:50

UprightPath (58 views)
2014-04-14 17:35:47

Porlus (76 views)
2014-04-14 15:48:38

tom_mai78101 (101 views)
2014-04-10 04:04:31

BurntPizza (161 views)
2014-04-08 23:06:04

tom_mai78101 (256 views)
2014-04-05 13:34:39

trollwarrior1 (209 views)
2014-04-04 12:06:45

CJLetsGame (216 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!