⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view3dwindow.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
		}    }    /*****************************************************************************     *          Demo Stuff                                                       *     *****************************************************************************/    /**     * Method to create spline interpolator for demo mode     */    private void setInterpolator()    {        Transform3D yAxis = new Transform3D();        List<J3DUtils.ThreeDDemoKnot> polys = new ArrayList<J3DUtils.ThreeDDemoKnot>();        double [] zValues = new double[2];        cell.getZValues(zValues);        double zCenter = (zValues[0] + zValues[1])/2;        Rectangle2D bounding = cell.getBounds();        Vector3d translation = new Vector3d (bounding.getCenterX(), bounding.getCenterY(), zCenter);        yAxis.setTranslation(translation);        for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext();)        {            NodeInst ni = it.next();            if (ni.getProto() == Artwork.tech().pinNode)            {                Rectangle2D rect = ni.getBounds();                Variable var = ni.getVar("3D_Z_VALUE");                double zValue = (var == null) ? zCenter : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_SCALE_VALUE");                double scale = (var == null) ? 1 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_HEADING_VALUE");                double heading = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_PITCH_VALUE");                double pitch = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_BANK_VALUE");                double bank = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_ROTX_VALUE");                double rotX = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_ROTY_VALUE");                double rotY = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                var = ni.getVar("3D_ROTZ_VALUE");                double rotZ = (var == null) ? 0 : TextUtils.atof(var.getObject().toString());                J3DUtils.ThreeDDemoKnot knot = new J3DUtils.ThreeDDemoKnot(rect.getCenterX(), rect.getCenterY(),                        zValue, scale, heading, pitch, bank, rotX, rotY, rotZ);                polys.add(knot);            }        }        if (polys.size() == 0) return; // nothing to create        KBKeyFrame[] splineKeyFrames = new KBKeyFrame[polys.size()];        TCBKeyFrame[] keyFrames = new TCBKeyFrame[polys.size()];        for (int i = 0; i < polys.size(); i++)        {            J3DUtils.ThreeDDemoKnot knot = polys.get(i);            splineKeyFrames[i] = J3DUtils.getNextKBKeyFrame((float)((float)i/(polys.size()-1)), knot);            keyFrames[i] = J3DUtils.getNextTCBKeyFrame((float)((float)i/(polys.size()-1)), knot);        }        Interpolator tcbSplineInter = new RotPosScaleTCBSplinePathInterpolator(J3DUtils.jAlpha, objTrans,                                                  yAxis, keyFrames);        tcbSplineInter.setSchedulingBounds(J3DUtils.infiniteBounds);        tcbSplineInter.setEnable(false);        interpolatorMap.put(objTrans, tcbSplineInter);        objTrans.addChild(tcbSplineInter);    }    /**     * Method to create a path interpolator using knots     * defined in input list     * @param knotList list with knot data. If null, search for data attached to nodes     */    public Map<TransformGroup,BranchGroup> addInterpolator(List<J3DUtils.ThreeDDemoKnot> knotList)    {        if (knotList != null && knotList.size() < 2)        {            System.out.println("Needs at least 2 frams for the interpolator");            return null;        }        Map<TransformGroup,BranchGroup> interMap = new HashMap<TransformGroup,BranchGroup>(1);        for (Iterator<NodeInst> it = cell.getNodes(); it.hasNext();)        {            NodeInst ni = it.next();            Variable var = ni.getVar("3D_NODE_DEMO");            if (var == null) continue;            List<J3DUtils.ThreeDDemoKnot> tmpList = knotList;            if (tmpList == null)            {                tmpList = J3DUtils.readDemoDataFromFile(this);                if (tmpList == null) continue; // nothing load            }            List<Node> list = electricObjectMap.get(ni);            for (int j = 0; j < list.size(); j++)            {                Node obj = list.get(j);                TransformGroup grp = transformGroupMap.get(obj);                interMap = addInterpolatorPerGroup(tmpList, grp, interMap, false);//                BranchGroup behaviorBranch = new BranchGroup();//                behaviorBranch.setCapability(BranchGroup.ALLOW_DETACH); // to detach this branch from parent group//                TCBKeyFrame[] keyFrames = new TCBKeyFrame[tmpList.size()];//                for (int i = 0; i < tmpList.size(); i++)//                {//                    J3DUtils.ThreeDDemoKnot knot = tmpList.get(i);//                    keyFrames[i] = J3DUtils.getNextTCBKeyFrame((float)((float)i/(tmpList.size()-1)), knot);//                }//                Transform3D yAxis = new Transform3D();//                Interpolator tcbSplineInter = new RotPosScaleTCBSplinePathInterpolator(J3DUtils.jAlpha, grp,//                                                          yAxis, keyFrames);//                tcbSplineInter.setSchedulingBounds(new BoundingSphere(new Point3d(), Double.MAX_VALUE));//                behaviorBranch.addChild(tcbSplineInter);//                interMap.put(grp, behaviorBranch);//                grp.addChild(behaviorBranch);//                interpolatorMap.put(grp, tcbSplineInter);            }        }        return interMap;    }    /**     * Method to add interpolator per group     * @param knotList     * @param grp     * @param interMap     * @return Map with interpolation groups     */    public Map<TransformGroup,BranchGroup> addInterpolatorPerGroup(List<J3DUtils.ThreeDDemoKnot> knotList, TransformGroup grp, Map<TransformGroup,BranchGroup> interMap, boolean useView)    {        if (knotList == null || knotList.size() < 2)        {            System.out.println("Needs at least 2 frams for the interpolator");            return null;        }        if (interMap == null)            interMap = new HashMap<TransformGroup,BranchGroup>(1);        if (grp == null)        {            if (!useView) grp = objTrans;            else grp = u.getViewingPlatform().getViewPlatformTransform();        }        BranchGroup behaviorBranch = new BranchGroup();        behaviorBranch.setCapability(BranchGroup.ALLOW_DETACH); // to detach this branch from parent group        TCBKeyFrame[] keyFrames = new TCBKeyFrame[knotList.size()];        for (int i = 0; i < knotList.size(); i++)        {            J3DUtils.ThreeDDemoKnot knot = knotList.get(i);            keyFrames[i] = J3DUtils.getNextTCBKeyFrame((float)((float)i/(knotList.size()-1)), knot);        }        Transform3D yAxis = new Transform3D();        Interpolator tcbSplineInter = new J3DRotPosScaleTCBSplinePathInterpolator(J3DUtils.jAlpha, grp,                                                  yAxis, keyFrames, knotList);        tcbSplineInter.setSchedulingBounds(new BoundingSphere(new Point3d(), Double.MAX_VALUE));        behaviorBranch.addChild(tcbSplineInter);        interMap.put(grp, behaviorBranch);        grp.addChild(behaviorBranch);        interpolatorMap.put(grp, tcbSplineInter);        return interMap;    }    /**     * Method to remove certain interpolators from scene graph     * @param interMap     */    public void removeInterpolator(Map<TransformGroup,BranchGroup> interMap)    {        canvas.resetMoveFrames();        for (TransformGroup grp : interMap.keySet())        {            Node node = interMap.get(grp);            grp.removeChild(node);        }    }    ///////////////////// KEY BEHAVIOR FUNCTION ///////////////////////////////    private static Vector3d tmpVec = new Vector3d();    private static Vector3d mapSize = null;    protected double getScale( )	{		return 0.05;	}    Vector3d getMapSize( )    {        if (mapSize == null)            mapSize = new Vector3d(2, 0, 2);        return mapSize;    }    Point2d convertToMapCoordinate( Vector3d worldCoord )	{		Point2d point2d = new Point2d( );		Vector3d squareSize = getMapSize();		point2d.x = (worldCoord.x + getPanel().getWidth())/ squareSize.x;		point2d.y = (worldCoord.z + getPanel().getHeight())/ squareSize.z;		return point2d;	}    public boolean isCollision(Transform3D t3d)	{		// get the translation		t3d.get(tmpVec);		// we need to scale up by the scale that was		// applied to the root TG on the view side of the scenegraph			tmpVec.scale( 1.0 / getScale( ) );//        Vector3d mapSquareSize = getMapSize( );		// first check that we are still inside the "world"//		if (tmpVec.x < -getPanel().getWidth() + mapSquareSize.x ||//			tmpVec.x > getPanel().getWidth() - mapSquareSize.x ||//			tmpVec.y < -getPanel().getHeight() + mapSquareSize.y ||//			tmpVec.y > getPanel().getHeight() - mapSquareSize.y  )//			return true;        // then do a pixel based look up using the map        return isCollision(tmpVec);	}    /**     * Method to detect if give x, y location in the world collides with geometry     * @param worldCoord     * @return true if vector collides     */	protected boolean isCollision( Vector3d worldCoord )	{		Point2d point = convertToMapCoordinate( worldCoord );//        PickTool pickTool = new PickTool(scene);//				pickTool.setMode( PickTool.BOUNDS );////				BoundingSphere bounds = (BoundingSphere) objTrans.getBounds( );//				PickBounds pickBounds = new PickBounds( new BoundingSphere( new Point3d(keyBehavior.positionVector.x,//                        keyBehavior.positionVector.y, keyBehavior.positionVector.z), bounds.getRadius( ) ) );//				pickTool.setShape( pickBounds, new Point3d(0, 0, 0));//				PickResult[] resultArray = pickTool.pickAll( );////        System.out.println( "Wold Point " + worldCoord + " local " + keyBehavior.positionVector);////        if (resultArray != null)//        {//        for( int n = 0; n < resultArray.length; n++ )//		{//			Object userData = resultArray[n].getObject( ).getUserData( );////			if ( userData != null && userData instanceof String )//			{//					System.out.println( "Collision between: " + objTrans.getUserData( ) + " and: " + userData );//				// check that we are not colliding with ourselves...//				if ( ((String) userData).equals( (String) objTrans.getUserData( ) ) == false )//				{//					System.out.println( "Collision between: " + objTrans.getUserData( ) + " and: " + userData );//					return true;//				}//			}//		}//        }        pickCanvas.setShapeLocation((int)point.x, (int)point.y);        PickResult result = pickCanvas.pickClosest();        if (result != null && result.getNode(PickResult.SHAPE3D) != null)        {//             Shape3D shape = (Shape3D)result.getNode(PickResult.SHAPE3D);             //shape.setAppearance(J3DAppearance.highlightApp);            for (int i = 0; i < result.numIntersections(); i++)            {                PickIntersection inter = result.getIntersection(i);//            System.out.println("Collision " + inter.getDistance() + " " + inter.getPointCoordinates() + " normal " + inter.getPointNormal());//                 System.out.println("Point  " + point + " world " + worldCoord);//                GeometryArray geo = inter.getGeometryArray();                if (inter.getDistance() < 6)                     return (true); // collision            }        }        return (false);	}    public J3DUtils.ThreeDDemoKnot addFrame(boolean useView)    {        Transform3D tmpTrans = new Transform3D();        if (!useView) objTrans.getTransform(tmpTrans);        else u.getViewingPlatform().getViewPlatformTransform().getTransform(tmpTrans);        tmpTrans.get(tmpVec);        Quat4f rot = new Quat4f();        tmpTrans.get(rot);        Shape3D shape = null;//        for (Highlight h : highlighter.getHighlights())//		{//			shape = (Shape3D)h.getObject();//            break;//        }//        repaint();        return(new J3DUtils.ThreeDDemoKnot(1, new Vector3f(tmpVec), rot, shape));    }    public void saveMovie(String filename)    {        if (filename != null)            canvas.saveMovie(filename);    }    private static class J3DRotPosScaleTCBSplinePathInterpolator extends com.sun.j3d.utils.behaviors.interpolators.RotPosScaleTCBSplinePathInterpolator    {        List knotList;        int previousUpper = -1, previousLower = -1;        public J3DRotPosScaleTCBSplinePathInterpolator(Alpha alpha, TransformGroup target, Transform3D axisOfTransform, TCBKeyFrame[] keys, List list)        {            super(alpha, target, axisOfTransform, keys);            knotList = list;        }        public void processStimulus(java.util.Enumeration criteria)        {            super.processStimulus(criteria);////            if (upperKnot == previousUpper && lowerKnot == previousLower) return;//            previousUpper = upperKnot;//            previousLower = lowerKnot;//            J3DUtils.ThreeDDemoKnot knot = knotList.get(upperKnot-1);//            if (knot != null && knot.shape != null)//                target.addChild(knot.shape);////            knot.shape.getAppearance().getRenderingAttributes().setVisible(true);//            knot = knotList.get(lowerKnot-1);//            if (knot != null && knot.shape != null)////                target.removeChild(knot.shape);//            knot.shape.getAppearance().getRenderingAttributes().setVisible(false);////            System.out.println("Criteria " + upperKnot + " " + lowerKnot);        }    }};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -