Skip to content

Commit 31dfd79

Browse files
authored
Merge pull request #249 from De-Panther/fix_webcam_errors
Fixed errors when trying to play webcam stream
2 parents 78c83e8 + b6a5bfa commit 31dfd79

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

Packages/webxr-interactions/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Fixed
1010
- No reference to controllers in SceneHitTest.
11+
- Errors when trying to play webcam stream.
1112

1213
## [0.16.0] - 2023-02-02
1314
### Added

Packages/webxr-interactions/Runtime/Plugins/WebGL/FixWebCamWebGL.jslib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var LibraryFixWebCamWebGL = {
6868
}
6969
GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[webcamBufferToTextureTable[buffer]]);
7070
GLctx.pixelStorei(GLctx.UNPACK_FLIP_Y_WEBGL, true);
71-
GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, videoElement);
71+
GLctx.texSubImage2D(GLctx.TEXTURE_2D, 0, 0, 0, GLctx.RGBA, GLctx.UNSIGNED_BYTE, videoElement);
7272
GLctx.pixelStorei(GLctx.UNPACK_FLIP_Y_WEBGL, false);
7373
disableNextSubImage = true;
7474
return 1;

Packages/webxr-interactions/Runtime/Scripts/PlayWebcam.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ public class PlayWebcam : MonoBehaviour
3535
private IntPtr latestWebcamPtr = IntPtr.Zero;
3636
private int lightingTexID = -1;
3737

38-
private int defaultWidth = 1280;
39-
private int defaultHeight = 720;
40-
4138
void Awake()
4239
{
4340
TrySetupRenderer();
@@ -86,18 +83,11 @@ void Play()
8683
if (webcamTexture == null)
8784
{
8885
var devices = WebCamTexture.devices;
89-
var device = devices[0];
90-
var resolutions = device.availableResolutions;
91-
if (resolutions?.Length > 0)
92-
{
93-
webcamTexture = new WebCamTexture(device.name, resolutions[0].width, resolutions[0].height, resolutions[0].refreshRate);
94-
}
95-
else
86+
if (devices == null || devices.Length == 0)
9687
{
97-
webcamTexture = new WebCamTexture(device.name, defaultWidth, defaultHeight);
88+
return;
9889
}
99-
float ratio = (float)defaultWidth / (float)defaultHeight;
100-
transform.localScale = new Vector3(ratio, 1f, 1f);
90+
webcamTexture = new WebCamTexture(devices[0].name);
10191
material.mainTexture = webcamTexture;
10292
}
10393
latestWebcamPtr = webcamTexture.GetNativeTexturePtr();

0 commit comments

Comments
 (0)