Entity.create(
listOf(
Mesh(Uri.parse("mesh://box")),
Material().apply {
baseColor = Color4(red = 0.2f, green = 0.8f, blue = 0.4f, alpha = 1.0f)
},
Box(Vector3(0.25f)),
Transform(Pose(Vector3(0.0f, 0.0f, 0.0f))),
))
class Material(repeatU: Float = 1.0f, repeatV: Float = 1.0f, offsetU: Float = 0.0f, offsetV: Float = 0.0f, baseColor: Color4 = Color4(0.5f, 0.5f, 0.5f, 1.0f), metallicInternal: Float = 0.0f, roughnessInternal: Float = 0.3f, unlit: Boolean = false, alphaMode: Int = com.meta.spatial.runtime.AlphaMode.OPAQUE.ordinal, shader: String = "", baseTextureAndroidResourceId: Int = 0, baseTextureScale: Float = 1.0f) : ComponentBase
Material
(
repeatU
, repeatV
, offsetU
, offsetV
, baseColor
, metallicInternal
, roughnessInternal
, unlit
, alphaMode
, shader
, baseTextureAndroidResourceId
, baseTextureScale
)
|
Signature
constructor(repeatU: Float = 1.0f, repeatV: Float = 1.0f, offsetU: Float = 0.0f, offsetV: Float = 0.0f, baseColor: Color4 = Color4(0.5f, 0.5f, 0.5f, 1.0f), metallicInternal: Float = 0.0f, roughnessInternal: Float = 0.3f, unlit: Boolean = false, alphaMode: Int = com.meta.spatial.runtime.AlphaMode.OPAQUE.ordinal, shader: String = "", baseTextureAndroidResourceId: Int = 0, baseTextureScale: Float = 1.0f) Parameters
repeatU:
Float
repeatV:
Float
offsetU:
Float
offsetV:
Float
baseColor:
Color4
metallicInternal:
Float
roughnessInternal:
Float
unlit:
Boolean
alphaMode:
Int
shader:
String
baseTextureAndroidResourceId:
Int
baseTextureScale:
Float
Returns |
alphaMode
: Int
[Get][Set] |
alpha mode of the material
Signature
var alphaMode: Int |
baseColor
: Color4
[Get][Set] |
: base color of the material
Signature
var baseColor: Color4 |
baseTextureAndroidResourceId
: Int
[Get][Set] |
base texture of the material
Signature
var baseTextureAndroidResourceId: Int |
baseTextureScale
: Float
[Get][Set] |
scale factor for the base texture (1.0 = original size, 0.5 = half size)
Signature
var baseTextureScale: Float |
cachable
: BuildConfig.COMPONENTCACHE_LEVEL >= 1
[Get][Set] |
Signature
open override var cachable: BuildConfig.COMPONENTCACHE_LEVEL >= 1 |
entID
: Long
[Get][Set] |
Signature
var entID: Long |
isDirty
: Boolean
[Get][Set] |
Signature
var isDirty: Boolean |
metallic
: Float
[Get][Set] |
: metallic of the material
Signature
var metallic: Float |
metallicInternal
: Float
[Get][Set] |
metallic of the material
Signature
var metallicInternal: Float |
offsetU
: Float
[Get][Set] |
offset u of the material
Signature
var offsetU: Float |
offsetV
: Float
[Get][Set] |
offset v of the material
Signature
var offsetV: Float |
recycled
: Boolean
[Get][Set] |
Signature
var recycled: Boolean |
repeatU
: Float
[Get][Set] |
repeat u of the material
Signature
var repeatU: Float |
repeatV
: Float
[Get][Set] |
repeat v of the material
Signature
var repeatV: Float |
roughness
: Float
[Get][Set] |
: roughness of the material
Signature
var roughness: Float |
roughnessInternal
: Float
[Get][Set] |
roughness of the material
Signature
var roughnessInternal: Float |
shader
: String
[Get][Set] |
shader of the material
Signature
var shader: String |
timeStamp
: Long
[Get][Set] |
Signature
var timeStamp: Long |
unlit
: Boolean
[Get][Set] |
whether the material is unlit
Signature
var unlit: Boolean |
companion
()
|
Gets the companion object for this component.
The companion object provides metadata about the component.
Signature
open override fun companion(): ComponentCompanion Throws
RuntimeException
|
generateSceneMaterial
(
entity
, ctx
)
|
Signature
fun generateSceneMaterial(entity: Entity, ctx: Context): SceneMaterial Parameters
entity:
Entity
ctx:
Context
Returns |
getComponentDataAttributeType
(
key
)
|
Gets the attribute type for the specified key.
Signature
fun getComponentDataAttributeType(key: Int): AttributePrimitive? Parameters
key:
Int
|
getComponentDataAttributeType
(
keyString
)
|
Gets the attribute type for the specified string key.
Signature
fun getComponentDataAttributeType(keyString: String): AttributePrimitive? Parameters
keyString:
String
Throws
IllegalArgumentException
|
getComponentDataKey
(
key
)
|
Gets the integer key associated with the specified string key.
Signature
fun getComponentDataKey(key: String): Int? Parameters
key:
String
Returns
Int?
|
getComponentDataValue
(
key
)
|
Gets the value for the specified key.
Signature
fun getComponentDataValue(key: Int): Any? Parameters
key:
Int
Returns
Any?
|
getComponentDataValue
(
keyString
)
|
Gets the value for the specified string key.
Signature
fun getComponentDataValue(keyString: String): Any? Parameters
keyString:
String
Returns
Any?
Throws
IllegalArgumentException
|
getEnumClass
(
key
)
|
Gets the enum class associated with the specified string key.
Signature
fun getEnumClass(key: String): Class<out Enum<*>>? Parameters
key:
String
Returns
Class?
|
hasComponentData
(
key
)
|
Checks if this component has data for the specified key.
Signature
fun hasComponentData(key: Int): Boolean Parameters
key:
Int
Returns
Boolean
|
hasComponentData
(
keyString
)
|
Checks if this component has data for the specified string key.
Signature
fun hasComponentData(keyString: String): Boolean Parameters
keyString:
String
Returns
Boolean
|
read
(
e
, cachable
)
|
Reads component data from the specified entity.
Signature
fun read(e: Entity, cachable: Boolean) Parameters
cachable:
Boolean
|
recycle
()
|
Recycles this component by returning it to its pool.
If the component has a pool assigned, it will be returned to that pool for reuse.
Signature
fun recycle() |
reset
()
|
Resets the component to its default state.
This method is called when a component is recycled to clear any state. Subclasses should override this method to reset their specific state.
Signature
open fun reset() |
setComponentDataValue
(
key
, value
)
|
Sets the value for the specified key.
Signature
fun setComponentDataValue(key: Int, value: Any): Boolean Parameters
key:
Int
value:
Any
Returns
Boolean
|
setComponentDataValue
(
keyString
, value
)
|
Sets the value for the specified string key.
Signature
fun setComponentDataValue(keyString: String, value: Any): Boolean Parameters
keyString:
String
value:
Any
Returns
Boolean
|
setPool
(
pool
, entID
)
|
Sets the component pool and entity ID for this component.
This is used for component recycling to track which pool the component belongs to and which entity it was associated with.
Signature
fun setPool(pool: ComponentPool<*>, entID: Long) Parameters
pool:
ComponentPool
entID:
Long
|
toString
()
|
Signature
open override fun toString(): String Returns
String
|
typeID
()
|
Returns the unique type ID of this component.
Each component type must have a unique ID for identification in the entity-component system.
Signature
open override fun typeID(): Int Returns
Int
|
write
(
e
)
|
Writes this component's data to the specified entity.
Signature
fun write(e: Entity) Parameters |
alphaModeData
: IntAttributeData
[Get] |
Signature
val alphaModeData: IntAttributeData |
alphaModeId
[Get] |
Signature
val alphaModeId: |
attributeKeys_
: IntArray
[Get] |
Signature
val attributeKeys_: IntArray |
attributeTypeCounts_
: IntArray
[Get] |
Signature
val attributeTypeCounts_: IntArray |
attributeTypes_
: IntArray
[Get] |
Signature
val attributeTypes_: IntArray |
attrMetaData_
: Map
[Get] |
Signature
val attrMetaData_: Map |
baseColorData
: Color4AttributeData
[Get] |
Signature
val baseColorData: Color4AttributeData |
baseColorId
[Get] |
Signature
val baseColorId: |
baseTextureAndroidResourceIdData
: IntAttributeData
[Get] |
Signature
val baseTextureAndroidResourceIdData: IntAttributeData |
baseTextureAndroidResourceIdId
[Get] |
Signature
val baseTextureAndroidResourceIdId: |
baseTextureScaleData
: FloatAttributeData
[Get] |
Signature
val baseTextureScaleData: FloatAttributeData |
baseTextureScaleId
[Get] |
Signature
val baseTextureScaleId: |
createDefaultInstance
: Function0
[Get] |
Signature
open override val createDefaultInstance: () -> Material |
enumClassesMap_
: Map
[Get] |
Signature
val enumClassesMap_: Map<Int, Class<out Enum<*>>> |
id
[Get] |
Signature
open override val id: |
keyStringToKeyIntMap_
: Map
[Get] |
Signature
val keyStringToKeyIntMap_: Map<String, Int> |
metallicInternalData
: FloatAttributeData
[Get] |
Signature
val metallicInternalData: FloatAttributeData |
metallicInternalId
[Get] |
Signature
val metallicInternalId: |
offsetUData
: FloatAttributeData
[Get] |
Signature
val offsetUData: FloatAttributeData |
offsetUId
[Get] |
Signature
val offsetUId: |
offsetVData
: FloatAttributeData
[Get] |
Signature
val offsetVData: FloatAttributeData |
offsetVId
[Get] |
Signature
val offsetVId: |
repeatUData
: FloatAttributeData
[Get] |
Signature
val repeatUData: FloatAttributeData |
repeatUId
[Get] |
Signature
val repeatUId: |
repeatVData
: FloatAttributeData
[Get] |
Signature
val repeatVData: FloatAttributeData |
repeatVId
[Get] |
Signature
val repeatVId: |
roughnessInternalData
: FloatAttributeData
[Get] |
Signature
val roughnessInternalData: FloatAttributeData |
roughnessInternalId
[Get] |
Signature
val roughnessInternalId: |
shaderData
: StringAttributeData
[Get] |
Signature
val shaderData: StringAttributeData |
shaderId
[Get] |
Signature
val shaderId: |
unlitData
: BooleanAttributeData
[Get] |
Signature
val unlitData: BooleanAttributeData |
unlitId
[Get] |
Signature
val unlitId: |
attributeKeys
()
|
Signature
open override fun attributeKeys(): IntArray Returns
IntArray
|
attributeMetaData
()
| Returns
Map
|
attributeTypeCountAvailable
()
|
Signature
open override fun attributeTypeCountAvailable(): Boolean Returns
Boolean
|
attributeTypeCounts
()
|
Signature
open override fun attributeTypeCounts(): IntArray Returns
IntArray
|
attributeTypes
()
|
Signature
open override fun attributeTypes(): IntArray Returns
IntArray
|
dependents
()
|
Signature
open override fun dependents(): IntArray Returns
IntArray
|
enumClassesMap
()
|
Signature
open override fun enumClassesMap(): Map<Int, Class<out Enum<*>>> Returns
Map
|
keyStringToKeyIntMap
(
keyString
)
|
Signature
open override fun keyStringToKeyIntMap(keyString: String): Int? Parameters
keyString:
String
Returns
Int?
|
registerSceneTexture
(
key
, texture
)
|
Registers a SceneTexture in the material cache with a custom key.
This allows apps to insert dynamic or pre-processed textures (such as rendered text, converted ShapeDrawables, or procedurally generated images) into the cache so they can be used with the Material component via Material.baseTextureAndroidResourceId.
The key should be a unique identifier, typically an Android resource ID or a unique hash. When Material.generateSceneMaterial is called with a matching Material.baseTextureAndroidResourceId, it will find the texture in this cache.
Example:
val bitmap = renderTextToBitmap("Hello World")
val texture = SceneTexture(bitmap)
Material.registerSceneTexture(myUniqueId, texture)
Entity.create(listOf(
Transform(Pose(position)),
Mesh(Uri.parse("mesh://quad")),
Quad(Vector2(-0.1f, -0.025f), Vector2(0.1f, 0.025f)),
Material().apply { baseTextureAndroidResourceId = myUniqueId }
))
Signature
fun registerSceneTexture(key: Int, texture: SceneTexture) Parameters
key:
Int
|