/** * Called at every frame update. * * @param frame Frame information */ public void update(FrameInput frame) { // Notify to components for (Component component : components.values()) { component.update(frame); } // Notify to children for (Entity child : children) { child.update(frame); } // Update local model matrix if necessary. if (localMatrixUpdateRequired) { updateLocalMatrix(); invalidateWorldModelMatrix(); localMatrixUpdateRequired = false; } // Update world model matrix if necessary. if (worldMatrixUpdateRequired) { updateWorldModelMatrix(); worldMatrixUpdateRequired = false; // Update native side values worldModelMatrix.get(matrixValues); setWorldModelMatrix(nativePointer.get(), matrixValues); } // Update opacity if necessary. if (updateOpacityRequired) { updateOpacity(); updateOpacityRequired = false; } }
/** * Create Entity from {@link Drawable}. New Entity has plane geometry. * * @param drawable Drawable for surface. * @return new Entity */ public static Entity from(Drawable drawable) { final Entity entity = new Entity(); entity.add(SurfaceRendererComponent.from(drawable)); entity.add(GeometryComponent.from(drawable)); return entity; }
/** * Create Entity from {@link View}. New Entity has plane geometry. * * @param view View for surface. * @return new Entity */ public static Entity from(View view) { final Entity entity = new Entity(); entity.add(SurfaceRendererComponent.from(view)); entity.add(GeometryComponent.from(view)); return entity; }
/** * Add child {@link Entity}. * * @param child Child entity. * @return {@code true} if Successfully added. Otherwise {@code false}. */ public boolean add(Entity child) { final boolean added = children.add(child); if (added) { child.parent = this; child.setApp(app); } return added; }
/** * For internal use only. * * @param app */ void setApp(MeganekkoApp app) { this.app = app; // Propagate to children for (Entity child : children) { child.setApp(app); } }
private void invalidateWorldModelMatrix() { worldMatrixUpdateRequired = true; // Propagate to children for (Entity child : children) { child.invalidateWorldModelMatrix(); } }
/** @return {@code true} if this entity and ancestors are all visible. Otherwise {@code false}. */ public boolean isShown() { if (!visible) return false; // Check parent visibility Entity parent = getParent(); if (parent == null) return true; return parent.isShown(); }
/** * For internal use only. * * @param surfacesPointer {@code &res.Surfaces} */ void collectSurfaceDefs(long surfacesPointer) { // Not visible if (!visible) return; addSurfaceDef(nativePointer.get(), surfacesPointer); for (Entity child : children) { child.collectSurfaceDefs(surfacesPointer); } }
private void updateOpacity() { SurfaceRendererComponent surfaceRendererComponent = getComponent(SurfaceRendererComponent.class); if (surfaceRendererComponent != null) { surfaceRendererComponent.setOpacity(getRenderingOpacity()); } for (Entity child : children) { child.updateOpacity(); } }
/** * Find {@link Entity} from children. Typically, id is {@code R.id.xxx} value. * * @param id ID * @return Found Entity or {@code null} if it has no matched Entity with id. */ @Nullable public Entity findById(int id) { if (this.id == id) return this; for (Entity child : children) { Entity found = child.findById(id); if (found != null) return found; } return null; }
/** Update world model matrix. */ public void updateWorldModelMatrix() { // parentMatrix * worldModelMatrix Entity parent = getParent(); if (parent != null) { Matrix4f parentMatrix = parent.getWorldModelMatrix(); parentMatrix.mul(localMatrix, worldModelMatrix); } else { // worldModelMatrix = localMatrix worldModelMatrix.set(localMatrix); } }
/** * Remove child {@link Entity}. * * @param child Child entity. * @return {@code true} if Successfully removed. Otherwise {@code false}. */ public boolean remove(Entity child) { final boolean removed = children.remove(child); if (removed) { child.parent = null; } return removed; }
private float parentOpacity() { Entity parent = getParent(); return parent != null ? parent.getOpacity() : 1.0f; }
/** * Remove this from scene graph. * * @return {@code true} if Successfully removed. Otherwise {@code false}. * @since 3.0.17 */ public boolean remove() { return parent != null && parent.remove(this); }