Search in sources :

Example 16 with Object3D

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();
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) Object3D(org.rajawali3d.Object3D)

Example 17 with Object3D

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);
    }
}
Also used : Material(org.rajawali3d.materials.Material) ShadowMapMaterial(org.rajawali3d.postprocessing.materials.ShadowMapMaterial) FogMaterialPlugin(org.rajawali3d.materials.plugins.FogMaterialPlugin) Object3D(org.rajawali3d.Object3D)

Example 18 with Object3D

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;
            }
        }
    }
}
Also used : BoundingSphere(org.rajawali3d.bounds.BoundingSphere) BoundingBox(org.rajawali3d.bounds.BoundingBox) Object3D(org.rajawali3d.Object3D)

Aggregations

Object3D (org.rajawali3d.Object3D)18 Vector3 (org.rajawali3d.math.vector.Vector3)5 Material (org.rajawali3d.materials.Material)4 ArrayList (java.util.ArrayList)3 SkeletalAnimationChildObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationChildObject3D)2 SkeletalAnimationObject3D (org.rajawali3d.animation.mesh.SkeletalAnimationObject3D)2 ParsingException (org.rajawali3d.loader.ParsingException)2 DiffuseMethod (org.rajawali3d.materials.methods.DiffuseMethod)2 TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)2 Matrix4 (org.rajawali3d.math.Matrix4)2 Quaternion (org.rajawali3d.math.Quaternion)2 SparseArray (android.util.SparseArray)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ByteBuffer (java.nio.ByteBuffer)1