Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  sharedCopy not cloning Apperance?  (Read 718 times)
0 Members and 1 Guest are viewing this topic.
Offline SpuTTer

Senior Devvie


Medals: 1
Exp: 14 years


Lazy Middle Class Intellectual


« Posted 2004-04-14 17:24:45 »

Hey guys. I may have found a bug with the Apperance section of the sharedCopy method, but I'm not positive. This may be a known issue, but I havent seen anyone talk about it directly on the forums here..

Im loading my models using Kevs awesome 3DS loader.

Then Im making a clone of it, so that I can have multiple objects only having to load the model one time. Makes sense right.

The problem I'm having is that when I go to change the Appearance of one of the cloned nodes, it changes the appearance for all nodes. It seems like the Appearance is not getting cloned at all, and that they are using a shared Appearance.


This is my code:


This sets the material.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public void setMaterial(Group group, Material mat) {
     
      java.util.List nodes = group.getChildren();
     
      for (int i = 0; i < nodes.size(); i++) {
            SceneGraphObject obj = (SceneGraphObject) nodes.get(i);
           
            if (obj instanceof Shape3D) {
                  Shape3D sh = (Shape3D) obj;
                  sh.getAppearance().setMaterial(mat);
                  sh.getAppearance().setChanged(true);  // for around for bug
                 
            } else if (obj instanceof Group) {
                  setMaterial( (Group) obj, mat);
            }
      }
}


Load the model from the model store and clone it into the characters branchgroup

1  
2  
3  
4  
TDSModel model = ModelStore.getModel(modelId);

// character is a branchgroup
character = (BranchGroup) model.sharedCopy(model);


Changing the appearance based on who "owns" the Character.

1  
2  
3  
4  
5  
6  
7  
8  
if (player == 1) {
      setMaterial(TextureStore.redMat);
      System.out.println("Color for: "+theName+" changed to red!");
} else
if (player == 2) {
      setMaterial(TextureStore.blueMat);
      System.out.println("Color for: "+theName+" changed to blue!");
                 }




A possible workaround for this is to create a new Appearance in my setMaterial method. I will test this out and see if it works. However, if its just something I'm doing wrong, or a bug, I'd like to know!

Thanks

Sacramento Volleyball
"Whitty phrase goes here."
Offline SpuTTer

Senior Devvie


Medals: 1
Exp: 14 years


Lazy Middle Class Intellectual


« Reply #1 - Posted 2004-04-15 09:12:03 »

Adding the following code for a new appearance and then cloning the old one manually does seem to work. I will use this for now, but hopefully somone can answer the above q's.

Thanks!

1  
2  
3  
4  
5  
6  
7  
8  
Appearance na = new Appearance();

na = (Appearance) sh.getAppearance().cloneNodeComponent(true);

na.setMaterial(mat);
na.setChanged(true);  // for around for bug

sh.setAppearance(na);

Sacramento Volleyball
"Whitty phrase goes here."
Offline Yuri Vl. Gushchin

Senior Devvie




Speak Java!


« Reply #2 - Posted 2004-04-18 11:27:49 »

Here is a quote from JavaDoc:

Quote
A shared copy is one where the geometry and appearance is shared, but all other nodes are copied.  This is a replacement for shared groups because of performance considerations.  If you are loading the same model many times then this can save on memory and load times.  The only allowable within the subtree are groups and shapes. This also copies a shapes bounds and turns autocomute off so that it is fast to insert the model into the scene.


This means that sharedCopy() should not copy the appearance.

I think you should use duplicateNode() instead, but you again should check if that part works as expected because of forceDuplicate support is still not implemented for some nodes.

Yuri

Yuri Vl. Gushchin
JProof Group
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.

rwatson462 (32 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (58 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!