Przykładowy program Java 3D

Przykładowy program Java 3D
TS
  • Rejestracja:prawie 15 lat
  • Ostatnio:ponad 14 lat
0

Oto przykładowy program w Javie 3D, który jest dostępny wraz z tutorialem:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;

// HelloJava3Da renders a single, rotating cube.

public class HelloJava3Da extends Applet {
public HelloJava3Da() {
setLayout(new BorderLayout());
Canvas3D canvas3D = new Canvas3D(null);
add("Center", canvas3D);

BranchGroup scene = createSceneGraph();

// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();

simpleU.addBranchGraph(scene);

} // end of HelloJava3Da (constructor)

public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

objRoot.addChild(new ColorCube(0.4));

return objRoot;

} // end of CreateSceneGraph method of HelloJava3Da

// The following allows this to be run as an application
// as well as an applet

public static void main(String[] args) {
Frame frame = new MainFrame(new HelloJava3Da(), 256, 256);
} // end of main (method of HelloJava3Da)

} // end of class HelloJava3Da

Kompiluje sie normalnie ale po uruchomieniu nic sie nie wyswietla i wyskakuje ClassNotFoundException. Wie ktos moze co jest tu nie tak? Z gory dzieki za pomoc ;)

0

było najpierw przeczytać tutorial...

TS
  • Rejestracja:prawie 15 lat
  • Ostatnio:ponad 14 lat
0

Mam zamiar skonczyc czytac tutorial ale najpierw chcialem zobaczyc czy te programy w ogole mi beda dzialac, czy sciagnalem wszystkie potrzebne rzeczy itp

VT
  • Rejestracja:ponad 16 lat
  • Ostatnio:6 miesięcy
  • Postów:167
0

do javy3d musisz zainstalować dodatkowe biblioteki binarne i dodać do projektu jary z j3d.
tu masz wszystkie instalki:
https://java3d.dev.java.net/binary-builds.html

TS
  • Rejestracja:prawie 15 lat
  • Ostatnio:ponad 14 lat
0

Tzn wydaje mi sie, ze juz mam sciagniete wszystko, bo program sie kompiluje tylko po uruchomieniu wyskakuje ClassNotFoundException

lipkerson
  • Rejestracja:ponad 17 lat
  • Ostatnio:ponad 2 lata
0

A Apache Ant Ty posiadasz na swoim blaszaku?


Another jam from the world for the jam from the voices of the world......
TS
  • Rejestracja:prawie 15 lat
  • Ostatnio:ponad 14 lat
0

Yyy... Szczerze mowiac nie wiem co to jest wiec przypuszczam, ze nie posiadam ;)
A co to jest?

lipkerson
  • Rejestracja:ponad 17 lat
  • Ostatnio:ponad 2 lata
0

Hmm to takie małe coś co wspomaga budowanie aplikacji. Taki "make" w Java.

Spróbuj poniższy przykład

Kopiuj
import java.applet.Applet;


import javax.media.j3d.*;
import javax.vecmath.*;


import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.TextureLoader;


/*
 * This example builds a simple Java 3D application using the
 * Sun utility classes: MainFrame and SimpleUniverse.
 * The example displays a moving sphere, in front of a
 * background image. It uses a texture image and one light
 * to increase the visual impact of the scene.
 */
