[SOLVED] Change Video Texture material

Software: Away3D 4.x

Beek, Member
Posted: 04 March 2016 07:16 PM   Total Posts: 67

Hi,

I’m making a VR video player and trying to swap out the video on the sphere without a few seconds of black screen while the new video loads. My plan has been to load a dummy mesh with the texture and swap them out, ,then dispose of the dummy mesh. Unfortunately I can’t seem to dispose of the previous videos, cos after a few videos I’m getting a massive slow down and lots of resource errors - and this is on desktop so I hate to think what’s going to happen on mobile.

This is my current working code:

private function updateVideoSphere():void
  {
   
   
//if(_currentScene)
    //clearCurrentScene();
   
if(!panoVideoMesh){
    trace
("CREATING INTIAL VIDEO");
    
sphereGeometry = new SphereGeometry(50006448);
    
texture2DBase = new NativeVideoTexture(Model.config.getAssetUrl(Model.currentScene.video), truetrue);
    
texture2DBase.player.play();
    
texture2DBase.addEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
    
textureMaterial = new TextureMaterial(texture2DBasefalsefalsefalse);
    
panoVideoMesh = new Mesh(sphereGeometrytextureMaterial);
    
panoVideoMesh.scaleX *= -1;
    
    
panoVideoMesh.rotate(Vector3D.Y_AXIS,-90);
    
    
cameraController = new HoverController(camera);
    
ready true;
    
scene.addChild(panoVideoMesh);
   
}
   
else
   
{
    trace
("REPLACING VIDEO");
    
//texture2DBase.player.pause();
    
texture2DBaseNext = new NativeVideoTexture(Model.config.getAssetUrl(Model.currentScene.video), truetrue);
    
texture2DBaseNext.addEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
    
textureMaterialNext = new TextureMaterial(texture2DBaseNextfalsefalsefalse);
    
panoVideoMeshNext = new Mesh(sphereGeometrytextureMaterialNext);

    
scene.addChild(panoVideoMeshNext);
    
//panoVideoMeshNext.visible = false;
   
}
  }
  
  
private function onVideoStart(e:Event):void{

   
if(panoVideoMeshNext){
    ready 
false;
    
TextureMaterial(panoVideoMesh.material).texture texture2DBaseNext;
    
texture2DBaseNext.removeEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
    
scene.removeChild(panoVideoMeshNext);
    
panoVideoMeshNext.dispose();
    
//textureMaterialNext.dispose();
    //texture2DBaseNext.dispose();
    
ready true;
    
    if(
texture2DBase){
     texture2DBase
.dispose();
     
texture2DBase null;
    
}
    
   }
   
else
    
texture2DBase.removeEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);

   
   
  

And it kind of works, I just can’t see how to properly dispose of the video after the change without destroying the current video.

Any clues gratefully received.

   

Beek, Member
Posted: 04 March 2016 07:29 PM   Total Posts: 67   [ # 1 ]

EDIT:

This worked

  var currentMaterial:TextureMaterial = panoVideoMesh.material as TextureMaterial;
  var currentTexture:NativeVideoTexture = currentMaterial.texture as NativeVideoTexture;

 
  TextureMaterial(panoVideoMesh.material).texture = texture2DBaseNext;
  texture2DBaseNext.removeEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
  scene.removeChild(panoVideoMeshNext);
  panoVideoMeshNext.dispose();
 
  currentTexture.dispose();

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X