PNG Transparency #21
Treat materials with png texture automatically as transparent.
This commit is contained in:
parent
59ebed95bc
commit
3842e1afcf
2
source/external/rhino.importer.js
vendored
2
source/external/rhino.importer.js
vendored
@ -280,7 +280,7 @@ OV.Importer3dm = class extends OV.ImporterBase
|
||||
SetColor (material.diffuse, rhinoMaterial.diffuseColor);
|
||||
SetColor (material.specular, rhinoMaterial.specularColor);
|
||||
material.opacity = 1.0 - rhinoMaterial.transparency;
|
||||
material.transparent = OV.IsLower (material.opacity, 1.0);
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
// material.shininess = rhinoMaterial.shine / 255.0;
|
||||
if (IsBlack (material.diffuse) && !IsWhite (rhinoMaterial.reflectionColor)) {
|
||||
SetColor (material.diffuse, rhinoMaterial.reflectionColor);
|
||||
|
||||
@ -158,9 +158,10 @@ OV.Importer3ds = class extends OV.ImporterBase
|
||||
shininessStrength = obj.ReadPercentageChunk (reader, chunkLength);
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_TRANSPARENCY) {
|
||||
material.opacity = 1.0 - obj.ReadPercentageChunk (reader, chunkLength);
|
||||
material.transparent = OV.IsLower (material.opacity, 1.0);
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
} else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP) {
|
||||
material.diffuseMap = obj.ReadTextureMapChunk (reader, chunkLength);
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
} else {
|
||||
obj.SkipChunk (reader, chunkLength);
|
||||
}
|
||||
|
||||
@ -226,6 +226,7 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.diffuseMap = CreateTexture (keyword, line, this.callbacks);
|
||||
OV.UpdateMaterialTransparency (this.currentMaterial);
|
||||
return true;
|
||||
} else if (keyword === 'map_ks') {
|
||||
if (this.currentMaterial === null || parameters.length === 0) {
|
||||
@ -268,14 +269,14 @@ OV.ImporterObj = class extends OV.ImporterBase
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = 1.0 - parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
OV.UpdateMaterialTransparency (this.currentMaterial);
|
||||
return true;
|
||||
} else if (keyword === 'd') {
|
||||
if (this.currentMaterial === null || parameters.length < 1) {
|
||||
return true;
|
||||
}
|
||||
this.currentMaterial.opacity = parseFloat (parameters[0]);
|
||||
this.currentMaterial.transparent = OV.IsLower (this.currentMaterial.opacity, 1.0);
|
||||
OV.UpdateMaterialTransparency (this.currentMaterial);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -290,7 +290,7 @@ OV.ImporterPly = class extends OV.ImporterBase
|
||||
material.name = materialName;
|
||||
material.diffuse = new OV.Color (color[0], color[1], color[2]);
|
||||
material.opacity = color[3] / 255.0;
|
||||
material.transparent = OV.IsLower (material.opacity, 1.0);
|
||||
OV.UpdateMaterialTransparency (material);
|
||||
materialIndex = obj.model.AddMaterial (material);
|
||||
colorToMaterial[materialName] = materialIndex;
|
||||
}
|
||||
|
||||
@ -70,3 +70,16 @@ OV.ResizeImageToPowerOfTwoSides = function (image)
|
||||
context.drawImage (image, 0, 0, width, height);
|
||||
return context.getImageData (0, 0, width, height);
|
||||
};
|
||||
|
||||
OV.UpdateMaterialTransparency = function (material)
|
||||
{
|
||||
material.transparent = false;
|
||||
if (OV.IsLower (material.opacity, 1.0)) {
|
||||
material.transparent = true;
|
||||
} else if (material.diffuseMap !== null) {
|
||||
let extension = OV.GetFileExtension (material.diffuseMap.name);
|
||||
if (extension === 'png') {
|
||||
material.transparent = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user