public class A extends Applet
{
 /*
  * Create a simple Java 3D environment containing:
  * a sphere (geometry), a light,background geometry
  * with an applied texture, and a behavior that will
  * move the sphere along the X-axis.
  */
 public A()
 {
  // create the SimpleUniverse class that will
  // encapsulate the scene that we are building.
  // SimpleUniverse is a helper class (utility)
  // from SUN that is included with the core Java 3D
  // distribution.
  SimpleUniverse u = new SimpleUniverse();


  // create a BranchGroup. A BranchGroup is a node in
  // a Tree data structure that can have child nodes
  BranchGroup bgRoot = new BranchGroup();


  // create the Background node and add it to the SimpleUniverse
  u.addBranchGraph( createBackground() );


  // create the behaviors to move the geometry along the X-axis.
  // The behavior is added as a child of the bgRoot node.
  // Anything added as a child of the tg node will be effected by the
  // behavior (will be moved along the X-axis).
  TransformGroup tg = createBehaviors( bgRoot );


  // add the Sphere geometry as a child of the tg
  // so that it will be moved along the X-axis.
  tg.addChild( createSceneGraph() );


  // because the sphere was added at the 0,0,0 coordinate
  // and by default the viewer is also located at 0,0,0
  // we have to move the viewer back a little so that
  // she can see the scene.
  u.getViewingPlatform().setNominalViewingTransform();


  // add a light to the root BranchGroup to illuminate the scene
  addLights( bgRoot );


  // finally wire everything together by adding the root
  // BranchGroup to the SimpleUniverse
  u.addBranchGraph( bgRoot );
 }


 /*
  * Create the geometry for the scene. In this case
  * we simply create a Sphere
  * (a built-in Java 3D primitive).
  */
 public BranchGroup createSceneGraph()
 {
  // create a parent BranchGroup node for the Sphere
  BranchGroup bg = new BranchGroup();


  // create an Appearance for the Sphere.
  // The Appearance object controls various rendering
  // options for the Sphere geometry.
  Appearance app = new Appearance();


  // assign a Material to the Appearance. For the Sphere
  // to respond to the light in the scene it must have a Material.
  // Assign some colors to the Material and a shininess setting
  // that controls how reflective the surface is to lighting.
  Color3f objColor = new Color3f(0.8f, 0.2f, 1.0f);
  Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
  app.setMaterial(new Material(objColor, black, objColor, black,
    80.0f));


  // create a Sphere with a radius of 0.1
  // and associate the Appearance that we described.
  // the option GENERATE_NORMALS is required to ensure that the
  // Sphere responds correctly to lighting.
  Sphere sphere = new Sphere( 0.1f, Primitive.GENERATE_NORMALS,
    app );


  // add the sphere to the BranchGroup to wire
  // it into the scene.
  bg.addChild( sphere );
  return bg;
 }


 /*
  * Add a directional light to the BranchGroup.
  */
 public void addLights( BranchGroup bg )
 {
  // create the color for the light
  Color3f color = new Color3f( 1.0f,1.0f,0.0f );


  // create a vector that describes the direction that
  // the light is shining.
  Vector3f direction  = new Vector3f( -1.0f,-1.0f,-1.0f );


  // create the directional light with the color and direction
  DirectionalLight light = new DirectionalLight( color, direction );


  // set the volume of influence of the light.
  // Only objects within the Influencing Bounds
  // will be illuminated.
  light.setInfluencingBounds( getBoundingSphere() );


  // add the light to the BranchGroup
  bg.addChild( light );
 }


 /*
  * Create some Background geometry to use as
  * a backdrop for the application. Here we create
  * a Sphere that will enclose the entire scene and
  * apply a texture image onto the inside of the Sphere
  * to serve as a graphical backdrop for the scene.
  */
 public BranchGroup createBackground()
 {
  // create a parent BranchGroup for the Background
  BranchGroup backgroundGroup = new BranchGroup();


  // create a new Background node
  Background back = new Background();


  // set the range of influence of the background
  back.setApplicationBounds( getBoundingSphere() );


  // create a BranchGroup that will hold
  // our Sphere geometry
  BranchGroup bgGeometry = new BranchGroup();


  // create an appearance for the Sphere
  Appearance app = new Appearance();


  // load a texture image using the Java 3D texture loader
  Texture tex = new TextureLoader( "c:/1/lipkal.jpg", this).getTexture();


  // apply the texture to the Appearance
  app.setTexture( tex );


  // create the Sphere geometry with radius 1.0.
  // we tell the Sphere to generate texture coordinates
  // to enable the texture image to be rendered
  // and because we are *inside* the Sphere we have to generate
  // Normal coordinates inwards or the Sphere will not be visible.
  Sphere sphere = new Sphere( 1.0f,
              Primitive.GENERATE_TEXTURE_COORDS |

              Primitive.GENERATE_NORMALS_INWARD, app );


  // start wiring everything together,

  // add the Sphere to its parent BranchGroup.

  bgGeometry.addChild( sphere );



  // assign the BranchGroup to the Background as geometry.

  back.setGeometry( bgGeometry );



  // add the Background node to its parent BranchGroup.

  backgroundGroup.addChild( back );



  return backgroundGroup;

 }



