Class RenderableManager.Builder
- java.lang.Object
-
- com.google.android.filament.RenderableManager.Builder
-
- Enclosing class:
- RenderableManager
public static class RenderableManager.Builder extends java.lang.ObjectAdds renderable components to entities using a builder pattern.
-
-
Constructor Summary
Constructors Constructor Description Builder(int count)Creates a builder for renderable components.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RenderableManager.BuilderblendOrder(int index, int blendOrder)Sets an ordering index for blended primitives that all live at the same Z value.RenderableManager.BuilderboundingBox(Box aabb)The axis-aligned bounding box of the renderable.voidbuild(Engine engine, int entity)Adds the Renderable component to an entity.RenderableManager.BuildercastShadows(boolean enabled)Controls if this renderable casts shadows, false by default.RenderableManager.Builderculling(boolean enabled)Controls frustum culling, true by default.RenderableManager.BuilderenableSkinningBuffers(boolean enabled)Allows bones to be swapped out and shared using SkinningBuffer.RenderableManager.Buildergeometry(int index, RenderableManager.PrimitiveType type, VertexBuffer vertices, IndexBuffer indices)RenderableManager.Buildergeometry(int index, RenderableManager.PrimitiveType type, VertexBuffer vertices, IndexBuffer indices, int offset, int count)RenderableManager.Buildergeometry(int index, RenderableManager.PrimitiveType type, VertexBuffer vertices, IndexBuffer indices, int offset, int minIndex, int maxIndex, int count)Specifies the geometry data for a primitive.RenderableManager.Builderinstances(int instanceCount)Specifies the number of draw instance of this renderable.RenderableManager.BuilderlayerMask(int select, int value)Sets bits in a visibility mask.RenderableManager.BuilderlightChannel(int channel, boolean enable)Enables or disables a light channel.RenderableManager.Buildermaterial(int index, MaterialInstance material)Binds a material instance to the specified primitive.RenderableManager.Buildermorphing(int targetCount)Controls if the renderable has vertex morphing targets, zero by default.RenderableManager.Buildermorphing(int level, int primitiveIndex, MorphTargetBuffer morphTargetBuffer)Utility method to specify morph target buffer for a primitive.RenderableManager.Buildermorphing(int level, int primitiveIndex, MorphTargetBuffer morphTargetBuffer, int offset, int count)Specifies the morph target buffer for a primitive.RenderableManager.Builderpriority(int priority)Provides coarse-grained control over draw order.RenderableManager.BuilderreceiveShadows(boolean enabled)Controls if this renderable receives shadows, true by default.RenderableManager.BuilderscreenSpaceContactShadows(boolean enabled)Controls if this renderable uses screen-space contact shadows.RenderableManager.Builderskinning(int boneCount)RenderableManager.Builderskinning(int boneCount, java.nio.Buffer bones)Enables GPU vertex skinning for up to 255 bones, 0 by default.RenderableManager.Builderskinning(SkinningBuffer skinningBuffer, int boneCount, int offset)Enables GPU vertex skinning for up to 255 bones, 0 by default.
-
-
-
Constructor Detail
-
Builder
public Builder(@IntRange(from=1L) int count)Creates a builder for renderable components.- Parameters:
count- the number of primitives that will be supplied to the builder Note that builders typically do not have a long lifetime since clients should discard them after callingbuild(com.google.android.filament.Engine, int). For a usage example, seeRenderableManager.
-
-
Method Detail
-
geometry
@NonNull public RenderableManager.Builder geometry(@IntRange(from=0L) int index, @NonNull RenderableManager.PrimitiveType type, @NonNull VertexBuffer vertices, @NonNull IndexBuffer indices, @IntRange(from=0L) int offset, @IntRange(from=0L) int minIndex, @IntRange(from=0L) int maxIndex, @IntRange(from=0L) int count)
Specifies the geometry data for a primitive. Filament primitives must have an associatedVertexBufferandIndexBuffer. Typically, each primitive is specified with a pair of daisy-chained calls:geometry()andmaterial().- Parameters:
index- zero-based index of the primitive, must be less than the count passed to Builder constructortype- specifies the topology of the primitive (e.g.,RenderableManager.PrimitiveType.TRIANGLES)vertices- specifies the vertex buffer, which in turn specifies a set of attributesindices- specifies the index buffer (either u16 or u32)offset- specifies where in the index buffer to start reading (expressed as a number of indices)minIndex- specifies the minimum index contained in the index buffermaxIndex- specifies the maximum index contained in the index buffercount- number of indices to read (for triangles, this should be a multiple of 3)
-
geometry
@NonNull public RenderableManager.Builder geometry(@IntRange(from=0L) int index, @NonNull RenderableManager.PrimitiveType type, @NonNull VertexBuffer vertices, @NonNull IndexBuffer indices, @IntRange(from=0L) int offset, @IntRange(from=0L) int count)
-
geometry
@NonNull public RenderableManager.Builder geometry(@IntRange(from=0L) int index, @NonNull RenderableManager.PrimitiveType type, @NonNull VertexBuffer vertices, @NonNull IndexBuffer indices)
-
material
@NonNull public RenderableManager.Builder material(@IntRange(from=0L) int index, @NonNull MaterialInstance material)
Binds a material instance to the specified primitive.If no material is specified for a given primitive, Filament will fall back to a basic default material.
- Parameters:
index- zero-based index of the primitive, must be less than the count passed to Builder constructormaterial- the material to bind
-
blendOrder
@NonNull public RenderableManager.Builder blendOrder(@IntRange(from=0L) int index, @IntRange(from=0L,to=32767L) int blendOrder)
Sets an ordering index for blended primitives that all live at the same Z value.- Parameters:
index- the primitive of interestblendOrder- draw order number (0 by default). Only the lowest 15 bits are used.
-
boundingBox
@NonNull public RenderableManager.Builder boundingBox(@NonNull Box aabb)
The axis-aligned bounding box of the renderable.This is an object-space AABB used for frustum culling. For skinning and morphing, this should encompass all possible vertex positions. It is mandatory unless culling is disabled for the renderable.
-
layerMask
@NonNull public RenderableManager.Builder layerMask(@IntRange(from=0L,to=255L) int select, @IntRange(from=0L,to=255L) int value)
Sets bits in a visibility mask. By default, this is 0x1.This feature provides a simple mechanism for hiding and showing groups of renderables in a Scene. See
View.setVisibleLayers(int, int).For example, to set bit 1 and reset bits 0 and 2 while leaving all other bits unaffected, do:
builder.layerMask(7, 2).- Parameters:
select- the set of bits to affectvalue- the replacement values for the affected bits- See Also:
RenderableManager.setLayerMask(int, int, int)
-
priority
@NonNull public RenderableManager.Builder priority(@IntRange(from=0L,to=7L) int priority)
Provides coarse-grained control over draw order.In general Filament reserves the right to re-order renderables to allow for efficient rendering. However clients can control ordering at a coarse level using priority.
For example, this could be used to draw a semitransparent HUD, if a client wishes to avoid using a separate View for the HUD. Note that priority is completely orthogonal to
layerMask(int, int), which merely controls visibility.The priority is clamped to the range [0..7], defaults to 4; 7 is lowest priority (rendered last).
- See Also:
blendOrder(int, int)
-
culling
@NonNull public RenderableManager.Builder culling(boolean enabled)
Controls frustum culling, true by default.Do not confuse frustum culling with backface culling. The latter is controlled via the material.
-
lightChannel
@NonNull public RenderableManager.Builder lightChannel(@IntRange(from=0L,to=7L) int channel, boolean enable)
Enables or disables a light channel. Light channel 0 is enabled by default.- Parameters:
channel- Light channel to enable or disable, between 0 and 7.enable- Whether to enable or disable the light channel.
-
instances
@NonNull public RenderableManager.Builder instances(@IntRange(from=1L,to=65535L) int instanceCount)
Specifies the number of draw instance of this renderable. The default is 1 instance and the maximum number of instances allowed is 65535. 0 is invalid. All instances are culled using the same bounding box, so care must be taken to make sure all instances render inside the specified bounding box. The material can use getInstanceIndex() in the vertex shader to get the instance index and possibly adjust the position or transform.- Parameters:
instanceCount- the number of instances silently clamped between 1 and 65535.
-
castShadows
@NonNull public RenderableManager.Builder castShadows(boolean enabled)
Controls if this renderable casts shadows, false by default. If the View's shadow type is set toView.ShadowType.VSM, castShadows should only be disabled if either is true:RenderableManager.setReceiveShadows(int, boolean)is also disabled- the object is guaranteed to not cast shadows on itself or other objects (for example, a ground plane)
-
receiveShadows
@NonNull public RenderableManager.Builder receiveShadows(boolean enabled)
Controls if this renderable receives shadows, true by default.
-
screenSpaceContactShadows
@NonNull public RenderableManager.Builder screenSpaceContactShadows(boolean enabled)
Controls if this renderable uses screen-space contact shadows. This is more expensive but can improve the quality of shadows, especially in large scenes. (off by default).
-
enableSkinningBuffers
@NonNull public RenderableManager.Builder enableSkinningBuffers(boolean enabled)
Allows bones to be swapped out and shared using SkinningBuffer. If skinning buffer mode is enabled, clients must call #setSkinningBuffer() rather than #setBonesAsQuaternions(). This allows sharing of data between renderables.- Parameters:
enabled- If true, enables buffer object mode. False by default.
-
skinning
@NonNull public RenderableManager.Builder skinning(SkinningBuffer skinningBuffer, @IntRange(from=0L,to=255L) int boneCount, int offset)
Enables GPU vertex skinning for up to 255 bones, 0 by default.Skinning Buffer mode must be enabled.
Each vertex can be affected by up to 4 bones simultaneously. The attached VertexBuffer must provide data in the BONE_INDICES slot (uvec4) and the BONE_WEIGHTS slot (float4).
See also
RenderableManager.setSkinningBuffer(int, com.google.android.filament.SkinningBuffer, int, int),SkinningBuffer.setBonesAsMatrices(com.google.android.filament.Engine, java.nio.Buffer, int, int)orSkinningBuffer.setBonesAsQuaternions(com.google.android.filament.Engine, java.nio.Buffer, int, int), which can be called on a per-frame basis to advance the animation.- Parameters:
skinningBuffer- null to disable, otherwise theSkinningBufferto useboneCount- 0 to disable, otherwise the number of bone transforms (up to 255)offset- offset in theSkinningBuffer- Returns:
- this
Builderobject for chaining calls - See Also:
RenderableManager.setSkinningBuffer(int, com.google.android.filament.SkinningBuffer, int, int),SkinningBuffer.setBonesAsMatrices(com.google.android.filament.Engine, java.nio.Buffer, int, int),SkinningBuffer.setBonesAsQuaternions(com.google.android.filament.Engine, java.nio.Buffer, int, int)
-
skinning
@NonNull public RenderableManager.Builder skinning(@IntRange(from=0L,to=255L) int boneCount)
-
skinning
@NonNull public RenderableManager.Builder skinning(@IntRange(from=0L,to=255L) int boneCount, @NonNull java.nio.Buffer bones)
Enables GPU vertex skinning for up to 255 bones, 0 by default.Skinning Buffer mode must be disabled.
Each vertex can be affected by up to 4 bones simultaneously. The attached VertexBuffer must provide data in the
BONE_INDICESslot (uvec4) and theBONE_WEIGHTSslot (float4).See also
RenderableManager.setBonesAsMatrices(int, java.nio.Buffer, int, int), which can be called on a per-frame basis to advance the animation.- Parameters:
boneCount- Number of bones associated with this componentbones- A FloatBuffer containing boneCount transforms. Each transform consists of 8 float. float 0 to 3 encode a unit quaternion w+ix+jy+kz stored as x,y,z,w. float 4 to 7 encode a translation stored as x,y,z,1- See Also:
SkinningBuffer.setBonesAsMatrices(com.google.android.filament.Engine, java.nio.Buffer, int, int)
-
morphing
@NonNull public RenderableManager.Builder morphing(@IntRange(from=0L,to=255L) int targetCount)
Controls if the renderable has vertex morphing targets, zero by default. This is required to enable GPU morphing.Filament supports two morphing modes: standard (default) and legacy.
For standard morphing, A
For legacy morphing, the attachedMorphTargetBuffermust be created and provided viaRenderableManager.setMorphTargetBufferAt(int, int, int, com.google.android.filament.MorphTargetBuffer, int, int). Standard morphing supports up toCONFIG_MAX_MORPH_TARGET_COUNTmorph targets.VertexBuffermust provide data in the appropriateVertexBuffer.VertexAttributeslots (MORPH_POSITION_0etc). Legacy morphing only supports up to 4 morph targets and will be deprecated in the future. Legacy morphing must be enabled on the material definition: either via thelegacyMorphingmaterial attribute or by calling {@link MaterialBuilder::useLegacyMorphing}.See also
RenderableManager.setMorphWeights(int, float[], int), which can be called on a per-frame basis to advance the animation.
-
morphing
@NonNull public RenderableManager.Builder morphing(@IntRange(from=0L) int level, @IntRange(from=0L) int primitiveIndex, @NonNull MorphTargetBuffer morphTargetBuffer, @IntRange(from=0L) int offset, @IntRange(from=0L) int count)
Specifies the morph target buffer for a primitive. The morph target buffer must have an associated renderable and geometry. Two conditions must be met: 1. The number of morph targets in the buffer must equal the renderable's morph target count. 2. The vertex count of each morph target must equal the geometry's vertex count.- Parameters:
level- the level of detail (lod), only 0 can be specifiedprimitiveIndex- zero-based index of the primitive, must be less than the count passed to Builder constructormorphTargetBuffer- specifies the morph target bufferoffset- specifies where in the morph target buffer to start reading (expressed as a number of vertices)count- number of vertices in the morph target buffer to read, must equal the geometry's count (for triangles, this should be a multiple of 3)
-
morphing
@NonNull public RenderableManager.Builder morphing(@IntRange(from=0L) int level, @IntRange(from=0L) int primitiveIndex, @NonNull MorphTargetBuffer morphTargetBuffer)
Utility method to specify morph target buffer for a primitive. For details, see themorphing(int).
-
build
public void build(@NonNull Engine engine, int entity)Adds the Renderable component to an entity.If this component already exists on the given entity and the construction is successful, it is first destroyed as if
RenderableManager.destroy(int)was called.- Parameters:
engine- reference to theEngineto associate this renderable withentity- entity to add the renderable component to
-
-