Source Code Cross Referenced for WindowFixer.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » internalloaders » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » org.jdesktop.j3dfly.utils.internalloaders 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/internalloaders/WindowFixer.java,v 1.1 2005/04/20 21:05:04 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.internalloaders;
019:
020:        import java.io.*;
021:        import javax.media.j3d.*;
022:        import java.awt.image.RenderedImage;
023:        import javax.vecmath.Color3f;
024:        import com.sun.j3d.utils.image.TextureLoader;
025:        import com.sun.j3d.utils.scenegraph.io.SceneGraphFileReader;
026:        import com.sun.j3d.utils.scenegraph.io.SceneGraphFileWriter;
027:
028:        /**
029:         *
030:         * Class to fix the windows in the Van demo for JavaOne
031:         *
032:         * @author  paulby
033:         * @version 
034:         */
035:        public class WindowFixer extends java.lang.Object {
036:
037:            /** Creates new WindowFixer */
038:            public WindowFixer() {
039:                try {
040:                    File file = new File("glass.j3f");
041:                    SceneGraphFileReader reader = new SceneGraphFileReader(file);
042:
043:                    BranchGroup bg = reader.readBranchGraph(0)[0];
044:
045:                    Shape3D shape = (Shape3D) bg.getChild(0);
046:
047:                    org.jdesktop.j3d.utils.scenegraph.traverser.GeometryArrayStripifier
048:                            .stripify(bg);
049:                    bg.removeAllChildren();
050:                    System.out
051:                            .println("geom " + shape.numGeometries() + " "
052:                                    + shape.getGeometry(0) + " "
053:                                    + shape.getGeometry(2));
054:                    javax.media.j3d.TriangleStripArray stripArray = (javax.media.j3d.TriangleStripArray) shape
055:                            .getGeometry(2);
056:
057:                    Appearance app = new Appearance();
058:                    PolygonAttributes polyAttr = new PolygonAttributes();
059:                    polyAttr.setCullFace(PolygonAttributes.CULL_NONE);
060:                    app.setPolygonAttributes(polyAttr);
061:
062:                    TransparencyAttributes transAttr = new TransparencyAttributes();
063:                    transAttr
064:                            .setTransparencyMode(TransparencyAttributes.BLENDED);
065:                    transAttr.setTransparency(0.3f);
066:                    app.setTransparencyAttributes(transAttr);
067:
068:                    addWalls(bg);
069:
070:                    shape.removeAllGeometries();
071:                    System.out.println("Strip count "
072:                            + stripArray.getNumStrips());
073:                    int[] vertexCounts = new int[stripArray.getNumStrips()];
074:                    stripArray.getStripVertexCounts(vertexCounts);
075:                    int pos = 0;
076:                    Color3f windowClr = new Color3f(51f / 255f, 145f / 255f,
077:                            8f / 255f);
078:                    for (int i = 0; i < vertexCounts.length; i++) {
079:                        float[] coords = new float[vertexCounts[i] * 3];
080:                        float[] normals = new float[coords.length];
081:                        //System.out.println("Getting "+pos+"  "+coords.length+"  "+stripArray.getVertexCount() );
082:                        stripArray.getCoordinates(pos, coords);
083:                        stripArray.getNormals(pos, normals);
084:                        pos += vertexCounts[i];
085:                        TriangleStripArray newStrip = new TriangleStripArray(
086:                                vertexCounts[i], TriangleArray.COORDINATES
087:                                        | TriangleArray.NORMALS
088:                                        | TriangleArray.COLOR_3,
089:                                new int[] { vertexCounts[i] });
090:                        newStrip.setCoordinates(0, coords);
091:                        newStrip.setNormals(0, normals);
092:                        for (int j = 0; j < normals.length / 3; j++)
093:                            newStrip.setColor(j, windowClr);
094:                        Shape3D s = new Shape3D(newStrip, app);
095:                        bg.addChild(s);
096:                    }
097:
098:                    //reader = new SceneGraphFileReader( new File( "geometry"+File.separatorChar+"Dodge_Caravan_Interior_95.j3f"));
099:                    //Transform3D t3d = new Transform3D();
100:                    //t3d.rotY( Math.toRadians(-90 ));
101:                    //TransformGroup interior = new TransformGroup( t3d );
102:                    //interior.addChild( reader.readBranchGraph(0)[0] );
103:
104:                    //bg.addChild( interior );
105:
106:                    Background background = new Background(new Color3f(
107:                            11f / 255f, 93f / 255f, 165f / 255f));
108:                    background.setApplicationBounds(new BoundingSphere(
109:                            new javax.vecmath.Point3d(),
110:                            Double.POSITIVE_INFINITY));
111:                    bg.addChild(background);
112:
113:                    File outFile = new File("newglass2.j3f");
114:                    SceneGraphFileWriter writer = new SceneGraphFileWriter(
115:                            outFile, null, false, null, null);
116:                    writer.writeBranchGraph(bg);
117:                    writer.close();
118:                } catch (Exception e) {
119:                    e.printStackTrace();
120:                }
121:
122:                System.exit(0);
123:            }
124:
125:            private void addWalls(BranchGroup bg) {
126:                TriangleStripArray wallGeom = new TriangleStripArray(4,
127:                        TriangleStripArray.COORDINATES
128:                                | TriangleStripArray.TEXTURE_COORDINATE_2
129:                                | TriangleStripArray.COLOR_3, new int[] { 4 });
130:                float w = 1.3f;
131:                float base = -0.4f;
132:                float top = 0.15f;
133:                float offset = 1.3f;
134:                wallGeom.setCoordinates(0, new float[] { -w, base, offset, w,
135:                        base, offset, -w, top, offset, w, top, offset });
136:                wallGeom.setTextureCoordinates(0, 0, new float[] { 0f, 0f, 1f,
137:                        0f, 0f, 1f, 1f, 1f });
138:
139:                TriangleStripArray backWallGeom = new TriangleStripArray(4,
140:                        TriangleStripArray.COORDINATES
141:                                | TriangleStripArray.TEXTURE_COORDINATE_2
142:                                | TriangleStripArray.COLOR_3, new int[] { 4 });
143:                backWallGeom.setCoordinates(0, new float[] { -w, base, -offset,
144:                        w, base, -offset, -w, top, -offset, w, top, -offset });
145:                backWallGeom.setTextureCoordinates(0, 0, new float[] { 0f, 0f,
146:                        1f, 0f, 0f, 1f, 1f, 1f });
147:
148:                TriangleStripArray leftWallGeom = new TriangleStripArray(4,
149:                        TriangleStripArray.COORDINATES
150:                                | TriangleStripArray.TEXTURE_COORDINATE_2
151:                                | TriangleStripArray.COLOR_3, new int[] { 4 });
152:                leftWallGeom.setCoordinates(0, new float[] { -w, base, -offset,
153:                        -w, base, offset, -w, top, -offset, -w, top, offset });
154:
155:                leftWallGeom.setTextureCoordinates(0, 0, new float[] { 0f, 0f,
156:                        1f, 0f, 0f, 1f, 1f, 1f });
157:
158:                TriangleStripArray rightWallGeom = new TriangleStripArray(4,
159:                        TriangleStripArray.COORDINATES
160:                                | TriangleStripArray.TEXTURE_COORDINATE_2
161:                                | TriangleStripArray.COLOR_3, new int[] { 4 });
162:                rightWallGeom.setCoordinates(0, new float[] { w, base, -offset,
163:                        w, base, offset, w, top, -offset, w, top, offset });
164:
165:                rightWallGeom.setTextureCoordinates(0, 0, new float[] { 0f, 0f,
166:                        1f, 0f, 0f, 1f, 1f, 1f });
167:
168:                Color3f clr = new Color3f(1f, 1f, 1f);
169:                for (int i = 0; i < 4; i++) {
170:                    wallGeom.setColor(i, clr);
171:                    backWallGeom.setColor(i, clr);
172:                    leftWallGeom.setColor(i, clr);
173:                    rightWallGeom.setColor(i, clr);
174:                }
175:
176:                PolygonAttributes polyAttr = new PolygonAttributes();
177:                polyAttr.setCullFace(PolygonAttributes.CULL_NONE);
178:                Appearance wallApp = new Appearance();
179:                wallApp.setPolygonAttributes(polyAttr);
180:                TransparencyAttributes wallTrans = new TransparencyAttributes();
181:                wallTrans.setTransparency(0.5f);
182:                wallTrans.setTransparencyMode(TransparencyAttributes.BLENDED);
183:                wallApp.setTransparencyAttributes(wallTrans);
184:
185:                Shape3D frontWall = new Shape3D(wallGeom, wallApp);
186:                bg.addChild(frontWall);
187:
188:                Shape3D backWall = new Shape3D(backWallGeom, wallApp);
189:                bg.addChild(backWall);
190:
191:                Shape3D leftWall = new Shape3D(leftWallGeom, wallApp);
192:                bg.addChild(leftWall);
193:
194:                Shape3D rightWall = new Shape3D(rightWallGeom, wallApp);
195:                bg.addChild(rightWall);
196:
197:                TextureLoader tl = new TextureLoader("geometry"
198:                        + File.separatorChar + "asphlt.gif", "RGBA", null);
199:                //System.out.println("Loaded Image ");
200:
201:                Appearance floorApp = new Appearance();
202:                TextureAttributes textureAttr = new TextureAttributes();
203:                textureAttr.setTextureMode(TextureAttributes.MODULATE);
204:                ImageComponent2D image = tl.getImage();
205:                Texture2D floorTexture = new Texture2D(Texture2D.BASE_LEVEL,
206:                        Texture2D.RGBA, image.getWidth(), image.getHeight());
207:                floorTexture.setImage(0, image);
208:                floorApp.setTexture(floorTexture);
209:                System.out.println("Got texture");
210:
211:                float size = 4f;
212:                float height = -0.35f;
213:
214:                TriangleStripArray floorGeom = new TriangleStripArray(4,
215:                        TriangleArray.COORDINATES | TriangleArray.NORMALS
216:                                | TriangleArray.TEXTURE_COORDINATE_2,
217:                        new int[] { 4 });
218:                floorGeom.setCoordinates(0, new float[] { -size, height, -size,
219:                        -size, height, size, size, height, -size, size, height,
220:                        size });
221:                floorGeom.setNormals(0, new float[] { 0f, 1f, 0f, 0f, 1f, 0f,
222:                        0f, 1f, 0f });
223:                floorGeom.setTextureCoordinates(0, new float[] { 0f, 0f, 0f,
224:                        5f, 5f, 0f, 5f, 5f });
225:                Shape3D floor = new Shape3D(floorGeom, floorApp);
226:                bg.addChild(floor);
227:            }
228:
229:            public static void main(String[] args) {
230:                new WindowFixer();
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.