 /*

  * Create a behavior to move child nodes along the X-axis.

  * The behavior is added to the BranchGroup bg, whereas

  * any nodes added to the returned TransformGroup will be

  * effected by the behavior.

  */

 public TransformGroup createBehaviors( BranchGroup bg )

 {

  // create a TransformGroup.

  //

  // A TransformGroup is a Group node (can have children)

  // and contains a Transform3D member.

  //

  // The Transform3D member contains a 4x4 transformation matrix

  // that is applied during rendering to all the TransformGroup's

  // child nodes. The 4x4 matrix can describe:

  // scaling, translation and rotation in one neat package!



  // enable the TRANSFORM_WRITE capability so that

  // our behavior code can modify it at runtime.

  TransformGroup objTrans = new TransformGroup();

  objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);



  // create a new Transform3D that will describe

  // the direction we want to move.

  Transform3D xAxis = new Transform3D();



  // create an Alpha object.

  // The Alpha object describes a function against time.

  // The Alpha will output a value that ranges between 0 and 1

  // using the time parameters (in milliseconds).

  Alpha xAlpha = new Alpha( -1,

             Alpha.DECREASING_ENABLE |

             Alpha.INCREASING_ENABLE,

                   1000,

                   1000,

                   5000,

                   1000,

                   1000,

                   10000,

                   2000,

                   4000 );



  // create a PositionInterpolator.

  // The PositionInterpolator will modify the translation components

  // of a TransformGroup's Transform3D (objTrans) based on the output

  // from the Alpha. In this case the movement will range from

  // -0.8 along the X-axis with Alpha=0 to X=0.8 when Alpha=1.

  PositionInterpolator posInt = new PositionInterpolator(  xAlpha,

                 objTrans,

                 xAxis, -0.8f, 0.8f );



  // set the range of influence of the PositionInterpolator

  posInt.setSchedulingBounds( getBoundingSphere() );



  // wire the PositionInterpolator into its parent

  // TransformGroup. Just like rendering nodes behaviors

  // must be added to the scenegraph.

  objTrans.addChild( posInt );



  // add the TransformGroup to its parent BranchGroup

  bg.addChild( objTrans );



  // we return the TransformGroup with the

  // behavior attached so that we can add nodes to it

  // (which will be effected by the PositionInterpolator).

  return objTrans;

 }



 /*

  * Return a BoundingSphere that describes the

  * volume of the scene.

  */

 BoundingSphere getBoundingSphere()

 {

  return new BoundingSphere( new Point3d(0.0,0.0,0.0), 200.0 );

 }



 /*

  * main entry point for the Application.

  */

 public static void main(String[] args)

 {

  A simpleTest = new A();

 }

}

Chodzi? Tylko zmień sobie teksturę na jakąś Twoją grafikę.


Another jam from the world for the jam from the voices of the world......
lipkerson
  • Rejestracja:ponad 17 lat
  • Ostatnio:ponad 2 lata
0

Zaciekawił mnie temat - kiedyś chciałem tym się pobawić ale czasu brak.
Ok ten Twój przykład z tutoriala tez rudzy tylko z tego Canvas3D wywal nulla bo widać nie ma jakiś domyślnych graficznych:

GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();.
i
Canvas3D canvas3D = new Canvas3D(config);
a w importach dodaj
import java.awt.GraphicsConfiguration;

W sumie fajne to...tylko teraz ja mam pytanie-czy ta technologia jest rozwijana?

Fajny link znalazłem:

