How can I use this without the camera feed? #307
-
A newbie here, asking for a university project, I want the ar to happen with no camera feed.. exactly like in the demo app Ar Environment Lights, when the skybox is set to color. |
Beta Was this translation helpful? Give feedback.
Answered by
ThomasGorisse
Feb 10, 2022
Replies: 1 comment
-
Hi, So here how it is implemented inside AR Environment Lights app: data class APIEnvironment(
val name: String,
val ktxIblUrl: String? = null,
val ktxSkyboxUrl: String? = null,
val hdrUrl: String? = null,
val fromServer: Boolean = true
) {
private var environment: Environment? = null
suspend fun loadEnvironment(context: Context) = environment
?: withContext(Dispatchers.IO) {
when {
ktxIblUrl != null -> KTXLoader.loadEnvironment(
context,
ktxIblUrl.absoluteUrl,
ktxSkyboxUrl?.absoluteUrl
)
hdrUrl != null -> HDRLoader.loadEnvironment(context, hdrUrl.absoluteUrl)
else -> null
}?.also { environment = it }
}
private val String.absoluteUrl
get() = takeIf { it.isAbsolute } ?: "$serverUrl/$environmentsPath/$this"
}
var environment: APIEnvironment? = null
set(value) {
if (field != value) {
field = value
if (value != null) {
isLoadingEnvironment = true
lifecycleScope.launch {
sceneView.environment = value.loadEnvironment(this@MainActivity)
isLoadingEnvironment = false
}
}
}
}
fun onEstimationModeChanged(button: CompoundButton?, checked: Boolean) {
if (checked) {
button?.id?.let { estimationMode ->
sceneView.lightEstimationConfig = LightEstimationConfig(
mode = when (estimationMode) {
R.id.environmentalHdrMode,
R.id.environmentalHdrNoReflections,
R.id.environmentalHdrNoSpecularFilter -> {
Config.LightEstimationMode.ENVIRONMENTAL_HDR
}
R.id.ambientIntensityMode -> Config.LightEstimationMode.AMBIENT_INTENSITY
else -> Config.LightEstimationMode.DISABLED
},
environmentalHdrReflections = estimationMode != R.id.environmentalHdrNoReflections,
environmentalHdrSpecularFilter = estimationMode != R.id.environmentalHdrNoSpecularFilter
)
}
}
}
fun onSkyboxModeChanged(button: CompoundButton?, checked: Boolean) {
if (checked) {
val skyboxMode = button!!.id
if (this.skyboxMode != skyboxMode) {
when (skyboxMode) {
R.id.cameraSkybox -> {
sceneView.renderer?.setSkybox(null)
sceneView.renderer?.addEntity(sceneView.cameraStream.cameraStreamRenderable)
scene.removeOnUpdateListener(::doSkyboxFrameUpdate)
}
R.id.reflectionsSkybox,
R.id.colorSkybox -> {
if (this.skyboxMode == R.id.cameraSkybox) {
sceneView.renderer?.removeEntity(sceneView.cameraStream.cameraStreamRenderable)
sceneView.scene.addOnUpdateListener(::doSkyboxFrameUpdate)
}
}
}
}
this.skyboxMode = skyboxMode
}
}
fun doSkyboxFrameUpdate(frameTime: FrameTime) {
sceneView.renderer?.setSkybox(
Skybox.Builder().apply {
when (skyboxMode) {
R.id.reflectionsSkybox -> {
val environment = sceneView.estimatedEnvironmentLights?.environment
?: sceneView.environment
environment?.indirectLight?.reflectionsTexture?.let { environment(it) }
}
R.id.colorSkybox -> {
val mainLight = sceneView.estimatedEnvironmentLights?.mainLight
?: sceneView.mainLight
mainLight?.color?.let { color(it.toFloatArray()) }
}
}
}.build()
)
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bileldeb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Sorry for the late answer. If you are still interested on that subject, I can help you in exchange of some screen records of your app shared in here.
This is a very interesting subject and I really think that the usages of this behavior are awesome.
So here how it is implemented inside AR Environment Lights app: