use of com.badlogic.gdx.graphics.g3d.ModelInstance in project nhglib by VoidZombie.
the class ModelComponent method initWithModel.
public void initWithModel(Model m) {
model = new ModelInstance(m);
state = ModelComponent.State.READY;
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ModelInstanceRenderer method update.
@Override
public void update() {
for (int i = 0, positionOffset = 0, c = controller.particles.size; i < c; ++i, positionOffset += renderData.positionChannel.strideSize) {
ModelInstance instance = renderData.modelInstanceChannel.data[i];
float scale = hasScale ? renderData.scaleChannel.data[i] : 1;
float qx = 0, qy = 0, qz = 0, qw = 1;
if (hasRotation) {
int rotationOffset = i * renderData.rotationChannel.strideSize;
qx = renderData.rotationChannel.data[rotationOffset + ParticleChannels.XOffset];
qy = renderData.rotationChannel.data[rotationOffset + ParticleChannels.YOffset];
qz = renderData.rotationChannel.data[rotationOffset + ParticleChannels.ZOffset];
qw = renderData.rotationChannel.data[rotationOffset + ParticleChannels.WOffset];
}
instance.transform.set(renderData.positionChannel.data[positionOffset + ParticleChannels.XOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.YOffset], renderData.positionChannel.data[positionOffset + ParticleChannels.ZOffset], qx, qy, qz, qw, scale, scale, scale);
if (hasColor) {
int colorOffset = i * renderData.colorChannel.strideSize;
ColorAttribute colorAttribute = (ColorAttribute) instance.materials.get(0).get(ColorAttribute.Diffuse);
BlendingAttribute blendingAttribute = (BlendingAttribute) instance.materials.get(0).get(BlendingAttribute.Type);
colorAttribute.color.r = renderData.colorChannel.data[colorOffset + ParticleChannels.RedOffset];
colorAttribute.color.g = renderData.colorChannel.data[colorOffset + ParticleChannels.GreenOffset];
colorAttribute.color.b = renderData.colorChannel.data[colorOffset + ParticleChannels.BlueOffset];
if (blendingAttribute != null)
blendingAttribute.opacity = renderData.colorChannel.data[colorOffset + ParticleChannels.AlphaOffset];
}
}
super.update();
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class ProjectTest method create.
@Override
public void create() {
ObjLoader objLoader = new ObjLoader();
sphere = objLoader.loadModel(Gdx.files.internal("data/sphere.obj"));
sphere.materials.get(0).set(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE));
cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
instances[i] = new ModelInstance(sphere, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
}
batch = new SpriteBatch();
font = new BitmapFont();
logo = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
modelBatch = new ModelBatch();
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class EdgeDetectionTest method create.
public void create() {
ShaderProgram.pedantic = false;
/*
* shader = new ShaderProgram(Gdx.files.internal("data/shaders/default.vert").readString(), Gdx.files.internal(
* "data/shaders/depthtocolor.frag").readString()); if (!shader.isCompiled()) { Gdx.app.log("EdgeDetectionTest",
* "couldn't compile scene shader: " + shader.getLog()); }
*/
batchShader = new ShaderProgram(Gdx.files.internal("data/shaders/batch.vert").readString(), Gdx.files.internal("data/shaders/convolution.frag").readString());
if (!batchShader.isCompiled()) {
Gdx.app.log("EdgeDetectionTest", "couldn't compile post-processing shader: " + batchShader.getLog());
}
ObjLoader objLoader = new ObjLoader();
scene = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
sceneInstance = new ModelInstance(scene);
modelBatch = new ModelBatch();
fbo = new FrameBuffer(Format.RGB565, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 0, 10);
cam.lookAt(0, 0, 0);
cam.far = 30;
batch = new SpriteBatch();
batch.setShader(batchShader);
fboRegion = new TextureRegion(fbo.getColorBufferTexture());
fboRegion.flip(false, true);
logger = new FPSLogger();
calculateOffsets();
}
use of com.badlogic.gdx.graphics.g3d.ModelInstance in project libgdx by libgdx.
the class Animation3DTest method onLoaded.
@Override
protected void onLoaded() {
if (skydome == null) {
skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
instances.add(new ModelInstance(floorModel, "floor"));
instances.add(tree = new ModelInstance(floorModel, "tree"));
assets.load("data/g3d/knight.g3db", Model.class);
loading = true;
} else if (character == null) {
character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
BoundingBox bbox = new BoundingBox();
character.calculateBoundingBox(bbox);
character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
instances.add(character);
animation = new AnimationController(character);
animation.animate("Idle", -1, 1f, null, 0.2f);
status = idle;
for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
// Now attach the node of another model at the tip of this knights sword:
ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
ship.detach();
// offset from the sword node to the tip of the sword, in rest pose
ship.translation.x = 10f;
ship.rotation.set(Vector3.Z, 90f);
ship.scale.scl(5f);
ship.parts.get(0).enabled = false;
character.getNode("sword").addChild(ship);
}
}
Aggregations