mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 02:24:04 -05:00
Merge pull request #295 from CesiumGS/double-sided-material
New optional parameter `doubleSidedMaterial` to force materials to be rendered on both sides
This commit is contained in:
commit
a26858a58e
@ -1,5 +1,9 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
### 3.2.0 - 2023-??-??
|
||||||
|
|
||||||
|
- Added `doubleSidedMaterial` option to force materials to be rendered double sided. [#294](https://github.com/CesiumGS/obj2gltf/pull/294)
|
||||||
|
|
||||||
### 3.1.6 - 2023-02-10
|
### 3.1.6 - 2023-02-10
|
||||||
|
|
||||||
- Update npm module dependencies.
|
- Update npm module dependencies.
|
||||||
|
@ -114,6 +114,7 @@ As a convenience the PBR textures may be supplied directly to the command line.
|
|||||||
| `--input-up-axis` | Up axis of the obj. | No |
|
| `--input-up-axis` | Up axis of the obj. | No |
|
||||||
| `--output-up-axis` | Up axis of the converted glTF. | No |
|
| `--output-up-axis` | Up axis of the converted glTF. | No |
|
||||||
| `--triangle-winding-order-sanitization` | Apply triangle winding order sanitization. | No |
|
| `--triangle-winding-order-sanitization` | Apply triangle winding order sanitization. | No |
|
||||||
|
| `--doubleSidedMaterial` | Allow the material properties to be double-sided | No, default `false` |
|
||||||
|
|
||||||
## Build Instructions
|
## Build Instructions
|
||||||
|
|
||||||
|
@ -160,6 +160,11 @@ const argv = yargs
|
|||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: defaults.triangleWindingOrderSanitization,
|
default: defaults.triangleWindingOrderSanitization,
|
||||||
},
|
},
|
||||||
|
doubleSidedMaterial: {
|
||||||
|
describe: "Allow the material properties to be double-sided",
|
||||||
|
type: "boolean",
|
||||||
|
default: defaults.doubleSidedMaterial,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.parse(args);
|
.parse(args);
|
||||||
|
|
||||||
@ -216,6 +221,7 @@ const options = {
|
|||||||
inputUpAxis: argv.inputUpAxis,
|
inputUpAxis: argv.inputUpAxis,
|
||||||
outputUpAxis: argv.outputUpAxis,
|
outputUpAxis: argv.outputUpAxis,
|
||||||
triangleWindingOrderSanitization: argv.triangleWindingOrderSanitization,
|
triangleWindingOrderSanitization: argv.triangleWindingOrderSanitization,
|
||||||
|
doubleSidedMaterial: argv.doubleSidedMaterial,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.time("Total");
|
console.time("Total");
|
||||||
|
@ -853,7 +853,7 @@ function createSpecularGlossinessMaterial(material, options) {
|
|||||||
transparent = transparent || diffuseTexture.transparent;
|
transparent = transparent || diffuseTexture.transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doubleSided = transparent;
|
const doubleSided = transparent || options.doubleSidedMaterial;
|
||||||
const alphaMode = transparent ? "BLEND" : "OPAQUE";
|
const alphaMode = transparent ? "BLEND" : "OPAQUE";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -934,7 +934,7 @@ function createMetallicRoughnessMaterial(material, options) {
|
|||||||
transparent = transparent || baseColorTexture.transparent;
|
transparent = transparent || baseColorTexture.transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doubleSided = transparent;
|
const doubleSided = transparent || options.doubleSidedMaterial;
|
||||||
const alphaMode = transparent ? "BLEND" : "OPAQUE";
|
const alphaMode = transparent ? "BLEND" : "OPAQUE";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -40,6 +40,7 @@ module.exports = obj2gltf;
|
|||||||
* @param {Logger} [options.logger] A callback function for handling logged messages. Defaults to console.log.
|
* @param {Logger} [options.logger] A callback function for handling logged messages. Defaults to console.log.
|
||||||
* @param {Writer} [options.writer] A callback function that writes files that are saved as separate resources.
|
* @param {Writer} [options.writer] A callback function that writes files that are saved as separate resources.
|
||||||
* @param {String} [options.outputDirectory] Output directory for writing separate resources when options.writer is not defined.
|
* @param {String} [options.outputDirectory] Output directory for writing separate resources when options.writer is not defined.
|
||||||
|
* @param {Boolean} [options.doubleSidedMaterial=false] Allows materials to be double sided.
|
||||||
* @return {Promise} A promise that resolves to the glTF JSON or glb buffer.
|
* @return {Promise} A promise that resolves to the glTF JSON or glb buffer.
|
||||||
*/
|
*/
|
||||||
function obj2gltf(objPath, options) {
|
function obj2gltf(objPath, options) {
|
||||||
@ -54,6 +55,10 @@ function obj2gltf(objPath, options) {
|
|||||||
options.checkTransparency,
|
options.checkTransparency,
|
||||||
defaults.checkTransparency
|
defaults.checkTransparency
|
||||||
);
|
);
|
||||||
|
options.doubleSidedMaterial = defaultValue(
|
||||||
|
options.doubleSidedMaterial,
|
||||||
|
defaults.doubleSidedMaterial
|
||||||
|
);
|
||||||
options.secure = defaultValue(options.secure, defaults.secure);
|
options.secure = defaultValue(options.secure, defaults.secure);
|
||||||
options.packOcclusion = defaultValue(
|
options.packOcclusion = defaultValue(
|
||||||
options.packOcclusion,
|
options.packOcclusion,
|
||||||
@ -179,6 +184,12 @@ obj2gltf.defaults = {
|
|||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
checkTransparency: false,
|
checkTransparency: false,
|
||||||
|
/**
|
||||||
|
* Gets and sets whether a material will be doubleSided or not
|
||||||
|
* @type Boolean
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
doubleSidedMaterial: false,
|
||||||
/**
|
/**
|
||||||
* Gets or sets whether the source model can reference paths outside of its directory.
|
* Gets or sets whether the source model can reference paths outside of its directory.
|
||||||
* @type Boolean
|
* @type Boolean
|
||||||
|
@ -406,6 +406,14 @@ describe("loadMtl", () => {
|
|||||||
expect(material.alphaMode).toBe("BLEND");
|
expect(material.alphaMode).toBe("BLEND");
|
||||||
expect(material.doubleSided).toBe(true);
|
expect(material.doubleSided).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses doubleSidedMaterial option", () => {
|
||||||
|
options.metallicRoughness = true;
|
||||||
|
options.doubleSidedMaterial = true;
|
||||||
|
|
||||||
|
const material = loadMtl._createMaterial(undefined, options);
|
||||||
|
expect(material.doubleSided).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("specularGlossiness", () => {
|
describe("specularGlossiness", () => {
|
||||||
@ -530,5 +538,13 @@ describe("loadMtl", () => {
|
|||||||
expect(material.alphaMode).toBe("BLEND");
|
expect(material.alphaMode).toBe("BLEND");
|
||||||
expect(material.doubleSided).toBe(true);
|
expect(material.doubleSided).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses doubleSidedMaterial option", () => {
|
||||||
|
options.specularGlossiness = true;
|
||||||
|
options.doubleSidedMaterial = true;
|
||||||
|
|
||||||
|
const material = loadMtl._createMaterial(undefined, options);
|
||||||
|
expect(material.doubleSided).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user