Example usage for javax.media.j3d SceneGraphObject getCapability

List of usage examples for javax.media.j3d SceneGraphObject getCapability

Introduction

In this page you can find the example usage for javax.media.j3d SceneGraphObject getCapability.

Prototype

public final boolean getCapability(int bit) 

Source Link

Document

Retrieves the specified capability bit.

Usage

From source file:Capabilities.java

/**
 * Return an array of capability bits for the object
 *
 * If no capabilities are set then an array of length 0 is returned
 *
 * @param obj The object for which to extract the capability bits
 *///from w  ww  .j  av a 2  s .co  m
public static int[] getCapabilities(javax.media.j3d.SceneGraphObject obj) {
    ArrayList bits = new ArrayList();

    int value;
    String str;
    Class cl = obj.getClass();

    java.lang.reflect.Field[] fields = cl.getFields();

    try {
        for (int i = 0; i < fields.length; i++) {
            str = fields[i].getName();
            value = fields[i].getInt(fields[i]);
            if (str.indexOf("ALLOW_") != -1 || str.indexOf("ENABLE_") != -1) {
                if (obj.getCapability(value))
                    bits.add(new Integer(value));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Internal Error");
    }

    int[] ret = new int[bits.size()];
    for (int i = 0; i < ret.length; i++)
        ret[i] = ((Integer) bits.get(i)).intValue();

    return ret;
}

From source file:Capabilities.java

/** Extract the names of all the SET capabilities in the object.
* The names (Strings) are appended to the arrayList
* @param obj The object for which to extract the capability strings
* @param capabilityStrings The ArrayList to which the capability names will be appended
*///from   w w w .  j  a va2s .  c  o m
public static void getCapabilities(javax.media.j3d.SceneGraphObject obj,
        java.util.ArrayList capabilityStrings) {

    int value;
    String str;
    Class cl = obj.getClass();

    java.lang.reflect.Field[] fields = cl.getFields();

    try {
        for (int i = 0; i < fields.length; i++) {
            str = fields[i].getName();
            value = fields[i].getInt(fields[i]);
            if (str.indexOf("ALLOW") != -1 || str.indexOf("ENABLE_") != -1) {
                if (obj.getCapability(value))
                    capabilityStrings.add(str);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Internal Error");
    }
}

From source file:TreePrinter.java

private void printNode(Object o, int indent, Set sharedGroups) {
    for (int i = 0; i < indent; i++)
        printStream.print(">");
    printStream.print(nodeString(o) + ": ");
    if (o instanceof SceneGraphObject) {
        SceneGraphObject sgo = (SceneGraphObject) o;
        int capBits = 0;
        // TODO: how to make sure we always check all the valid bits?
        for (int i = 0; i < 64; i++) {
            if (sgo.getCapability(i)) {
                capBits |= 1 << i;
            }//from  w  w w  .  java 2s.  c o  m
        }
        printStream.print("capBits:Ox" + Integer.toHexString(capBits));
        if (o instanceof javax.media.j3d.Group) {
            javax.media.j3d.Group g = (javax.media.j3d.Group) o;
            int numChildren = 0;
            try {
                numChildren = g.numChildren();
            } catch (CapabilityNotSetException e) {
                //anyone who is using treePrinter, is debugging, so it is
                //alright to blindly allow read. you should first detach
                //browser.curScene, print the tree, then add it back to
                //browser.locale when finished.
                g.setCapability(javax.media.j3d.Group.ALLOW_CHILDREN_READ);
                numChildren = g.numChildren();
                //System.out.println("Can't read children on group");
                //return;
            }
            printStream.print(" children:" + numChildren);
            if (o instanceof TransformGroup) {
                Transform3D transform = new Transform3D();
                Transform3D identity = new Transform3D();
                TransformGroup t = (TransformGroup) o;
                t.getTransform(transform);
                // TODO: use getBestType() when implemented
                if (transform.equals(identity)) {
                    printStream.print(" xform:IDENTITY ");
                } else {
                    printStream.print(" xform:NON-IDENTITY ");
                }
            }
        } else if (o instanceof Link) {
            Link l = (Link) o;
            SharedGroup sg = l.getSharedGroup();
            printStream.print(" sg:" + nodeString(sg));
            sharedGroups.add(sg);
        } else {
            printStream.print(": leaf");
        }
    }
    printStream.println();
}