Import & spawn 3D objects
in
Contributed Library Questions
•
2 years ago
Het guys,
This is my first post here. I hope I'm posting in the right forum.
I'm currently working on some audio reactive visuals, but I've got a problem with spawning 3D models.
I can spawn boxes perfectly fine, but when it comes to importing 3D models I've got a problem. I just can't figure it how to spawn them. The 3D models are made in 3DS Max, and exporting to different filetypes is no problem.
I'm using 2 classes, object classes, which each represent an object, and one objects class, which hold all the object classes.
As you might've guessed, I was trying to draw an 3D model in each object class. (Replaced it with a box right now)
Objects class:
- public class Objects
- {
- ArrayList objects = new ArrayList();
- float prevLow = 0;
- float prevMid = 0;
- float prevHigh = 0;
- float amp;
- void spawnObjects(int spawnAmmount, int lifeSpan, int spawnRadius1, int spawnRadius2)
- {
- for(int i = 0; i < spawnAmmount; i++)
- {
- objects.add(new Object(lifeSpan, spawnRadius1, spawnRadius2));
- }
- }
- void updateObjects()
- {
- // Check if bass freq increases
- amp = 1;
- for(int i = fft.specSize()/50; i < (fft.specSize()/50)*2; i++)
- {
- if(fft.getBand(i) > prevLow*8)
- {
- amp = 50;
- prevLow = fft.getBand(i);
- }
- }
- prevLow = prevLow - (prevLow/10);
- for(int i = 0; i < objects.size()-1; i++)
- {
- Object object = (Object) objects.get(i);
- if(object.dead())
- {
- objects.remove(i);
- }
- else
- {
- object.update(amp);
- }
- }
- }
- void drawObjects()
- {
- for(int i = 0; i < objects.size()-1; i++)
- {
- Object object = (Object) objects.get(i);
- object.draw();
- }
- }
- }
Object class:
- public class Object
- {
- int l,r1,r2;
- float x,y,z,w,h,d,rx,ry,rz;
- Object(int lifeSpan, int spawnRadius1, int spawnRadius2)
- {
- l = lifeSpan*fps;
- r1 = spawnRadius1/2;
- r2 = spawnRadius2/2;
- x = 0;
- y = 0;
- z = 0;
- while(
- x < r1 && x > -r1 &&
- y < r1 && y > -r1 &&
- z < r1 && z > -r1
- )
- {
- x = random(-r2,r2);
- y = random(-r2,r2);
- z = random(-r2,r2);
- }
- w = random(0,50);
- h = random(0,50);
- d = random(0,50);
- rx = random(0,360);
- ry = random(0,360);
- rz = random(0,360);
- }
- void update(float amp)
- {
- // -1 one life
- l -= 1;
- // move
- x += random(-1,1);
- y += random(-1,1);
- z += random(-1,1);
- // resize
- w += random(0,amp);
- h += random(0,amp);
- d += random(0,amp);
- w = w - (w/10);
- h = h - (h/10);
- d = d - (d/10);
- // rotate
- rx += random(-1,1);
- ry += random(-1,1);
- rz += random(-1,1);
- }
- void draw()
- {
- // Transform world
- translate(x,y,z);
- rotateX(radians(rx));
- rotateY(radians(ry));
- rotateZ(radians(rz));
- // Draw object
- box(w,h,d);
- // Transform world back
- rotateZ(-radians(rz));
- rotateY(-radians(ry));
- rotateX(-radians(rx));
- translate(-x,-y,-z);
- }
- boolean dead()
- {
- if(l < 1)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
If you need more code, please tell me.
1