# Picking und Farbe ändern



## truesoul (28. Apr 2010)

Guten Tag allerseits, 

also ich möchte gerne die Farbe von dem "gepickten" Objekt ändern bzw seine Eigentschaften.
Nur leider weiß ich nicht so genau wie ich es anzustellen haben.
Ich lade per vrml loader drei .wrl dateien. 
Und danach kommt die übliche Prozedur ( Siehe Code ). 

Die relevanten Methoden .


```
public BranchGroup macheSzenengraph()
{
    Loader f = new VrmlLoader();
    Scene []s = new Scene[Anzahl];


    try
    {
        s[0] = f.load("test/layoutparo_how-turm.wrl");
        s[1] = f.load("test/layoutparo_ausl-vertikw.wrl");
        s[2] = f.load("test/boa_0000.wrl");


    }
    catch (FileNotFoundException e)
    {
    System.err.println(e);
    System.exit(1);
    }
    catch (ParsingErrorException e)
    {
    System.err.println(e);
    System.exit(1);
    }
    catch (IncorrectFormatException e)
    {
    System.err.println(e);
    System.exit(1);
    }

    // Shape3D (global)
    gepickt.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    erstelleBranch(s);
    setBackdist(s);

    //objWurzel.addChild(erstelleBehaviorsGroup());
    objWurzel.addChild(createBackground());
    objWurzel.addChild(erstelleDirectLight());
    objWurzel.addChild(erstelleAmbientLight());
    objWurzel.addChild(new Shape3D(erstelleAchseX()));
    objWurzel.addChild(new Shape3D(erstelleAchseY()));
    objWurzel.addChild(new Shape3D(erstelleAchseZ()));

    objWurzel.addChild(ViewTG1);
    
    erstelleKeyBehavior();

    
    return objWurzel;
}

public void ObjektSelektiert(MouseEvent e){
    System.out.println("*** MouseClick ***");

    pickCanvas = new PickCanvas(c, objWurzel);
    pickCanvas.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
    pickCanvas.setTolerance(0f);
    pickCanvas.setShapeLocation(e);

    Node picked;
    
    PickResult[] results = pickCanvas.pickAllSorted();


    if (results != null) {
      for (int n = 0; n < results.length; n++) {
        PickResult pickResult = results[n];
        picked = results[n].getObject();
        System.out.println("Node: "+ picked);
        
        gepickt = (Shape3D)picked;

       /*
        * anschliessend hier setAppearance() ... leider kommt dann eine Exception
        */

        System.out.println("Sortiertes PickResult " + n + ": \n" + pickResult.getLocalToVworld());
        
      }
    }
  }

private void erstelleBranch(Scene scene[]){

        Objekt_Array = new TransformGroup[Anzahl];
        Transform3D D3 = new Transform3D();

        D3.setScale(Skalierung);
        for(int i = 0;i < Objekt_Array.length;i++){
            D3.setTranslation(new Vector3f(X_Position, Y_Position, Z_Position));
            Objekt_Array[i] = new TransformGroup();

            Objekt_Array[i].setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
            Objekt_Array[i].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
            Objekt_Array[i].setCapability(TransformGroup.ENABLE_PICK_REPORTING);
            Objekt_Array[i].setTransform(D3);
            Objekt_Array[i].addChild(scene[i].getSceneGroup());
            
            Objekt_Array[i].addChild(erstelleBehaviorsGroup());
            
            objWurzel.addChild(Objekt_Array[i]);
        }
    }
```
:

Ich bedanke mich schonmal für jede Hilfe.

Mfg


----------



## Marco13 (28. Apr 2010)

Wenn man eine Shape3D hat, und dort ALLOW_APPEARANCE_WRITE gesetzt ist, sollte man mit setAppearance eigentlich die Farbe ändern können...


----------



## truesoul (29. Apr 2010)

Hmmm , so hab ich mir es gedacht.
Die ALLOW_APPEARANCE_WRITE hab ich beim erstellen vom Branchgroup (macheSzenegraph()) gesetzt.
Ich habe eine Globale Shape3D Variable , und dafür halt den Capability gesetzt.
Dann habe ich in ObjektSelektiert() das gepickte Objekt der globalen Shape3D übergeben.
Aber sobald ich dann setAppearance(new Appearance()) setze bekomme ich eine

CapabilityNotSetException: Shape3D: no capability to set appearance.

Also habe ich wohl die Capability falsch gesetzt?!

So sieht das Objekt ( datei von Ihnen ) aus:


