Hello,
Can someone explain me how to correctly scale the video to fit in the detected imagetarget.
My image target and the video have the same ratio.
I have the following code but my video is "cropped". I mean I see only a part of the video (as it was zoomed in).
I don't understand how I can correctly dislpay my video inside the detected image target
Note:
the image is 640x360
the video is: 640x360
Thanks a lot for your help !!
public class EasyArMagTarget : MonoBehaviour
{
void CreateTarget(string targetName, out SampleImageTargetBehaviour targetBehaviour)
{
GameObject Target = new GameObject(targetName);
Target.transform.localPosition = Vector3.zero;
targetBehaviour = Target.AddComponent<SampleImageTargetBehaviour>();
}
void Start()
{
SampleImageTargetBehaviour targetBehaviour;
ImageTrackerBehaviour tracker = FindObjectOfType<ImageTrackerBehaviour>();
// dynamically load all targets from json file
var targetList = ImageTargetBaseBehaviour.LoadListFromJsonFile("images_targets.json", StorageType.Assets);
foreach (var target in targetList.Where(t => t.IsValid).OfType<ImageTarget>())
{
CreateTarget(target.Name, out targetBehaviour);
targetBehaviour.Bind(tracker);
targetBehaviour.SetupWithTarget(target);
targetBehaviour.Size = new Vector2(target.Size.x, target.Size.y);
float ratio = target.Size.x / target.Size.y;
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.localScale = new Vector3(1f, 1f, 1f/ratio);
plane.transform.parent = targetBehaviour.gameObject.transform;
VideoPlayerBehaviour playerBehavior = plane.AddComponent<VideoPlayerBehaviour>();
playerBehavior.transform.localScale = new Vector3(1f, 1f, 1f / ratio);
playerBehavior.Path = "myvideo.mp4";
playerBehavior.EnableAutoPlay = true;
playerBehavior.EnableLoop = true;
playerBehavior.OpenWhenStart = true;
playerBehavior.DisplayTextMessage = true;
playerBehavior.Storage = StorageType.Assets;
playerBehavior.Type = VideoPlayerBaseBehaviour.VideoType.TransparentSideBySide;
playerBehavior.VideoScaleMode = VideoPlayerBaseBehaviour.ScaleMode.Fill;
playerBehavior.VideoScalePlane = VideoPlayerBaseBehaviour.ScalePlane.XZ;
playerBehavior.VideoScaleFactorBase = 0.02f;
}
targetBehaviour = null;
}
}