Mundarija:
2025 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2025-01-13 06:58
Agar siz Java dasturchisi bo'lsangiz, ehtimol siz bir vaqtning o'zida 3D formatida dasturlashni xohlagan bo'lsangiz kerak. Lekin qanday? Siz Java3D -dan foydalanishingiz va 3D ko'pburchakning har bir nuqtasini asta -sekin kirgizishingiz mumkin (bu menga yomon fikr deb ishondi) yoki Blender -dan (https://blender.org) bepul va ochiq kodli 3D modellashtirish dasturidan foydalanishingiz mumkin. Blend2Java deb nomlangan skript (https://sourceforge.net/projects/blend2java/). Biroq, Blend2Java -dagi hujjatlar deyarli yo'q, shuning uchun men bu erda o'tirib yozyapman.
1 -qadam: Dasturlarni yuklab oling
Sizga Blender (https://blender.org) va Blend2Java (https://sourceforge.net/projects/blend2java/) kerak bo'ladi. OK, keyin ikkalasini ham Blender -da oddiy modelni (yoki oddiy kubni ishlatib) ishga tushirgandan so'ng.
2 -qadam: Modelingizni XML -ga eksport qiling
Agar sizda model mavjud bo'lsa, siz Blender -da ishlatmoqchi bo'lgan tahrirlash rejimini oching va "a" tugmachasini bosib barcha nuqtalarni tanlang. Pastki panelda matn muharririni tanlang. Matn muharririda yangi faylni oching. Siz yuklagan blend2java.py faylini oching. Run. Ok sizning ob'ektingiz endi saqlangan joyda. XMLda bo'lishi kerak (agar sizda xato xabari bo'lsa, sizda ob'ekt uchun faqat 1 ta material bor). Ob'ekt nomini o'zgartiring (g'alati ismga ega bo'ladi).
3 -qadam: Ob'ektni Java -ga import qiling
Shape3D fred = null; harakat qilib ko'ring {XMLDecoder e = yangi XMLDecoder (yangi BufferedInputStream (yangi FileInputStream ("c: /HandShape3D.xml"))))); // bu erda sizning fayl nomingiz fred = (Shape3D) e.readObject (); e.yopish (); } catch (istisno e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Tashqi ko'rinish ap = yangi Tashqi ko'rinish (); Color3f col = yangi Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = new ColoringAttributes (col, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); obj.addChild (fred); uni har qanday 3d kodga kiriting yoki bu yerdan butun kodni ishlating java.io.*; import java.beans. XMLDecoder; import java.applet. Applet; import java.awt.*; import java. awt.event.*; import com.sun.j3d.utils.applet. MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*;.applet. Applet; import java.awt. BorderLayout; import java.awt. Frame; import com.sun.j3d.utils.applet. MainFrame; import com.sun.j3d.utils.geometry. ColorCube; import com.sun. j3d.utils.universe.*; com.sun.j3d.utils.behaviors.mouse.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.event.*; import java.util. Enumeration; umumiy sinf MouseBehaviorApp Applet {public BranchGroup createSceneGraph () {BranchGroup objRoot = new BranchGroup (); TransformGroup objTransform = yangi TransformGroup (); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_WRITE); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_READ); objRoot.addChild (objTransform); Shape3D fred = null; harakat qilib ko'ring {XMLDecoder e = yangi XMLDecoder (yangi BufferedInputStream (yangi FileInputStream ("c: /HandShape3D.xml"))))); fred = (Shape3D) e.readObject (); e.yopish (); } catch (istisno e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Tashqi ko'rinish ap = yangi Tashqi ko'rinish (); Color3f col = yangi Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = new ColoringAttributes (col, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); objTransform.addChild (fred); MouseRotate myMouseRotate = yangi MouseRotate (); myMouseRotate.setTransformGroup (objTransform); myMouseRotate.setSchedulingBounds (yangi BoundingSphere ()); objRoot.addChild (myMouseRotate); MouseTranslate myMouseTranslate = yangi MouseTranslate (); myMouseTranslate.setTransformGroup (objTransform); myMouseTranslate.setSchedulingBounds (yangi BoundingSphere ()); objRoot.addChild (myMouseTranslate); MouseZoom myMouseZoom = yangi MouseZoom (); myMouseZoom.setTransformGroup (objTransform); myMouseZoom.setSchedulingBounds (yangi BoundingSphere ()); objRoot.addChild (myMouseZoom); objRoot.compile (); objRoot -ni qaytarish; } umumiy MouseBehaviorApp () {setLayout (yangi BorderLayout ()); Canvas3D canvas3D = yangi Canvas3D (SimpleUniverse.getPreferredConfiguration ()); qo'shish ("Center", canvas3D); BranchGroup sahnasi = createSceneGraph (); SimpleUniverse simpleU = yangi SimpleUniverse (canvas3D); oddiyU.getViewingPlatform (). setNominalViewingTransform (); simpleU.addBranchGraph (sahna); } public static void main (String args) {Frame frame = new MainFrame (new MouseBehaviorApp (), 256, 256); }} undan to'liq dastur uchun foydalaning! Siz nima qildingiz? Men Java -ni bir oy oldin o'rganganman lol!