// Copyright 1997-2001 Shout3D LLC. // All rights reserved. package applets; import shout3d.core.Node; import shout3d.core.Renderer; import shout3d.core.Searcher; import shout3d.core.StringArrayField; import shout3d.hanim.Humanoid; import shout3d.hanim.Joint; import shout3d.hanim.Segment; /** * Demonstrates how to obtain references to the humanoids in a scene. */ public class HAnimExaminePanel extends ExaminePanel { private boolean done; public HAnimExaminePanel(HAnimExamineApplet applet) { super(applet); done = false; } /** * Overrides the RenderObserver method implementation in the * ExaminePanel superclass. */ public void onPostRender(Renderer renderer, Object data) { // required to get super class ExaminePanel's full functionality super.onPostRender(renderer, data); if (!done) { Node root = getScene(); Searcher searcher = getNewSearcher(); searcher.setType("Humanoid"); Node[][] paths = searcher.searchAll(root); if (null == paths) System.out.println("no Humanoid nodes found"); else for (int p = 0; p < paths.length; ++p) { Node[] path = paths[p]; Humanoid humanoid = (Humanoid)path[path.length - 1]; dumpHumanoid(humanoid); } done = true; } } private void dumpHumanoid(Humanoid humanoid) { System.out.println(); System.out.println(humanoid.name.getValue() + ": Humanoid"); for (int i = 0; i < humanoid.info.getValue().length; ++i) System.out.println("\t\t" + humanoid.info.getValue()[i]); dumpJoint(getHumanoidRoot(humanoid), 1); System.out.println(); } private void dumpJoint(Joint joint, int level) { for (int i = 0; i < level; ++i) System.out.print("\t"); System.out.println(joint.name.getValue() + ": Joint"); for (int i = 0; i < joint.children.getLength(); ++i) { Node child = joint.children.getValue()[i]; if (child instanceof Joint) dumpJoint((Joint)child, level + 1); else if (child instanceof Segment) dumpSegment((Segment)child, level + 1); } } private void dumpSegment(Segment segment, int level) { for (int i = 0; i < level; ++i) System.out.print("\t"); System.out.println(segment.name.getValue() + ": Segment"); } /** * Returns the first Joint in humanoidBody named HumanoidRoot. * Note that humanoids with more than one root are malformed. */ private Joint getHumanoidRoot(Humanoid humanoid) { Joint root = null; for (int i = 0; i < humanoid.humanoidBody.getLength(); ++i) if (humanoid.humanoidBody.getValue()[i] instanceof Joint) { Joint joint = (Joint)humanoid.humanoidBody.getValue()[i]; if (joint.name.getValue().equals("HumanoidRoot")) { root = joint; break; } } return root; } }