Uporaba mešalnika za ustvarjanje modelov Java3D: 3 koraki
Uporaba mešalnika za ustvarjanje modelov Java3D: 3 koraki
Anonim

Če ste programer Java, ste verjetno kdaj želeli programirati v 3D. Ampak kako? No, lahko uporabite Java3D in počasi vnesete vsako točko v 3D poligonu (poskusite, verjemite, to je slaba ideja) ali pa uporabite Blender (https://blender.org) brezplačen in odprtokodni program za 3D modeliranje skupaj z skript z imenom Blend2Java (https://sourceforge.net/projects/blend2java/). Vendar dokumentacija o Blend2Javi skoraj ne obstaja, zato sedim tukaj in pišem to.

1. korak: Prenesite programe

Potrebovali boste Blender (https://blender.org) in Blend2Java (https://sourceforge.net/projects/blend2java/). V redu, potem ko oba začnete z izdelavo preprostega modela (ali samo s standardno kocko) v Blenderju.

2. korak: izvozite svoj model v XML

Ko imate model, ki ga želite uporabiti v mešalniku, odprite način za urejanje in pritisnite tipko "a", da izberete vse točke. Na spodnji plošči izberite urejevalnik besedil. Odprite novo datoteko v urejevalniku besedil. Odprite datoteko blend2java.py, ki ste jo prenesli. Run. Ok, vaš objekt bi moral biti zdaj v. XML, kjer koli ste ga shranili (če imate in sporočilo o napaki, se prepričajte, da imate samo 1 material za predmet). Preimenujte predmet (ime bo čudno).

3. korak: Uvozite objekt v Javo

Shape3D fred = nič; poskusite {XMLDecoder e = nov XMLDecoder (nov BufferedInputStream (nov FileInputStream ("c: /HandShape3D.xml"))); // ime vaše datoteke tukaj fred = (Shape3D) e.readObject (); e. Zapri (); } catch (izjema e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Videz ap = nov videz (); Color3f col = nov Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = new ColoringAttributes (stolpec, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); obj.addChild (fred); vstavite to v katero koli 3d kodo ali uporabite celotno kodo tukaj uvoz java.io.*; uvoz java.beans. XMLDecoder; uvoz java.applet. Applet; uvoz java.awt.*; uvoz java. awt.event.*; uvoz com.sun.j3d.utils.applet. MainFrame; uvoz com.sun.j3d.utils.universe.*; uvoz javax.media.j3d.*; uvoz javax.vecmath.*; uvoz java.applet. Applet; uvoz java.awt. BorderLayout; uvoz java.awt. Frame; uvoz com.sun.j3d.utils.applet. MainFrame; uvoz com.sun.j3d.utils.geometry. ColorCube; uvoz com.sun. j3d.utils.universe.*; uvoz com.sun.j3d.utils.behaviors.mouse.*; uvoz javax.media.j3d.*; uvoz javax.vecmath.*; uvoz java.awt.event.*; uvoz java.util. Enumeration; javni razred MouseBehaviorApp razširja Applet {public BranchGroup createSceneGraph () {BranchGroup objRoot = new BranchGroup (); TransformGroup objTransform = nov TransformGroup (); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_WRITE); objTransform.setCapability (TransformGroup. ALLOW_TRANSFORM_READ); objRoot.addChild (objTransform); Shape3D fred = nič; poskusite {XMLDecoder e = nov XMLDecoder (nov BufferedInputStream (nov FileInputStream ("c: /HandShape3D.xml"))); fred = (Shape3D) e.readObject (); e. Zapri (); } catch (izjema e) {e.printStackTrace (); } ColoringAttributes at = new ColoringAttributes (); Videz ap = nov videz (); Color3f col = nov Color3f (1.0f, 0.0f, 1.0f); ColoringAttributes ca = new ColoringAttributes (stolpec, ColoringAttributes. NICEST); ap.setColoringAttributes (ca); fred.setAppearance (ap); objTransform.addChild (fred); MouseRotate myMouseRotate = nov MouseRotate (); myMouseRotate.setTransformGroup (objTransform); myMouseRotate.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseRotate); MouseTranslate myMouseTranslate = nov MouseTranslate (); myMouseTranslate.setTransformGroup (objTransform); myMouseTranslate.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseTranslate); MouseZoom myMouseZoom = nov MouseZoom (); myMouseZoom.setTransformGroup (objTransform); myMouseZoom.setSchedulingBounds (nova BoundingSphere ()); objRoot.addChild (myMouseZoom); objRoot.compile (); return objRoot; } javni MouseBehaviorApp () {setLayout (nov BorderLayout ()); Canvas3D canvas3D = novo Canvas3D (SimpleUniverse.getPreferredConfiguration ()); add ("Center", canvas3D); BranchGroup scene = createSceneGraph (); SimpleUniverse simpleU = nov SimpleUniverse (platno3D); simpleU.getViewingPlatform (). setNominalViewingTransform (); simpleU.addBranchGraph (prizor); } javna statična void main (String args) {Frame frame = new MainFrame (new MouseBehaviorApp (), 256, 256); }} uporabite to za popolno programsko zbirko! ste končali! in potem rečete "zdaj kaj"? Nimam pojma! Pred enim mesecem sem se naučil Javo lol!