Cov txheej txheem:

Siv Blender los Tsim Java3D Qauv: 3 Kauj Ruam
Siv Blender los Tsim Java3D Qauv: 3 Kauj Ruam
Anonim
Siv Blender los tsim Java3D Qauv
Siv Blender los tsim Java3D Qauv

Yog tias koj yog Java programmer koj yuav xav tau qhov program hauv 3D ntawm qee kis. Tab sis li cas? Zoo koj tuaj yeem siv Java3D thiab maj mam ntaus hauv txhua kis hauv 3D polygon (sim nws ntseeg kuv nws lub tswv yim tsis zoo), lossis koj tuaj yeem siv Blender (https://blender.org) pub dawb thiab qhib qhov 3D qauv qauv nrog ib tsab ntawv hu ua Blend2Java (https://sourceforge.net/projects/blend2java/). Txawm li cas los xij cov ntaub ntawv ntawm Blend2Java yuav luag tsis muaj yog li ntawd yog vim li cas kuv thiaj nyob ntawm no sau qhov no.

Kauj ruam 1: Rub tawm Cov Haujlwm

Koj yuav xav tau Blender (https://blender.org) thiab Blend2Java (https://sourceforge.net/projects/blend2java/). Ua li ntawd thaum koj muaj ob qho tib si pib ua los ntawm kev ua qauv yooj yim (lossis tsuas yog siv lub voos xwmfab txheem) hauv Blender.

Kauj ruam 2: Export Koj Tus Qauv rau XML

Export Koj Tus Qauv rau XML
Export Koj Tus Qauv rau XML

Thaum koj muaj tus qauv koj xav siv hauv Blender qhib Hloov Kho Hom thiab ntaus "a" qhov tseem ceeb los xaiv txhua lub ntsiab lus. Hauv qab vaj huam sib luag xaiv cov ntawv sau. Qhib ib daim ntawv tshiab hauv cov ntawv sau. Qhib cov ntaub ntawv blend2java.py uas koj rub tawm. Run. Ok koj lub hom phiaj yuav tsum tam sim no nyob hauv. XML qhov twg los xij koj khaws nws (yog tias koj muaj thiab cov lus yuam kev ua shure koj tsuas muaj 1 cov khoom siv rau lub hom phiaj). Hloov lub npe (nws yuav muaj lub npe txawv).

Kauj ruam 3: Ntshuam Lub Hom Phiaj rau Java

Ntshuam Lub Hom Phiaj rau Java
Ntshuam Lub Hom Phiaj rau Java

Shape3D fred = tsis muaj; sim {XMLDecoder e = tshiab XMLDecoder (tshiab BufferedInputStream (FileInputStream tshiab ("c: /HandShape3D.xml"))); // koj cov ntaub ntawv npe no fred = (Shape3D) e.readObject (); e.close (); } ntes (Tsuas yog e) {e.printStackTrace (); } ColoringAttributes ntawm = tshiab ColoringAttributes (); Tshwm sim ap = Tshwm sim tshiab (); Color3f col = tshiab Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = tshiab ColoringAttributes (col, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); obj.addChild (fred); ntxig qhov no rau hauv 3d code lossis siv tag nrho cov cai ntawm no ntshuam java.io.*; ntshuam java.beans. XMLDecoder; ntshuam java.applet. Applet; ntshuam java.awt.*; ntshuam java. awt.event.*; ntshuam com.sun.j3d.utils.applet. MainFrame; ntshuam com.sun.j3d.utils.universe.*; ntshuam javax.media.j3d.*; ntshuam javax.vecmath.*; ntshuam java.applet. Applet; ntshuam java.awt. BorderLayout; ntshuam java.awt. Frame; ntshuam com.sun.j3d.utils.applet. MainFrame; ntshuam com.sun.j3d.utils.geometry. ColorCube; ntshuam com.sun. j3d.utils.universe.*; ntshuam com.sun.j3d.utils.behaviors.mouse.*; ntshuam javax.media.j3d.*; ntshuam javax.vecmath.*; ntshuam java.awt.event.*; ntshuam java.util. Enumeration; pej xeem chav MouseBehaviorApp txuas Applet {pej xeem BranchGroup createSceneGraph () {BranchGroup objRoot = BranchGroup tshiab (); TransformGroup objTransform = tshiab TransformGroup (); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_WRITE); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_READ); objRoot.addChild (objTransform); Shape3D fred = tsis muaj; sim {XMLDecoder e = tshiab XMLDecoder (BufferedInputStream tshiab (FileInputStream tshiab ("c: /HandShape3D.xml"))); fred = (Shape3D) e.readObject (); e.close (); } ntes (Tsuas yog e) {e.printStackTrace (); } ColoringAttributes ntawm = tshiab ColoringAttributes (); Tshwm sim ap = Tshwm sim tshiab (); Color3f col = tshiab Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = tshiab ColoringAttributes (col, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); objTransform.addChild (fred); MouseRotate myMouseRotate = tshiab MouseRotate (); myMouseRotate.setTransformGroup (objTransform); myMouseRotate.setSchedulingBounds (BoundingSphere tshiab ()); objRoot.addChild (myMouseRotate); MouseTranslate myMouseTranslate = tshiab MouseTranslate (); myMouseTranslate.setTransformGroup (objTransform); myMouseTranslate.setSchedulingBounds (BoundingSphere tshiab ()); objRoot.addChild (myMouseTranslate); MouseZoom myMouseZoom = tshiab MouseZoom (); myMouseZoom.setTransformGroup (objTransform); myMouseZoom.setSchedulingBounds (BoundingSphere tshiab ()); objRoot.addChild (myMouseZoom); objRoot.compile (); rov objRoot; } pej xeem MouseBehaviorApp () {setLayout (tshiab BorderLayout ()); Canvas3D canvas3D = Canvas3D tshiab (SimpleUniverse.getPreferredConfiguration ()); ntxiv ("Center", canvas3D); BranchGroup scene = createSceneGraph (); SimpleUniverse simpleU = tshiab SimpleUniverse (canvas3D); simpleU.getViewingPlatform (). setNominalViewingTransform (); simpleU.addBranchGraph (scene); } pej xeem zoo li qub tsis muaj dab tsi tseem ceeb (Txoj hlua args) {Ncej ncej = tshiab MainFrame (tshiab MouseBehaviorApp (), 256, 256); }} siv qhov no rau kev ua tiav programtada! koj ua tiav! thiab tom qab ntawd koj hais tias "tam sim no yog dab tsi?" Kuv tsis muaj lub tswv yim! Kuv nyuam qhuav kawm Java ib hlis dhau los lol!

Pom zoo: