Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(cocos): a mesh whose converted material blends is imported as not opaque, so the engine draws it with blending: a fog that fades out was drawn black where it should have been clear

yhh04b4d3b28a1b
diff --git a/pipeline/src/import/cocos/components.ts b/pipeline/src/import/cocos/components.ts
index f0c629282..8451ede11 100644
--- a/pipeline/src/import/cocos/components.ts
+++ b/pipeline/src/import/cocos/components.ts
@@ -62,7 +62,8 @@ export interface ComponentContext {
/** What a Cocos material draws and how; null when the project has no such material. */
material?(uuid: string): MaterialInfo | null;
/** The Estella material a Cocos material of the project's own effect became (its shader converted), by its project path; null when the effect could not be converted. */
- convertedMaterial?(uuid: string): { ref: string } | null;
+ /** The converted material for a project material, and whether it blends (its effect's pass says so, which the material file does not). */
+ convertedMaterial?(uuid: string): { ref: string; blends?: boolean } | null;
/**
* The engine MeshRenderer data of the part of a model a Cocos mesh sub-asset names, once that model was brought in. `exact` is false when
* the part was picked because the model draws only one.
@@ -641,6 +642,8 @@ function applyMaterial(data: Raw, c: CocosComponent, ctx: ComponentContext, wher
if (info.color) data.color = info.color;
data.lit = !info.unlit;
data.opaque = !info.transparent;
+ // what the effect's pass blends is what the draw does: a mesh the engine takes for opaque is drawn without blending, and a fog that fades out would draw black
+ if (converted?.blends !== undefined) data.opaque = !converted.blends;
data.cullBackfaces = info.cullBack;
let exact = info.builtinEffect || converted !== null && converted !== undefined;
if (!exact) ctx.report.note('mesh-custom-effect', where);
diff --git a/pipeline/src/import/cocos/importProject.ts b/pipeline/src/import/cocos/importProject.ts
index e240378db..42b0bcf01 100644
--- a/pipeline/src/import/cocos/importProject.ts
+++ b/pipeline/src/import/cocos/importProject.ts
@@ -31,7 +31,7 @@ import { convertPass, isOutlinePass, type PassConversion } from './effectConvert
* importer that made less (or differently), and is brought up to date when it is opened. Raise it when the converted output changes in a
* way an existing project needs to pick up: a new generated file, a field a document or a manifest now carries.
*/
-export const COCOS_IMPORT_REVISION = 17;
+export const COCOS_IMPORT_REVISION = 18;
/** Whether the project at @p projectRoot was written by an importer of this revision. A project that was not converted has nothing to bring up. */
export function cocosImportIsCurrent(projectRoot: string): boolean {
@@ -692,7 +692,7 @@ export async function importCocosProject(opts: CocosImportOptions): Promise<Impo
type EffectTechnique = { name: string; passes: EffectPass[]; outline: boolean[] };
type ParsedEffect = { effect: CocosEffect; techniques: EffectTechnique[] };
const effects = new Map<string, ParsedEffect | null>();
- const convertedMaterials = new Map<string, { ref: string } | null>();
+ const convertedMaterials = new Map<string, { ref: string; blends?: boolean } | null>();
const effectOf = (entry: CocosAssetEntry): ParsedEffect | null => {
if (effects.has(entry.file)) return effects.get(entry.file) ?? null;
let result: ParsedEffect | null = null;
@@ -772,9 +772,9 @@ export async function importCocosProject(opts: CocosImportOptions): Promise<Impo
// what was converted before the check is converted again with its answer
shaders.clear();
};
- const convertedMaterial = (materialUuid: string): { ref: string } | null => {
+ const convertedMaterial = (materialUuid: string): { ref: string; blends?: boolean } | null => {
if (convertedMaterials.has(materialUuid)) return convertedMaterials.get(materialUuid) ?? null;
- let result: { ref: string } | null = null;
+ let result: { ref: string; blends?: boolean } | null = null;
try {
const mat = index.byUuid.get(materialUuid);
if (mat && mat.rel.endsWith('.mtl')) {
@@ -859,7 +859,7 @@ export async function importCocosProject(opts: CocosImportOptions): Promise<Impo
properties,
});
report.note('effect-converted', `${effectEntry.rel} (${technique.name})`);
- result = { ref: materialRel };
+ result = { ref: materialRel, blends: blendMode !== 9 };
}
}
}