Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AR object is completely black #476

Open
Shubi-khanduri opened this issue Sep 24, 2024 · 0 comments
Open

AR object is completely black #476

Shubi-khanduri opened this issue Sep 24, 2024 · 0 comments

Comments

@Shubi-khanduri
Copy link

Shubi-khanduri commented Sep 24, 2024

I am rendering .glb file in my app. I am getting .glb file from the local storage of mobile objects color is completely black IDK what is happening. but when I am getting the same file from asset in Android studio it is working perfectly fine all the colour of object are showing perfectly even if I am getting the year object from URL it is working fine here is but I am doing please help me with this.
@ThomasGorisse, or someone else, do you know, how can I fix that? Is it possible?
sceneView = findViewById<ARSceneView?>(R.id.
sceneView
).
apply
{
lifecycle = [email protected]
planeRenderer.isEnabled = true
configureSession { session, config ->
config.
depthMode
= when (session.isDepthModeSupported(Config.DepthMode.
AUTOMATIC
)) {
true -> Config.DepthMode.
AUTOMATIC

else -> Config.DepthMode.
DISABLED

}
config.
instantPlacementMode
= Config.InstantPlacementMode.
DISABLED

config.
lightEstimationMode
= Config.LightEstimationMode.
ENVIRONMENTAL_HDR

}
onSessionUpdated = { _, frame ->
if (anchorNode == null) {
frame.
getUpdatedPlanes
()
.
firstOrNull
{ it.
type
== Plane.Type.
HORIZONTAL_UPWARD_FACING
}
?.
let
{ plane ->
addAnchorNode(plane.createAnchor(plane.
centerPose
))
}
}
}
onTrackingFailureChanged = { reason ->
[email protected] = reason
}
}

fun addAnchorNode(anchor: Anchor, uri: Uri) {
    if (selectedFile == null) {
        Log.e("ARActivity", "Failed to copy file")
        return
    }
    Log.e("FileCheck", "File loading...")
    sceneView.addChildNode(
        AnchorNode(sceneView.engine, anchor)
            .apply {
                isEditable = true
                lifecycleScope.launch {
                    isLoading = true
                    buildModelNode1(selectedFile)?.let { addChildNode(it) }

// buildModelNode()?.let { addChildNode(it) }
isLoading = false
}
anchorNode = this
}
)
}

fun addAnchorNode(anchor: Anchor) {

    sceneView.addChildNode(
        AnchorNode(sceneView.engine, anchor)
            .

apply
{
isEditable = true

lifecycleScope
.
launch
{
isLoading = true
buildModelNode()?.
let
{ addChildNode(it) }
// buildViewNode()?.let { addChildNode(it) }
isLoading = false
}
anchorNode = this
}
)
}

fun buildModelNode1(file: File?): ModelNode? {
// val file = File(cacheDir, "DamagedHelmet.glb")
if (file == null) {
Log.e("FileCheck", "File does not exist: ")
return null
}
Log.d("FileCheck", "File exists: ${file.
absolutePath
}")
sceneView.modelLoader.createModelInstance(file = file).
let
{ model ->
return ModelNode(
modelInstance = model,
// Scale to fit in a 0.5 meters cube
scaleToUnits = 0.5f,
// Bottom origin instead of center so the model base is on floor
// centerOrigin = Position(y = -0.5f)
centerOrigin = Position(x = 0.0f, y = -1.0f, z = 0.0f)
).
apply
{
isEditable = true
}
}
}

WhatsApp Image 2024-09-24 at 7 21 40 PM
WhatsApp Image 2024-09-24 at 7 21 57 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant