Coder Social home page Coder Social logo

Comments (9)

ThomasGorisse avatar ThomasGorisse commented on June 18, 2024 2

The 1.18.8 release solves some Material issues and brings a Video Texture sample
Release 1.18.8 - Video Texture + SceneView Background

from sceneform-android.

aseemiboson avatar aseemiboson commented on June 18, 2024 1

@suryanadiminti99
give me your mail id will sent

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024 1

@aseemiboson Thankyou very much.

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024

@aseemiboson did you got any solution ?

from sceneform-android.

aseemiboson avatar aseemiboson commented on June 18, 2024

@suryanadiminti99
private fun loadVideo() {
runOnUiThread {
val uri = Uri.parse(arData!!.arContent[0].arProperty[2].propertyValue)
val player = MediaPlayer.create(this@MainActivity,uri)
val externalTexture = ExternalTexture()
player.setSurface(externalTexture.surface)
player.setAudioStreamType(AudioManager.STREAM_MUSIC)
player.setScreenOnWhilePlaying(true)
player.isLooping = true
//player.start();
Material.builder().setSource(this@MainActivity,R.raw.augmented_video_material).build().thenAccept { material: Material? ->
Log.d(TAG,"loadVideo: $uri")
val playerNode = Node()
Log.d(TAG,"loadVideo: Aspect Ratio = ${player.videoWidth}x${player.videoHeight}")
val gcd = gcd(player.videoWidth.toLong(),player.videoHeight.toLong())
val widthAspect = (player.videoWidth/gcd).toFloat()
val heightAspect = (player.videoHeight/gcd).toFloat()
val videoScreen = ShapeFactory.makeCube(Vector3(widthAspect,heightAspect,0.0001f),Vector3.zero(),material)
videoScreen.isShadowCaster = true
videoScreen.material.setExternalTexture("videoTexture",externalTexture)
// cube.material.setFloat3("keyColor",CHROMA_KEY_COLOR);
playerNode.renderable = videoScreen
// (playerNode.renderable as ModelRenderable).material.setFloat4("keyColor",CHROMA_KEY_COLOR);
val boundingBox = videoScreen.collisionShape as Box?
if (boundingBox != null) {
val boundingBoxSize = boundingBox.size
val maxExtent = Math.max(boundingBoxSize.x,Math.max(boundingBoxSize.y,boundingBoxSize.z))
val targetSize = 0.2f // Whatever size you want.
val scale = targetSize / maxExtent
val scaleVector3 = Vector3.one().scaled(scale)
playerNode.localScale = scaleVector3
Log.d(TAG,"loadVideo: Scale ${Vector3.one().scaled(scale).toString()}")
}
cube!!.addChild(playerNode)
player.start()
}
}
}

this is currently i am using but this is support in Scenceform 1.16.0 Official SDK, in this repo its crashing, to do chroma keying use croma keying material and put keyColor

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024

@aseemiboson will you please share your material file ? or can we use chromakey material ?

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024

@aseemiboson [email protected]

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024

@aseemiboson It's working in previous scene form module.

from sceneform-android.

suryanadiminti99 avatar suryanadiminti99 commented on June 18, 2024

@ThomasGorisse Hi , You really did a great job .

This is the code for android users to show video using cube.

`runOnUiThread(new Runnable() {
@OverRide
public void run() {
// Create Media Player
mediaPlayer = MediaPlayer.create(ArActivity.this,Uri.fromFile(new File(videoUrl)));
ExternalTexture externalTexture = new ExternalTexture();
mediaPlayer.setSurface(externalTexture.getSurface());
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setScreenOnWhilePlaying(true);
mediaPlayer.setLooping(true);

            Material.builder().setSource(ArActivity.this,R.raw.chroma_key_material).build().thenAccept(material -> {


            ModelRenderable renderable = ShapeFactory.makeCube(new Vector3(Float.parseFloat(scalex),0.0001f,Float.parseFloat(scaley)),Vector3.zero(),material);


            renderable.getMaterial().setExternalTexture("videoTexture", externalTexture);
            renderable.getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);

            AnchorNode anchorNode = new AnchorNode(anchor);

            // Create a node to render the video and add it to the anchor.
            Node videoNode = new Node();
            anchorNode.setParent(arFragment.getArSceneView().getScene());
            videoNode.setParent(anchorNode);

            // Vector3 vectorScale = new Vector3(Float.parseFloat(scalex), 0.0001f, Float.parseFloat(scaley));




            Vector3 vectorPos = new Vector3(Float.parseFloat(posx), Float.parseFloat(posy),(Float.parseFloat(posz)));

            Vector3 vectorScale = new Vector3(Float.parseFloat(scalex), Float.parseFloat(scaley),(Float.parseFloat(scalez)));



            Quaternion rx = Quaternion.eulerAngles(new Vector3(Float.parseFloat(rotatex), 0.0f, 0.0f));
            Quaternion ry = Quaternion.eulerAngles(new Vector3(0.0f, Float.parseFloat(rotatey), Float.parseFloat(rotatez)));



            // Set Scaling
            //  videoNode.setLocalScale(vectorScale);
            // Set Position
            videoNode.setLocalPosition(vectorPos);
            // Set Rotation
            videoNode.setLocalRotation(Quaternion.multiply(rx,ry));
            // Set Scaling values
            videoNode.setLocalScale(vectorScale);



            // Start playing the video when the first node is placed.
            if (!mediaPlayer.isPlaying()) {
                mediaPlayer.start();


                externalTexture.getSurfaceTexture().setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
                    @Override
                    public void onFrameAvailable(SurfaceTexture surfaceTexture) {
                        videoNode.setRenderable(renderable);
                        externalTexture.getSurfaceTexture().setOnFrameAvailableListener(null);
                    }
                });

            } else {
                videoNode.setRenderable(renderable);
            }


            });




        }
    });`

@ThomasGorisse Please look on this issue. Why it is not working in current repository .

from sceneform-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.