http://www.tecgraf.puc-rio.br/~ismael/Cursos/Cidade_CG/labs/Java3D/Java3D_onlinebook_selman/onlinebook.html

Dużo przykładów. Zgłebie to...mam nadzieje że jak ktoś kto już ma jakieś doświadczenie w tym tez mi pomoze jak się jakieś pytania po drodze pojawia. pzdr

PS: A ten ant to do budowania przykładów by mieć jednego jara(przykładów ze strony J3D).


Another jam from the world for the jam from the voices of the world......
VT
  • Rejestracja:ponad 16 lat
  • Ostatnio:6 miesięcy
  • Postów:167
0

podobno słabo jest rozwijane.
Ja mam w swojej pracy dyplomowej stworzyć aplikację w 3d i po chwilowej analizie rynku stwierdziłem, że użyje JOGL zamiast tegotj. biblioteki pozwalającej korzystać z OpenGLa z poziomu javy. Przede wszystkim dlatego, że OpenGL jest znacznie szerzej rozpowszechniony a użycie tego w javie niewiele różni się od użycia w c, tak więc dużo łatwiej o dokumentację itp.

Kliknij, aby dodać treść...

Pomoc 1.18.8

Typografia

Edytor obsługuje składnie Markdown, w której pojedynczy akcent *kursywa* oraz _kursywa_ to pochylenie. Z kolei podwójny akcent **pogrubienie** oraz __pogrubienie__ to pogrubienie. Dodanie znaczników ~~strike~~ to przekreślenie.

Możesz dodać formatowanie komendami , , oraz .

Ponieważ dekoracja podkreślenia jest przeznaczona na linki, markdown nie zawiera specjalnej składni dla podkreślenia. Dlatego by dodać podkreślenie, użyj <u>underline</u>.

Komendy formatujące reagują na skróty klawiszowe: Ctrl+B, Ctrl+I, Ctrl+U oraz Ctrl+S.

Linki

By dodać link w edytorze użyj komendy lub użyj składni [title](link). URL umieszczony w linku lub nawet URL umieszczony bezpośrednio w tekście będzie aktywny i klikalny.

Jeżeli chcesz, możesz samodzielnie dodać link: <a href="link">title</a>.

Wewnętrzne odnośniki

Możesz umieścić odnośnik do wewnętrznej podstrony, używając następującej składni: [[Delphi/Kompendium]] lub [[Delphi/Kompendium|kliknij, aby przejść do kompendium]]. Odnośniki mogą prowadzić do Forum 4programmers.net lub np. do Kompendium.

Wspomnienia użytkowników

By wspomnieć użytkownika forum, wpisz w formularzu znak @. Zobaczysz okienko samouzupełniające nazwy użytkowników. Samouzupełnienie dobierze odpowiedni format wspomnienia, zależnie od tego czy w nazwie użytkownika znajduje się spacja.

Znaczniki HTML

Dozwolone jest używanie niektórych znaczników HTML: <a>, <b>, <i>, <kbd>, <del>, <strong>, <dfn>, <pre>, <blockquote>, <hr/>, <sub>, <sup> oraz <img/>.

Skróty klawiszowe

Dodaj kombinację klawiszy komendą notacji klawiszy lub skrótem klawiszowym Alt+K.

Reprezentuj kombinacje klawiszowe używając taga <kbd>. Oddziel od siebie klawisze znakiem plus, np <kbd>Alt+Tab</kbd>.

Indeks górny oraz dolny

Przykład: wpisując H<sub>2</sub>O i m<sup>2</sup> otrzymasz: H2O i m2.

Składnia Tex

By precyzyjnie wyrazić działanie matematyczne, użyj składni Tex.

<tex>arcctg(x) = argtan(\frac{1}{x}) = arcsin(\frac{1}{\sqrt{1+x^2}})</tex>

Kod źródłowy

Krótkie fragmenty kodu

Wszelkie jednolinijkowe instrukcje języka programowania powinny być zawarte pomiędzy obróconymi apostrofami: `kod instrukcji` lub ``console.log(`string`);``.

Kod wielolinijkowy

