Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error in node environment #2362

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/SystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export class SystemInfo {
static platform: Platform = Platform.Unknown;
/** The operating system is running on. */
static operatingSystem: string = "";

/** @internal */
static _isBrowser = true;

/** Whether the system support SIMD. */
private static _simdSupported: boolean | null = null;

Expand All @@ -24,6 +28,7 @@ export class SystemInfo {
static _initialize(): void {
{
if (typeof navigator == "undefined") {
SystemInfo._isBrowser = false;
return;
}

Expand Down
13 changes: 9 additions & 4 deletions packages/loader/src/gltf/extensions/EXT_texture_webp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Texture2D } from "@galacean/engine-core";
import { SystemInfo, Texture2D } from "@galacean/engine-core";
import type { ITexture } from "../GLTFSchema";
import { registerGLTFExtension } from "../parser/GLTFParser";
import { GLTFParserContext } from "../parser/GLTFParserContext";
Expand All @@ -15,10 +15,15 @@ class EXT_texture_webp extends GLTFExtensionParser {

constructor() {
super();
const testCanvas = document.createElement("canvas");

testCanvas.width = testCanvas.height = 1;
this._supportWebP = testCanvas.toDataURL("image/webp").indexOf("data:image/webp") == 0;
// @ts-ignore
if (SystemInfo._isBrowser) {
const testCanvas = document.createElement("canvas");
testCanvas.width = testCanvas.height = 1;
this._supportWebP = testCanvas.toDataURL("image/webp").indexOf("data:image/webp") == 0;
} else {
this._supportWebP = false;
}
}

override async createAndParse(
Expand Down
Loading