use of org.rajawali3d.Object3D in project Rajawali by Rajawali.
the class ObjectColorPicker method pickObject.
public static void pickObject(ColorPickerInfo pickerInfo) {
final ObjectColorPicker picker = pickerInfo.getPicker();
OnObjectPickedListener listener = picker.mObjectPickedListener;
if (listener != null) {
final ByteBuffer pixelBuffer = ByteBuffer.allocateDirect(4);
pixelBuffer.order(ByteOrder.nativeOrder());
GLES20.glReadPixels(pickerInfo.getX(), picker.mRenderer.getViewportHeight() - pickerInfo.getY(), 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
pixelBuffer.rewind();
final int r = pixelBuffer.get(0) & 0xff;
final int g = pixelBuffer.get(1) & 0xff;
final int b = pixelBuffer.get(2) & 0xff;
final int a = pixelBuffer.get(3) & 0xff;
final int index = Color.argb(a, r, g, b);
if (0 <= index && index < picker.mObjectLookup.size()) {
// Index may have holes due to unregistered objects
Object3D pickedObject = picker.mObjectLookup.get(index);
if (pickedObject != null) {
listener.onObjectPicked(pickedObject);
return;
}
}
listener.onNoObjectPicked();
}
}
use of org.rajawali3d.Object3D in project Rajawali by Rajawali.
the class Scene method updateChildMaterialWithLights.
/**
* Update the lights on this child's material. This method should only
* be called when the lights collection is dirty. It will
* trigger compilation of all light-enabled shaders.
*
* @param child
*/
private void updateChildMaterialWithLights(Object3D child) {
Material material = child.getMaterial();
if (material != null && material.lightingEnabled())
material.setLights(mLights);
if (material != null && mFogParams != null)
material.addPlugin(new FogMaterialPlugin(mFogParams));
int numChildren = child.getNumChildren();
for (int i = 0; i < numChildren; i++) {
Object3D grandChild = child.getChildAt(i);
updateChildMaterialWithLights(grandChild);
}
}
use of org.rajawali3d.Object3D in project Rajawali by Rajawali.
the class RayPickingVisitor method apply.
public void apply(INode node) {
if (node instanceof Object3D) {
Object3D o = (Object3D) node;
if (!o.isVisible() || !o.isInFrustum())
return;
if (o.getGeometry().hasBoundingSphere()) {
BoundingSphere bsphere = o.getGeometry().getBoundingSphere();
bsphere.calculateBounds(o.getGeometry());
bsphere.transform(o.getModelMatrix());
if (intersectsWith(bsphere)) {
if (mPickedObject == null || (mPickedObject != null && o.getPosition().z < mPickedObject.getPosition().z))
mPickedObject = o;
}
} else {
// Assume bounding box if no bounding sphere found.
BoundingBox bbox = o.getGeometry().getBoundingBox();
bbox.calculateBounds(o.getGeometry());
bbox.transform(o.getModelMatrix());
if (intersectsWith(bbox)) {
if (mPickedObject == null || (mPickedObject != null && o.getPosition().z < mPickedObject.getPosition().z))
mPickedObject = o;
}
}
}
}
Aggregations