Dodaj fragment kodu komendą . Fragmenty kodu zajmujące całą lub więcej linijek powinny być umieszczone w wielolinijkowym fragmencie kodu. Znaczniki ``` lub ~~~ umożliwiają kolorowanie różnych języków programowania. Możemy nadać nazwę języka programowania używając auto-uzupełnienia, kod został pokolorowany używając konkretnych ustawień kolorowania składni:

```javascript
document.write('Hello World');
```

Możesz zaznaczyć również już wklejony kod w edytorze, i użyć komendy  by zamienić go w kod. Użyj kombinacji Ctrl+`, by dodać fragment kodu bez oznaczników języka.

Tabelki

Dodaj przykładową tabelkę używając komendy . Przykładowa tabelka składa się z dwóch kolumn, nagłówka i jednego wiersza.

Wygeneruj tabelkę na podstawie szablonu. Oddziel komórki separatorem ; lub |, a następnie zaznacz szablonu.

nazwisko;dziedzina;odkrycie
Pitagoras;mathematics;Pythagorean Theorem
Albert Einstein;physics;General Relativity
Marie Curie, Pierre Curie;chemistry;Radium, Polonium

Użyj komendy by zamienić zaznaczony szablon na tabelkę Markdown.

Lista uporządkowana i nieuporządkowana

Możliwe jest tworzenie listy numerowanych oraz wypunktowanych. Wystarczy, że pierwszym znakiem linii będzie * lub - dla listy nieuporządkowanej oraz 1. dla listy uporządkowanej.

Użyj komendy by dodać listę uporządkowaną.

1. Lista numerowana
2. Lista numerowana

Użyj komendy by dodać listę nieuporządkowaną.

* Lista wypunktowana
* Lista wypunktowana
** Lista wypunktowana (drugi poziom)

Składnia Markdown

Edytor obsługuje składnię Markdown, która składa się ze znaków specjalnych. Dostępne komendy, jak formatowanie , dodanie tabelki lub fragmentu kodu są w pewnym sensie świadome otaczającej jej składni, i postarają się unikać uszkodzenia jej.

Dla przykładu, używając tylko dostępnych komend, nie możemy dodać formatowania pogrubienia do kodu wielolinijkowego, albo dodać listy do tabelki - mogłoby to doprowadzić do uszkodzenia składni.

W pewnych odosobnionych przypadkach brak nowej linii przed elementami markdown również mógłby uszkodzić składnie, dlatego edytor dodaje brakujące nowe linie. Dla przykładu, dodanie formatowania pochylenia zaraz po tabelce, mogłoby zostać błędne zinterpretowane, więc edytor doda oddzielającą nową linię pomiędzy tabelką, a pochyleniem.

Skróty klawiszowe

Skróty formatujące, kiedy w edytorze znajduje się pojedynczy kursor, wstawiają sformatowany tekst przykładowy. Jeśli w edytorze znajduje się zaznaczenie (słowo, linijka, paragraf), wtedy zaznaczenie zostaje sformatowane.

  • Ctrl+B - dodaj pogrubienie lub pogrub zaznaczenie
  • Ctrl+I - dodaj pochylenie lub pochyl zaznaczenie
  • Ctrl+U - dodaj podkreślenie lub podkreśl zaznaczenie
  • Ctrl+S - dodaj przekreślenie lub przekreśl zaznaczenie

Notacja Klawiszy

  • Alt+K - dodaj notację klawiszy

Fragment kodu bez oznacznika

  • Alt+C - dodaj pusty fragment kodu

Skróty operujące na kodzie i linijkach:

  • Alt+L - zaznaczenie całej linii
  • Alt+, Alt+ - przeniesienie linijki w której znajduje się kursor w górę/dół.
  • Tab/⌘+] - dodaj wcięcie (wcięcie w prawo)
  • Shit+Tab/⌘+[ - usunięcie wcięcia (wycięcie w lewo)

Dodawanie postów:

  • Ctrl+Enter - dodaj post
  • ⌘+Enter - dodaj post (MacOS)