How to add shadows to the model #584
Unanswered
playblindlythenchangecareers
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I tried adding shadows to the model as follows, but it had no effect. Is there something wrong with my approach?
`@Composable
fun Dial(dialViewModel: DialViewModel) {
Box {
val engine = rememberEngine()
val view = rememberView(engine)
val renderer = rememberRenderer(engine)
val modelLoader = rememberModelLoader(engine)
val materialLoader = rememberMaterialLoader(engine)
val environmentLoader = rememberEnvironmentLoader(engine)
val centerNode = rememberNode(engine)
val dialRootNode = rememberNode(engine)
val planeRootNode = rememberNode(engine)
val pointerRootNode = rememberNode(engine)
val cameraNode = rememberCameraNode(engine)
centerNode.addChildNode(cameraNode)
cameraNode.lookAt(centerNode)
cameraNode.position = Position(z = 2.9f)
dialRootNode.addChildNode(planeRootNode)
dialRootNode.addChildNode(pointerRootNode)
dialRootNode.position = Position(0f, -0.1f, 0f)
DialPlane(dialViewModel, modelLoader, planeRootNode)
DialPointer(dialViewModel, modelLoader, pointerRootNode)
Scene(
engine = engine,
view = view,
renderer = renderer,
environmentLoader = environmentLoader,
modelLoader = modelLoader,
mainLightNode = DefaultLightNode(engine),
cameraNode = cameraNode,
childNodes = listOf(centerNode, dialRootNode),
)
}
}
class DefaultLightNode(engine: Engine) : LightNode(
engine = engine,
type = LightManager.Type.SUN,
apply = {
color(255f, 255f, 0f)
intensity(100000f)
direction(0f, 20f, -5.0f)
castShadows(true)
})
@composable
fun DialPointer(dialViewModel: DialViewModel, modelLoader: ModelLoader, pointerRootNode: Node) {
LogUtils.d("")
removeChildNode(pointerRootNode, "dialPointer")
val dialPointer = ModelFactory.createModelNode(modelLoader, dialViewModel.dialPointer).apply {
isShadowCaster = true
isShadowReceiver = true
}
dialPointer.position = Position(0f, 0f, 0.28f)
dialPointer.name = "dialPointer"
pointerRootNode.addChildNode(dialPointer)
}
@composable
fun DialPlane(dialViewModel: DialViewModel, modelLoader: ModelLoader, planeRootNode: Node) {
LogUtils.d("")
removeChildNode(planeRootNode, "dialPlane")
val dialPlane = ModelFactory.createModelNode(modelLoader, dialViewModel.dialPlane).apply {
isShadowCaster = true
isShadowReceiver = true
}
dialPlane.name = "dialPlane"
planeRootNode.addChildNode(dialPlane)
}`
Beta Was this translation helpful? Give feedback.
All reactions