Sadržaj:
2025 Autor: John Day | [email protected]. Zadnja promjena: 2025-01-13 06:57
Ako ste programer na Javi, vjerojatno ste u nekom trenutku htjeli programirati u 3D -u. Ali kako? Pa, mogli biste koristiti Java3D i polako upisivati svaku točku u 3D poligon (pokušajte, vjerujte mi, to je loša ideja), ili možete koristiti Blender (https://blender.org) besplatni program za 3D modeliranje otvorenog koda zajedno s skripta pod nazivom Blend2Java (https://sourceforge.net/projects/blend2java/). Međutim, dokumentacija o Blend2Javi gotovo da ne postoji pa zato sjedim ovdje i pišem ovo.
Korak 1: Preuzmite programe
Trebat će vam Blender (https://blender.org) i Blend2Java (https://sourceforge.net/projects/blend2java/). U redu, onda kad ih oboje započnete izradom jednostavnog modela (ili samo pomoću standardne kocke) u Blenderu.
Korak 2: Izvezite svoj model u XML
Nakon što imate model koji želite koristiti u Blenderu, otvorite Edit Mode i pritisnite tipku "a" za odabir svih točaka. Na donjoj ploči odaberite uređivač teksta. Otvorite novu datoteku u uređivaču teksta. Otvorite datoteku blend2java.py koju ste preuzeli. Pokreni. Dobro, vaš objekt sada bi trebao biti u. XML -u gdje god ste ga spremili (ako imate i poruku o pogrešci, provjerite imate li samo 1 materijal za objekt). Preimenujte objekt (imat će čudan naziv).
Korak 3: Uvezite objekt u Javu
Shape3D fred = null; isprobajte {XMLDecoder e = novi XMLDecoder (novi BufferedInputStream (novi FileInputStream ("c: /HandShape3D.xml"))); // ime vaše datoteke ovdje fred = (Shape3D) e.readObject (); e.close (); } catch (Izuzetak e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Izgled ap = novi Izgled (); Color3f col = nova Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = new ColoringAttributes (col, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); obj.addChild (fred); umetnite ovo u bilo koji 3d kôd ili upotrijebite cijeli kôd ovdje uvoz java.io.*; uvoz java.beans. XMLDecoder; uvoz java.applet. Applet; uvoz java.awt.*; uvoz java. awt.event.*; import com.sun.j3d.utils.applet. MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; import java.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.*; import com.sun.j3d.utils.behaviors.mouse.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.event.*; import java.util. Enumeration; javna klasa MouseBehaviorApp proširuje Applet {public BranchGroup createSceneGraph () {BranchGroup objRoot = new BranchGroup (); TransformGroup objTransform = nova TransformGroup (); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_WRITE); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_READ); objRoot.addChild (objTransform); Shape3D fred = null; isprobajte {XMLDecoder e = novi XMLDecoder (novi BufferedInputStream (novi FileInputStream ("c: /HandShape3D.xml"))); fred = (Shape3D) e.readObject (); e.close (); } catch (iznimka e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Izgled ap = novi Izgled (); Color3f col = nova 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 = novi MouseRotate (); myMouseRotate.setTransformGroup (objTransform); myMouseRotate.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseRotate); MouseTranslate myMouseTranslate = novi MouseTranslate (); myMouseTranslate.setTransformGroup (objTransform); myMouseTranslate.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseTranslate); MouseZoom myMouseZoom = novi MouseZoom (); myMouseZoom.setTransformGroup (objTransform); myMouseZoom.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseZoom); objRoot.compile (); return objRoot; } javni MouseBehaviorApp () {setLayout (novi BorderLayout ()); Canvas3D canvas3D = novi Canvas3D (SimpleUniverse.getPreferredConfiguration ()); add ("Centar", platno3D); BranchGroup scena = createSceneGraph (); SimpleUniverse simpleU = novi SimpleUniverse (canvas3D); simpleU.getViewingPlatform (). setNominalViewingTransform (); simpleU.addBranchGraph (scena); } public static void main (String args) {Frame frame = new MainFrame (new MouseBehaviorApp (), 256, 256); }} iskoristite ovo za potpunu programsku tatu! gotovi ste! i onda kažete "što sad"? Nemam pojma! Upravo sam naučio Javu prije mjesec dana lol!