use of javax.media.j3d.BranchGroup in project ffx by mjschnie.
the class MolecularAssembly method createScene.
/**
* The MolecularAssembly BranchGroup has two TransformGroups between it and
* the "base" node where geometry is attached. If the point between the two
* transformations is where user rotation occurs. For example, if rotating
* about the center of mass of the system, the RotToCOM transformation will
* be an identity transformation (ie. none). If rotation is about some atom
* or group of atoms within the system, then the RotToCOM transformation
* will be a translation from that point to the COM.
*
* @param zero boolean
* @return BranchGroup
*/
public BranchGroup createScene(boolean zero) {
originToRotT3D = new Transform3D();
originToRotV3D = new Vector3d();
originToRot = new TransformGroup(originToRotT3D);
branchGroup = new BranchGroup();
rotToCOM = new TransformGroup();
rotToCOMT3D = new Transform3D();
rotToCOMV3D = new Vector3d();
// Set capabilities needed for picking and moving the MolecularAssembly
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Put the MolecularAssembly in the middle of the scene
if (zero) {
originToRotV3D.set(0.0, 0.0, 0.0);
originToRotT3D.set(originToRotV3D);
originToRot.setTransform(originToRotT3D);
}
wire = renderWire();
switchGroup = new Switch(Switch.CHILD_NONE);
switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);
base = new BranchGroup();
base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
childNodes = new BranchGroup();
childNodes.setCapability(BranchGroup.ALLOW_DETACH);
childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
switchGroup.addChild(base);
if (wire != null) {
base.addChild(wire);
}
vrml = loadVRML();
if (vrml != null) {
vrmlTG = new TransformGroup();
vrmlTd = new Transform3D();
vrmlTG.setTransform(vrmlTd);
vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
vrmlTG.addChild(vrml);
switchGroup.addChild(vrmlTG);
setView(RendererCache.ViewModel.INVISIBLE, null);
}
switchGroup.setWhichChild(Switch.CHILD_ALL);
rotToCOM.addChild(switchGroup);
originToRot.addChild(rotToCOM);
branchGroup.addChild(originToRot);
branchGroup.compile();
return branchGroup;
}
use of javax.media.j3d.BranchGroup in project ffx by mjschnie.
the class RendererCache method sphereFactory.
/**
* <p>
* sphereFactory</p>
*
* @param ap a {@link javax.media.j3d.Appearance} object.
* @param div a int.
* @param transform3D a {@link javax.media.j3d.Transform3D} object.
* @return a {@link javax.media.j3d.BranchGroup} object.
*/
public static final BranchGroup sphereFactory(Appearance ap, int div, Transform3D transform3D) {
BranchGroup branchGroup;
if (spherePool.size() > 0) {
branchGroup = spherePool.remove(0);
if (branchGroup != null) {
TransformGroup transformGroup = (TransformGroup) branchGroup.getChild(0);
transformGroup.setTransform(transform3D);
Shape3D sphere = (Shape3D) transformGroup.getChild(0);
sphere.setAppearance(ap);
return branchGroup;
}
}
branchGroup = new BranchGroup();
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
TransformGroup transformGroup = createTransformGroup(transform3D);
Shape3D sphere = createSphere(ap, div);
transformGroup.addChild(sphere);
branchGroup.addChild(transformGroup);
branchGroup.compile();
return branchGroup;
}
use of javax.media.j3d.BranchGroup in project ffx by mjschnie.
the class GraphicsCanvas method attachModel.
/**
* This attaches a MolecularAssembly to the Scene BranchGroup.
*
* @param s MolecularAssembly to attach.
*/
public void attachModel(MolecularAssembly s) {
if (s == null) {
return;
}
synchronized (this) {
BranchGroup bg = s.getBranchGroup();
resetGlobalView();
baseBranchGroup.addChild(bg);
}
}
use of javax.media.j3d.BranchGroup in project ffx by mjschnie.
the class GraphicsCanvas method initialize.
/**
* Initialization of the GraphisCanvas.
*/
private void initialize() {
setBackground(Color.black);
universe = new SimpleUniverse(this);
SimpleUniverse.setJ3DThreadPriority(Thread.MAX_PRIORITY);
universe.getViewingPlatform().setNominalViewingTransform();
// Create the Scene Root BranchGroup
BranchGroup objRoot = new BranchGroup();
baseTransformGroup = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.1d);
baseTransformGroup.setTransform(t3d);
baseTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
baseTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
// Set the Background
Color3f bgColor = new Color3f(RendererCache.BLACK);
background = new Background(bgColor);
background.setCapability(Background.ALLOW_COLOR_READ);
background.setCapability(Background.ALLOW_COLOR_WRITE);
bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 2000.0);
background.setApplicationBounds(bounds);
// Create lights
AmbientLight aLgt = new AmbientLight(new Color3f(Color.darkGray));
aLgt.setInfluencingBounds(bounds);
Vector3f dir = new Vector3f(0.0f, -1.0f, -1.0f);
Color3f dLgtColor = new Color3f(Color.lightGray);
DirectionalLight dLgt = new DirectionalLight(dLgtColor, dir);
dLgt.setInfluencingBounds(bounds);
dir = new Vector3f(0.0f, 1.0f, -1.0f);
dLgtColor = new Color3f(0.1f, 0.1f, 0.1f);
DirectionalLight dLgt2 = new DirectionalLight(dLgtColor, dir);
dLgt2.setInfluencingBounds(bounds);
// Create the Base of the Molecular Scene
baseBranchGroup = new BranchGroup();
baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
baseBranchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
baseBranchGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
// Add children created above to the base TransformGroup
baseTransformGroup.addChild(background);
baseTransformGroup.addChild(baseBranchGroup);
objRoot.addChild(baseTransformGroup);
// Position the view platmform and add lights
View v = universe.getViewer().getView();
v.setProjectionPolicy(View.PARALLEL_PROJECTION);
v.setFrontClipPolicy(View.VIRTUAL_EYE);
v.setFrontClipDistance(1.0);
v.setBackClipPolicy(View.VIRTUAL_EYE);
v.setBackClipDistance(10.0);
v.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_NONE);
Transform3D trans = new Transform3D();
trans.set(new Vector3d(0.0d, 0.0d, 2.0d));
TransformGroup vptg = universe.getViewingPlatform().getViewPlatformTransform();
vptg.setTransform(trans);
BranchGroup viewBranch = new BranchGroup();
viewBranch.addChild(aLgt);
viewBranch.addChild(dLgt);
viewBranch.addChild(dLgt2);
vptg.addChild(viewBranch);
// Initialize Behaviors
graphicsAxis = new GraphicsAxis(universe.getViewingPlatform(), this, bounds);
graphicsEvents = new GraphicsEvents(mainPanel, this, graphicsAxis, universe, bounds, baseBranchGroup, baseTransformGroup);
baseBranchGroup.addChild(graphicsEvents);
rendererPicking = new GraphicsPicking(baseBranchGroup, bounds, this, mainPanel);
baseBranchGroup.addChild(rendererPicking);
renderer = new ffx.potential.Renderer(bounds, mainPanel.getStatusBar());
baseBranchGroup.addChild(renderer);
// Compile the Root BranchGroup and add it to the Universe
objRoot.compile();
universe.addBranchGraph(objRoot);
}
Aggregations