Closed aseemiboson closed 3 years ago
@aseemiboson did you got any solution ?
@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
@aseemiboson will you please share your material file ? or can we use chromakey material ?
@suryanadiminti99 give me your mail id will sent
@aseemiboson suryanadiminti99@gmail.com
@aseemiboson Thankyou very much.
@aseemiboson It's working in previous scene form module.
@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 .
The 1.18.8 release solves some Material issues and brings a Video Texture sample Release 1.18.8 - Video Texture + SceneView Background
Could you please give me an example of video rendering