JavaB3d

Blitz3D Forums/Blitz3D Programming/JavaB3d

Leon Drake(Posted 2011) [#1]
Well i wasn't sure exactly what forum to post this in.

I started a little project to create a wrapper around Java3d to give people the ease of coding to mimic Blitz3d

Worklog: http://blitzbasic.com/logs/userlog.php?log=1831&user=9295

code example

package javab3d.examples;

import javab3d.JavaB3DApplet;
import javab3d.entity.JEntity;


public class Hello3DWorld extends JavaB3DApplet {

	public Hello3DWorld() 
	{

		JEntity j = CreateCube(null);
		RotateEntity(j,0.6,0.6,0.6);
		PositionEntity(j,0.5,0.1,-0.6);
	
		JEntity l = CreateLight(1,null);
		PositionEntity(l,-0.5,-0.1,0.6);
		
		JEntity s = CreateSphere(8,null);
		
		
		
	}

 

}



which so far produces this.




Hotshot2005(Posted 2011) [#2]
wow That is cool....Students could learn from it and become JavaB3d Expert in no time LOL :)

Last edited 2011


Leon Drake(Posted 2011) [#3]
Alright got brushes implemented so far, at least for setting diffuse colors, going to add texture and the various other colors you can set ambient, specular etc etc..

code example 2:

package javab3d.examples;

import javab3d.JavaB3DApplet;
import javab3d.brush.JBrush;
import javab3d.entity.JEntity;


public class Hello3DWorld extends JavaB3DApplet {

	public Hello3DWorld() 
	{

		JEntity j = CreateCube(null);
		RotateEntity(j,0.6,0.6,0.6);
		PositionEntity(j,0.5,0.1,-0.6);
	
		JEntity l = CreateLight(1,null);
		PositionEntity(l,-0.5,-0.1,0.6);
		
		JEntity s = CreateSphere(8,null);
		
		JBrush b = CreateBrush(1.0f,0.0f,0.0f);
		
		PaintEntity(s,b);
		
		
		
	}

 

}


we now have a red ball!




Leon Drake(Posted 2011) [#4]
Got basic textures in via brushes, i'll have to make a few functions so you can just add a texture to an entity without using a brush.

package javab3d.examples;

import javab3d.JavaB3DApplet;
import javab3d.brush.JBrush;
import javab3d.brush.JTexture;
import javab3d.entity.JEntity;


public class Hello3DWorld extends JavaB3DApplet {

	public Hello3DWorld() 
	{

		JTexture tex = LoadTexture("C:\\Program Files\\Blitz3D\\samples\\mak\\flag\\b3dlogo.jpg",0);
		
		
		JEntity j = CreateCube(null);
		RotateEntity(j,0.6,0.6,0.6);
		PositionEntity(j,0.5,0.1,-0.6);
	
		JEntity l = CreateLight(1,null);
		PositionEntity(l,-0.5,-0.1,0.6);
		
		JEntity s = CreateSphere(8,null);
		
		JBrush b = CreateBrush(1.0f,0.0f,0.0f);
		JBrush b2 = CreateBrush(0.0f,1.0f,0.0f);
		JBrush b3 = CreateBrush(0.0f,1.0f,1.0f);
		BrushTexture(b,tex,0,0);
		PaintEntity(s,b);
		PaintEntity(j,b2);
		
		JEntity c = CreateCone(8,null);
		RotateEntity(c,0.3,0.3,0.3);
		PositionEntity(c,-0.5,-0.1,-0.6);
		

		
		PaintEntity(c,b3);
	}

 

}





Kryzon(Posted 2011) [#5]
If these are applets... could you host them anywhere so we can test the performance etc?


Leon Drake(Posted 2011) [#6]
yep.

i think i'd like to set it up to spit out FPS and Number of Polygons first. Almost to that part.


Leon Drake(Posted 2011) [#7]
Ok so for the main loop you'd have to create a function like this

	public void Repeat()
	{
		RotateEntity(j,x,y,z);
		x+=0.0;
		y+=0.1;
		z+=0.0;
		
	}


i wonder what the FPS is because that box spins really flippin fast.


Leon Drake(Posted 2011) [#8]
Ok so i got the 2d stuff started, i dont think it will be a prob to implement both blitz3d and 2d commands.

Text command works fine

although i had to break the 3d and 2d portions up so that all the 2d stuff will render after the 3d. example

package javab3d.examples;

import java.awt.Graphics;

import javab3d.JavaB3DApplet;
import javab3d.brush.JBrush;
import javab3d.brush.JTexture;
import javab3d.entity.JEntity;


public class Hello3DWorld extends JavaB3DApplet {

	public JEntity j;
	public double x,y,z;
	public Hello3DWorld() 
	{
		//System.out.println(getCodeBase());
		JTexture tex = LoadTexture("javab3d/examples/images/b3dlogo.jpg",0);
		
		
		j = CreateCube(null);
		
		PositionEntity(j,0.5,0.1,-0.6);
	
		JEntity l = CreateLight(1,null);
		PositionEntity(l,-0.5,-0.1,0.6);
		
		JEntity s = CreateSphere(8,null);
		
		JBrush b = CreateBrush(1.0f,0.0f,0.0f);
		JBrush b2 = CreateBrush(0.0f,1.0f,0.0f);
		JBrush b3 = CreateBrush(0.0f,1.0f,1.0f);
		BrushTexture(b2,tex,0,0);
		PaintEntity(s,b);
		PaintEntity(j,b2);
		
		JEntity c = CreateCone(8,null);
		RotateEntity(c,0.3,0.3,0.3);
		PositionEntity(c,-0.5,-0.1,-0.6);
		

		
		PaintEntity(c,b3);
	}
	
	public void Repeat()
	{
		
		RotateEntity(j,x,y,z);
		x+=0.0;
		y+=0.1;
		z+=0.0;
		
	}
	
	public void Start2D()
	{
		Text(10,20,"Hey Blitzcoders!");
	}
	

 

}


created a special loop function for 2d "Start2D()"

which creates this




Leon Drake(Posted 2011) [#9]
Ok guys here is the url to the online applet, also i set it so you can use a web URL for the image file location as well. As you can see in the app it loads the blitz magazine cover on the homepage.

http://vigilsoft.net/javab3d/test.php


Kryzon(Posted 2011) [#10]
Hi Leon, sorry for the delay in testing.
I tried running it but Java threw some error lines:
javax.media.j3d.NativePipeline getSupportedOglVendor
SEVERE: java.lang.UnsatisfiedLinkError: no j3dcore-ogl-chk in java.library.path
java.lang.UnsatisfiedLinkError: no j3dcore-d3d in java.library.path

I updated my Java runtime before testing it, so it's the latest version.

Last edited 2011


Leon Drake(Posted 2011) [#11]
hmm must be some other jar file i forgot to include. i'll need to check that. i guess it works fine if you download java3d and install it. i'll need to look up exactly what i need to include for people who don't have it installed.


Anyways update: nearly done with the B3d importer. I also have a cal3d importer i wrote for unity in java mono, i'm pretty sure i can use it for this as i kinda prefer that format over b3d and it would be nice to have more options since b3d exporters aren't getting updated much.


TeaBoy(Posted 2011) [#12]
Leon, DUDE!

this is goooooooooooooooood stuff, I love Java and this will be a very cool addition, keep up the great work!


RifRaf(Posted 2011) [#13]
This is great, ive never used java but now I have motivation to learn enough to use this. Where should I start, is there an easy to use interpreter(ide) for Java coding ?


Leon Drake(Posted 2011) [#14]
eclipse for the win. best java IDE i know of.

man what a pain default IOstreams in java is bigendian and b3dfiles are littleendian.


fortunately i got that solved so now its just a matter of getting it to read every chunk.

man the api guide to javab3d is so vague i'm still trying to figure out how to weight vertices to bones.

at anyrate i think getting this b3dloader will be a major step in getting this done. most of the other commands are fairly simple to convert.. least until i get to the collision portion. but i am happy to see java3d comes with a 3d sound library :D


Kryzon(Posted 2011) [#15]
Skeletal animations are done in regular code, not through the API.

Have you taken a look at the MiniB3D source? it has the skeletal animation part. Well, only that actually.
It's missing animations for non-bone nodes, and I'm surprised since it's much simpler to implement (just calculate the matrices and that's it, the objects are animated).


Leon Drake(Posted 2011) [#16]
ya i'll take a look at that, for now i'm having some weird issue parsing the brush chunk from a b3d file. i parsed texs no problem but whenever i try to read number of texs from the file it returns 37 which is way too many textures for this model. i have to look to see if somehow i read from it after it finds the BRUS tag it's possible the reader got offset somewhere.