Can't Get this Simple Appet to Work Online

Started by AGP, June 09, 2009, 08:16:33 PM

Previous topic - Next topic

AGP

Locally it runs fine (although it just occurred to me that the jaguar.3DS file is in the same folder as the jar). I've tried variations of the Loader.load3DS line and none of them work either.


import java.awt.*;
import java.applet.*;
import com.threed.jpct.*;

public class RacerMusic extends Applet {
     private FrameBuffer buffer;
     private World theWorld;
     private Object3D car;
     private Camera camera;
     private AudioClip music;
     private float cameraToObjectDistance, cameraDisplacement;

     public void init() {
try {
     music = Applet.newAudioClip(this.getClass().getResource("TheSign.wav"));
}
catch (Exception e) {}
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
Config.maxPolysVisible = 250000;
Config.collideOffset = 500;
Config.oldStyle3DSLoader = true;
theWorld = new World();
theWorld.setAmbientLight(100, 100, 100);
camera = theWorld.getCamera();
car = Object3D.mergeAll(Loader.load3DS(this.getClass().getResource("./jaguar.3DS"), "jaguar.3DS", 1f));
theWorld.addObject(car);
theWorld.buildAllObjects();
System.out.println("Got this far (past loading the model).");
follow();
System.out.println("Got this far. 2");
     }
     private void follow() {
Matrix matrix = car.getWorldTransformation().invert3x3();
camera.setBack(matrix);
camera.setPosition(car.getTransformedCenter());
camera.rotateCameraX((float)Math.toRadians(100+cameraDisplacement));
camera.moveCamera(Camera.CAMERA_MOVEOUT, cameraToObjectDistance);
     }

     public void paint(Graphics g) {
if (buffer == null || theWorld == null)
     return;
buffer.clear(Color.black);
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.display(g);
     }

     public void start() {
music.loop();
     }
     public void stop() {}
     public void destroy() {}
}


EDIT: The HTML file (I want it to run via AppletLoader):
<html>
  <applet code="org.lwjgl.util.applet.AppletLoader" archive="lwjgl_util_applet.jar, lzma.jar" codebase="."

width="800" height="600">
    <param name="java_arguments" value="-Xmx320m">
    <param name="al_title" value="Racer Music v. 0.1">
    <param name="al_main" value="RacerMusic">
    <!-- logo to paint while loading, will be centered -->
    <param name="al_logo" value="Car.gif">
    <!-- progressbar to paint while loading. Will be painted on top of logo, width clipped to percentage done -->
    <param name="al_progressbar" value="appletprogress.gif">
   
    <!-- signed windows natives jar in a jar -->
    <param name="al_windows" value="windows_natives.jar.lzma">

    <!-- List of Jars to add to classpath -->
    <param name="al_jars" value="RacerMusic.jar, Data.jar, jpct.jar, lwjgl_applet.jar.pack.lzma,

lwjgl.jar.pack.lzma, jinput.jar.pack.lzma, lwjgl_util.jar.pack.lzma, res.jar.lzma">
   
    <!-- signed linux natives jar in a jar -->
    <param name="al_linux" value="linux_natives.jar.lzma">
   
    <!-- signed mac osx natives jar in a jar -->
    <param name="al_mac" value="macosx_natives.jar.lzma">

    <!-- signed solaris natives jar in a jar -->
    <param name="al_solaris" value="solaris_natives.jar.lzma">
   
    <!-- Tags under here are optional -->
   
    <!-- Version of Applet, important otherwise applet won't be cached, version change will update applet, must be

int or float -->
    <!-- <param name="al_version" value="0.1"> -->
   
    <!-- background color to paint with, defaults to white -->
    <!-- <param name="al_bgcolor" value="000000"> -->
   
    <!-- foreground color to paint with, defaults to black -->
    <!-- <param name="al_fgcolor" value="ffffff"> -->
   
    <!-- error color to paint with, defaults to red -->
    <!-- <param name="al_errorcolor" value="ff0000"> -->
   
    <!-- whether to run in debug mode -->
    <!-- <param name="al_debug" value="false"> -->
   
    <!-- whether to prepend host to cache path - defaults to true -->
    <param name="al_prepend_host" value="false">

  </applet>

  <p>
    if <code>al_debug</code> is true the applet will load and extract resources with a delay, to be able to see the

loader process.
  </p>

  </body>
</html>

EgonOlsen


AGP

It tells me it's an invalid 3ds file. I sent you the jar.

EgonOlsen

Invalid 3ds file is a (pretty dumb) message that actually means: File not found! Something like "Couldn't read file..." should be printed out right before the "invalid" message. I suggest to do a Logger.setOnError(Logger.ON_ERROR_THROW_EXCEPTION); right at the start of your program to get better exception handling.