```
#VRML V2.0 utf8
Transform {
children [
Shape {
appearance Appearance {
material Material {
ambientIntensity 1.000000
diffuseColor 0.752941 0.752941 0.752941
emissiveColor 0.158118 0.158118 0.158118
specularColor 0.662588 0.662588 0.662588
shininess 0.210000
transparency 0.000000
}
}
geometry IndexedFaceSet {
color Color {
color [
 0.752941 0.752941 0.752941
]
}
coord Coordinate {
point [
 -279.268555 151.965546 0.000000, -279.268555 151.965546 3585.000000, -278.601563 143.891037 0.000000, -278.601563 143.891037 3585.000000, -277.853943 159.943100 0.000000,
 -277.853943 159.943100 3585.000000, -275.897064 136.253754 0.000000, -275.897064 136.253754 3585.000000, -274.451263 167.295929 0.000000, -274.451263 167.295929 3585.000000,
 -271.333954 129.558929 0.000000, -271.333954 129.558929 3585.000000, -269.285614 173.537643 0.000000, -269.285614 173.537643 3585.000000, -265.214142 124.249466 0.000000,
 -265.214142 124.249466 3585.000000, -262.698792 178.255295 0.000000, -262.698792 178.255295 3585.000000, -257.942474 120.676613 0.000000, -257.942474 120.676613 3585.000000,
 -255.126511 181.136765 0.000000, -255.126511 181.136765 3585.000000, -250.000000 119.076729 -0.000000, -250.000000 119.076729 3585.000000, -247.069702 181.991470 0.000000,
 -247.069702 181.991470 3585.000000, -241.673355 -0.000000 -0.000000, -241.673355 -0.000000 3585.000000, -239.061386 180.762848 0.000000, -239.061386 180.762848 3585.000000,
 -231.631363 177.532181 0.000000, -231.631363 177.532181 3585.000000, -225.271149 172.513184 0.000000, -225.271149 172.513184 3585.000000, -220.401520 166.037918 0.000000,
 -220.401520 166.037918 3585.000000, -217.344604 158.534729 0.000000, -217.344604 158.534729 3585.000000, -216.302673 150.500000 0.000000, -216.302673 150.500000 3585.000000,
 220.697327 150.500000 0.000000, 220.697327 150.500000 3585.000000, 221.689835 158.344940 0.000000, 221.689835 158.344940 3585.000000, 224.604828 165.695511 0.000000,
 224.604828 165.695511 3585.000000, 229.258591 172.088531 0.000000, 229.258591 172.088531 3585.000000, 235.357895 177.121109 0.000000, 235.357895 177.121109 3585.000000,
 241.673355 0.000000 0.000000, 241.673355 0.000000 3585.000000, 242.518356 180.476120 0.000000, 242.518356 180.476120 3585.000000, 250.000000 119.076729 -0.000000,
 250.000000 119.076729 3585.000000, 250.288757 181.942123 0.000000, 250.288757 181.942123 3585.000000, 257.895050 119.519592 0.000000, 257.895050 119.519592 3585.000000,
 258.179382 181.426758 0.000000, 258.179382 181.426758 3585.000000, 265.431091 121.914726 0.000000, 265.431091 121.914726 3585.000000, 265.693085 178.962494 0.000000,
 265.693085 178.962494 3585.000000, 272.133148 126.111206 0.000000, 272.133148 126.111206 3585.000000, 272.356323 174.704636 0.000000, 272.356323 174.704636 3585.000000,
 277.578918 131.844589 0.000000, 277.578918 131.844589 3585.000000, 277.749207 168.921478 0.000000, 277.749207 168.921478 3585.000000, 281.425232 138.753571 0.000000,
 281.425232 138.753571 3585.000000, 281.531921 161.977448 0.000000, 281.531921 161.977448 3585.000000, 283.429749 146.402771 0.000000, 283.429749 146.402771 3585.000000,
 283.466034 154.310165 0.000000, 283.466034 154.310165 3585.000000
]
}
normal Normal {
vector [
 -1.000000 0.000000 0.000000, -0.998917 0.046525 0.000000, -0.997564 -0.069756 0.000000, -0.977743 -0.209808 0.000000, -0.968492 0.249046 0.000000,
 -0.954008 0.299781 0.000000, -0.891885 -0.452262 0.000000, -0.875952 0.482398 0.000000, -0.845986 0.533204 0.000000, -0.747025 -0.664796 0.000000,
 -0.728214 0.685350 0.000000, -0.681998 0.731354 0.000000, -0.552745 -0.833350 0.000000, -0.534585 0.845115 0.000000, -0.472893 0.881120 0.000000,
 -0.321899 -0.946774 0.000000, -0.307269 0.951623 0.000000, -0.232502 0.972596 0.000000, -0.069756 -0.997564 0.000000, -0.060590 0.998163 0.000000,
 0.000000 -1.000000 0.000000, 0.000000 0.000000 -1.000000, 0.000000 0.000000 1.000000, 0.000000 1.000000 0.000000, 0.023269 0.999729 0.000000,
 0.180881 -0.983505 0.000000, 0.189907 0.981802 0.000000, 0.277501 0.960725 0.000000, 0.420119 -0.907469 0.000000, 0.428437 0.903572 0.000000,
 0.513375 0.858164 0.000000, 0.632883 -0.774247 0.000000, 0.639969 0.768401 0.000000, 0.715286 0.698832 0.000000, 0.805765 -0.592235 0.000000,
 0.811171 0.584809 0.000000, 0.869878 0.493267 0.000000, 0.927871 -0.372903 0.000000, 0.931257 0.364364 0.000000, 0.966922 0.255071 0.000000,
 0.991505 -0.130071 0.000000, 0.992658 0.120958 0.000000, 0.997564 -0.069756 0.000000, 1.000000 0.000000 0.000000
]
}
coordIndex [
 27, 23, 26, -1, 26, 23, 22, -1, 51, 27, 50, -1,
 50, 27, 26, -1, 55, 51, 54, -1, 54, 51, 50, -1,
 55, 54, 58, -1, 55, 58, 59, -1, 59, 58, 62, -1,
 59, 62, 63, -1, 63, 62, 66, -1, 63, 66, 67, -1,
 67, 66, 70, -1, 67, 70, 71, -1, 71, 70, 74, -1,
 71, 74, 75, -1, 75, 74, 78, -1, 75, 78, 79, -1,
 79, 78, 80, -1, 79, 80, 81, -1, 81, 80, 76, -1,
 81, 76, 77, -1, 77, 76, 72, -1, 77, 72, 73, -1,
 73, 72, 68, -1, 73, 68, 69, -1, 69, 68, 64, -1,
 69, 64, 65, -1, 65, 64, 60, -1, 65, 60, 61, -1,
 61, 60, 56, -1, 61, 56, 57, -1, 57, 56, 52, -1,
 57, 52, 53, -1, 53, 52, 48, -1, 53, 48, 49, -1,
 49, 48, 46, -1, 49, 46, 47, -1, 47, 46, 44, -1,
 47, 44, 45, -1, 45, 44, 42, -1, 45, 42, 43, -1,
 43, 42, 40, -1, 43, 40, 41, -1, 39, 41, 38, -1,
 38, 41, 40, -1, 39, 38, 36, -1, 39, 36, 37, -1,
 37, 36, 34, -1, 37, 34, 35, -1, 35, 34, 32, -1,
 35, 32, 33, -1, 33, 32, 30, -1, 33, 30, 31, -1,
 31, 30, 28, -1, 31, 28, 29, -1, 29, 28, 24, -1,
 29, 24, 25, -1, 25, 24, 20, -1, 25, 20, 21, -1,
 21, 20, 16, -1, 21, 16, 17, -1, 17, 16, 12, -1,
 17, 12, 13, -1, 13, 12, 8, -1, 13, 8, 9, -1,
 9, 8, 4, -1, 9, 4, 5, -1, 5, 4, 0, -1,
 5, 0, 1, -1, 1, 0, 2, -1, 1, 2, 3, -1,
 3, 2, 6, -1, 3, 6, 7, -1, 7, 6, 10, -1,
 7, 10, 11, -1, 11, 10, 14, -1, 11, 14, 15, -1,
 15, 14, 18, -1, 15, 18, 19, -1, 19, 18, 22, -1,
 19, 22, 23, -1, 19, 23, 39, -1, 23, 27, 39, -1,
 39, 27, 51, -1, 39, 51, 41, -1, 41, 51, 55, -1,
 41, 55, 43, -1, 19, 1, 15, -1, 15, 1, 3, -1,
 15, 3, 11, -1, 11, 3, 7, -1, 67, 71, 63, -1,
 63, 71, 75, -1, 63, 75, 59, -1, 59, 75, 79, -1,
 59, 79, 55, -1, 55, 79, 81, -1, 55, 81, 77, -1,
 43, 49, 45, -1, 45, 49, 47, -1, 19, 39, 1, -1,
 1, 39, 37, -1, 1, 37, 35, -1, 43, 55, 49, -1,
 49, 55, 57, -1, 49, 57, 53, -1, 61, 57, 65, -1,
 65, 57, 55, -1, 65, 55, 69, -1, 69, 55, 77, -1,
 69, 77, 73, -1, 17, 13, 21, -1, 21, 13, 29, -1,
 21, 29, 25, -1, 31, 29, 33, -1, 33, 29, 13, -1,
 33, 13, 35, -1, 35, 13, 9, -1, 35, 9, 1, -1,
 1, 9, 5, -1, 34, 36, 38, -1, 6, 2, 0, -1,
 76, 80, 54, -1, 54, 80, 78, -1, 32, 34, 12, -1,
 50, 26, 54, -1, 54, 26, 38, -1, 54, 38, 40, -1,
 48, 52, 54, -1, 54, 52, 56, -1, 72, 76, 68, -1,
 68, 76, 54, -1, 68, 54, 64, -1, 64, 54, 56, -1,
 64, 56, 60, -1, 78, 74, 70, -1, 12, 34, 8, -1,
 46, 48, 44, -1, 44, 48, 54, -1, 44, 54, 42, -1,
 42, 54, 40, -1, 26, 22, 38, -1, 38, 22, 18, -1,
 38, 18, 14, -1, 0, 4, 8, -1, 58, 54, 62, -1,
 62, 54, 78, -1, 62, 78, 66, -1, 66, 78, 70, -1,
 8, 34, 0, -1, 0, 34, 38, -1, 0, 38, 6, -1,
 6, 38, 14, -1, 6, 14, 10, -1, 12, 16, 20, -1,
 28, 30, 32, -1, 32, 12, 28, -1, 28, 12, 20, -1,
 28, 20, 24, -1
]
normalIndex [
 2, 2, 2, -1, 2, 2, 2, -1, 20, 20, 20, -1,
 20, 20, 20, -1, 42, 42, 42, -1, 42, 42, 42, -1,
 18, 18, 25, -1, 18, 25, 25, -1, 25, 25, 28, -1,
 25, 28, 28, -1, 28, 28, 31, -1, 28, 31, 31, -1,
 31, 31, 34, -1, 31, 34, 34, -1, 34, 34, 37, -1,
 34, 37, 37, -1, 37, 37, 40, -1, 37, 40, 40, -1,
 40, 40, 41, -1, 40, 41, 41, -1, 41, 41, 38, -1,
 41, 38, 38, -1, 38, 38, 35, -1, 38, 35, 35, -1,
 35, 35, 32, -1, 35, 32, 32, -1, 32, 32, 29, -1,
 32, 29, 29, -1, 29, 29, 26, -1, 29, 26, 26, -1,
 26, 26, 19, -1, 26, 19, 19, -1, 19, 19, 16, -1,
 19, 16, 16, -1, 16, 16, 13, -1, 16, 13, 13, -1,
 13, 13, 10, -1, 13, 10, 10, -1, 10, 10, 7, -1,
 10, 7, 7, -1, 7, 7, 4, -1, 7, 4, 4, -1,
 4, 4, 0, -1, 4, 0, 0, -1, 23, 23, 23, -1,
 23, 23, 23, -1, 43, 43, 39, -1, 43, 39, 39, -1,
 39, 39, 36, -1, 39, 36, 36, -1, 36, 36, 33, -1,
 36, 33, 33, -1, 33, 33, 30, -1, 33, 30, 30, -1,
 30, 30, 27, -1, 30, 27, 27, -1, 27, 27, 24, -1,
 27, 24, 24, -1, 24, 24, 17, -1, 24, 17, 17, -1,
 17, 17, 14, -1, 17, 14, 14, -1, 14, 14, 11, -1,
 14, 11, 11, -1, 11, 11, 8, -1, 11, 8, 8, -1,
 8, 8, 5, -1, 8, 5, 5, -1, 5, 5, 1, -1,
 5, 1, 1, -1, 1, 1, 3, -1, 1, 3, 3, -1,
 3, 3, 6, -1, 3, 6, 6, -1, 6, 6, 9, -1,
 6, 9, 9, -1, 9, 9, 12, -1, 9, 12, 12, -1,
 12, 12, 15, -1, 12, 15, 15, -1, 15, 15, 18, -1,
 15, 18, 18, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 22, 22, 22, -1, 22, 22, 22, -1,
 22, 22, 22, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1, 21, 21, 21, -1, 21, 21, 21, -1,
 21, 21, 21, -1
]
colorPerVertex FALSE
normalPerVertex TRUE
}
}
]
}
```

In welcher der drei Methoden muss ich die Capability setzen?


----------



## Marco13 (29. Apr 2010)

Was "gepickt" ist, und speziell auf welchem Objekt nun
gepickt.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
aufgerufen wird, erkennt man nicht. Aber das muss auf allen Shape3D-Objekten aufgerufen werden. Evtl. muss man erstmal den ganzen Szenegraph nach Shape3D-Objekten durchsuchen, und das bei ALLEN setzen...?


----------