I haven't received any jar file yet...i have a pretty strict SPAM filter, which simply deletes everything that it considers to be SPAM immediately. Maybe it killed your message on the way...any chance that i can download it somewhere ???

AGP

#4
REMOVED THE LINK (WEB SITE ISN"T READY YET)

EgonOlsen

I can't really test it...too much is missing and i have no idea where to get all these lzma-things from. Anyway, i would expect that


car = Object3D.mergeAll(Loader.load3DS(this.getClass().getResourceAsStream("jaguar.3DS", 1f));


should do the trick...doesn't it?

BTW: Your mail finally has arrived...it took 30min, but it made it... ;D

AGP

That's good to know you're not blocking me lol. The lzma stuff is the lwjgl applet package. You should really download it. And no, I tried the getResourceAsStream as well. Same message.

EgonOlsen

Ok, i did that...the version that i've posted above works fine for me:


Loading file from InputStream
File from InputStream loaded...23933 bytes
Processing new material 1 - Default!
Processing object from 3DS-file: Jaguar
Object 'Jaguar_jPCT5' created using 630 polygons and 520 vertices.


The test applet can be found here: http://www.jpct.net/test

(Don't mind the strange logo and such...i just took a random gif)

The "Fatal error (9):null"-stuff comes from the music.loop()-call. Remove it (because the music doesn't load anyway this way), and it doesn't say this anymore. I've slightly modified the applet to see at least something. This is the version, that i'm using:


import java.awt.*;
import java.applet.*;
import com.threed.jpct.*;

public class RacerMusic extends Applet {
private FrameBuffer buffer;
private World theWorld;
private Object3D car;
private Camera camera;
private AudioClip music;
private boolean exit;
private float cameraToObjectDistance, cameraDisplacement;

public void init() {
try {
music = Applet.newAudioClip(this.getClass().getResource(
"TheSign.wav"));
} catch (Exception e) {
e.printStackTrace();
}
Logger.setOnError(Logger.ON_ERROR_THROW_EXCEPTION);
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
Config.maxPolysVisible = 250000;
Config.collideOffset = 500;
Config.oldStyle3DSLoader = true;  // Needed?
theWorld = new World();
theWorld.setAmbientLight(100, 100, 100);
camera = theWorld.getCamera();
car = Object3D.mergeAll(Loader.load3DS(this.getClass()
.getResourceAsStream("jaguar.3DS"), 1f));
theWorld.addObject(car);
theWorld.buildAllObjects();
System.out.println("Got this far (past loading the model).");
follow();
System.out.println("Got this far. 2");
}

private void follow() {
Matrix matrix = car.getWorldTransformation().invert3x3();
camera.setBack(matrix);
camera.setPosition(car.getTransformedCenter());
camera.rotateCameraX((float) Math.toRadians(100 + cameraDisplacement));
camera.moveCamera(Camera.CAMERA_MOVEOUT, cameraToObjectDistance);
}

public void paint(Graphics g) {
if (buffer == null || theWorld == null) {
System.out.println("Not initialized yet...");
return;
}
buffer.clear(Color.black);
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.display(g);
}

public void update(Graphics g) {
paint(g);
}

public void start() {
new Thread() {
public void run() {
while (!exit) {
repaint();
try {
Thread.sleep(10);
} catch (Exception e) {
}
}
}
}.start();
}

public void stop() {
exit = true;
}

public void destroy() {
}
}


I think that it should actually be a JApplet instead of Applet and i don't think that the paint/update/repaint-stuff that i've added is a good one, but i


  • hate applets
  • have no clue about applets
  • wanted to see some graphics

...hence the crude code...hope this helps anyway.

EgonOlsen

BTW: The wiki contains some applet stuff...maybe that can be helpful.

paulscode

From your post, it sounds as though the 3DS file is not compiled inside the JAR, but external from the JAR (in the same directory).  If that is the case, then you can't access it via getResource or getResourceAsStream (those assume a resource compiled inside the JAR).  Instead you can access it with a new URL instance, something like:
car = Object3D.mergeAll(Loader.load3DS(new URL("./jaguar.3DS"), "jaguar.3DS", 1f));
I haven't done this recently, so if that doesn't work, try using ".\\jaguar.3DS" or just "jaguar.3DS" (or the full path "http://www. ...") for the filename.  Using a URL instance makes sence for applets, but this could probably also be done with an InputStream derived from a File instance.

AGP

Thanks Egon and paulscode. Paulscode, the file was in the jar, I just meant that it was also in that folder so that I didn't know which one was being loaded locally. And Egon, you needed Data.jar for the music, which plays fine. But it did finally work.