Skip to content

Commit

Permalink
fix(asset): convert: now not create default material
Browse files Browse the repository at this point in the history
  • Loading branch information
yyc-git committed Mar 4, 2019
1 parent aa06435 commit 3fed95d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 72 deletions.
13 changes: 5 additions & 8 deletions src/asset/assemble/BatchOperateWholeSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ let _getBufferData =
byteStride |> OptionService.isJsonSerializedValueNone ?
assertPass() :
byteStride
|>
OptionService.unsafeGetJsonSerializedValue == BufferUtils.getAccessorTypeSize(
accessor.
type_,
)
|> OptionService.unsafeGetJsonSerializedValue
== BufferUtils.getAccessorTypeSize(accessor.type_)
* bytes_per_element;
},
)
Expand Down Expand Up @@ -90,13 +87,13 @@ let _getBufferIndex16Data = (componentType, accessorIndex, dataViewArr, wd) =>
)
|> Obj.magic,
)
|. Some
->Some
| UNSIGNED_SHORT =>
_getBufferPointData(
(accessorIndex, Uint16Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint16Array.fromBufferRange,
)
|. Some
->Some
| _ => None
};

Expand All @@ -107,7 +104,7 @@ let _getBufferIndex32Data = (componentType, accessorIndex, dataViewArr, wd) =>
(accessorIndex, Uint32Array._BYTES_PER_ELEMENT, dataViewArr, wd),
Uint32Array.fromBufferRange,
)
|. Some
->Some
| _ => None
};

Expand Down
7 changes: 3 additions & 4 deletions src/asset/converter/ConvertGLBSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ let _checkAndWarn = (({meshes}: GLTFType.gltf) as gltf) => {
let _buildWDBJsonUint8Array = (gltf: GLTFType.gltf) => {
let gltf = _checkAndWarn(gltf);
let ({asset, scenes, scene, nodes, extensions}: GLTFType.gltf) as gltf =
gltf
|> ConvertMultiPrimitivesSystem.convertMultiPrimitivesToNodes
|> ConvertDefaultMaterialSystem.convert;
gltf |> ConvertMultiPrimitivesSystem.convertMultiPrimitivesToNodes;
/* |> ConvertDefaultMaterialSystem.convert; */

let transforms = ConvertTransformsSystem.convertToTransforms(gltf);

Expand Down Expand Up @@ -130,7 +129,7 @@ let _getEmptyEncodedUint8Data = () => {
TypeArrayService.getUint8_1(0, emptyUint8DataArr);
};

let _convertGLBToWDB = (gltf: GLTFType.gltf, binBuffer) : ArrayBuffer.t => {
let _convertGLBToWDB = (gltf: GLTFType.gltf, binBuffer): ArrayBuffer.t => {
let (bufferViewDataArr, streamChunkArr, jsonUint8Array) =
_buildWDBJsonUint8Array(gltf);

Expand Down
18 changes: 13 additions & 5 deletions src/asset/converter/ConvertMaterialsSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ let _convertColor = colorFactor =>
};

let convertToBasicMaterials =
({extras}: GLTFType.gltf)
: array(WDType.basicMaterial) =>
({extras}: GLTFType.gltf): array(WDType.basicMaterial) =>
switch (extras) {
| None => [||]
| Some({basicMaterials}) =>
Expand Down Expand Up @@ -53,14 +52,23 @@ let _convertPBRData = (name, diffuseColorFactor, arr, index) =>

let _convertMetallicRoughness = (name, pbrMetallicRoughness, arr, index) =>
switch (pbrMetallicRoughness) {
| None => arr
| None =>
/* arr */
WonderLog.Log.fatal(
WonderLog.Log.buildFatalMessage(
~title="_convertMetallicRoughness",
~description={j|pbrMetallicRoughness shouldn't be None|j},
~reason="",
~solution={j||j},
~params={j||j},
),
)
| Some(({baseColorFactor}: GLTFType.pbrMetallicRoughness)) =>
_convertPBRData(name, baseColorFactor, arr, index)
};

let convertToLightMaterials =
({materials}: GLTFType.gltf)
: array(WDType.lightMaterial) =>
({materials}: GLTFType.gltf): array(WDType.lightMaterial) =>
switch (materials) {
| None => [||]
| Some(materials) =>
Expand Down
54 changes: 22 additions & 32 deletions src/asset/converter/ConvertMeshRenderersSystem.re
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
let _convertByMesh =
(meshes, geometryGameObjectIndices, geometryIndices) =>
let _convertByMesh = (meshes, geometryGameObjectIndices, geometryIndices) =>
geometryGameObjectIndices
|> Js.Array.mapi((_, index) => {
let geometryIndex =
Array.unsafe_get(geometryIndices, index);
let geometryIndex = Array.unsafe_get(geometryIndices, index);

let {primitives}: GLTFType.mesh =
Array.unsafe_get(meshes, geometryIndex);

let {mode}: GLTFType.primitive =
let ({mode, material}: GLTFType.primitive) as primitive =
ConvertCommon.getPrimitiveData(primitives);

Some(
{
drawMode:
switch (mode) {
| Some(0) => DrawModeType.Points
| Some(1) => DrawModeType.Lines
| Some(2) => DrawModeType.Line_loop
| Some(3) => DrawModeType.Line_strip
| Some(4) => DrawModeType.Triangles
| Some(5) => DrawModeType.Triangle_strip
| Some(6) => DrawModeType.Triangle_fan
| None => DrawModeType.Triangles
},
}: WDType.meshRenderer,
);
ConvertMeshUtils.doesPrimitiveHasMaterial(primitive) ?
Some(
{
drawMode:
switch (mode) {
| Some(0) => DrawModeType.Points
| Some(1) => DrawModeType.Lines
| Some(2) => DrawModeType.Line_loop
| Some(3) => DrawModeType.Line_strip
| Some(4) => DrawModeType.Triangles
| Some(5) => DrawModeType.Triangle_strip
| Some(6) => DrawModeType.Triangle_fan
| None => DrawModeType.Triangles
},
}: WDType.meshRenderer,
) :
None;
});

let convertToMeshRenderers =
Expand All @@ -37,12 +37,7 @@ let convertToMeshRenderers =
{extras, meshes}: GLTFType.gltf,
) =>
switch (extras) {
| None =>
_convertByMesh(
meshes,
geometryGameObjectIndices,
geometryIndices,
)
| None => _convertByMesh(meshes, geometryGameObjectIndices, geometryIndices)
| Some({meshRenderers}) =>
switch (meshRenderers) {
| Some(meshRenderers) when Js.Array.length(meshRenderers) > 0 =>
Expand All @@ -57,11 +52,6 @@ let convertToMeshRenderers =
),
[||],
)
| _ =>
_convertByMesh(
meshes,
geometryGameObjectIndices,
geometryIndices,
)
| _ => _convertByMesh(meshes, geometryGameObjectIndices, geometryIndices)
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ let convertToBasicCameraViewGameObjectIndexData = nodes => {
index,
) =>
switch (extras) {
| Some(({basicCameraView}))
when basicCameraView |> Js.Option.isSome =>
| Some({basicCameraView}) when basicCameraView |> Js.Option.isSome =>
_convertToGameObjectIndexDataFromExtras(
basicCameraView |> OptionService.unsafeGet,
(gameObjectIndices, componentIndices),
Expand Down Expand Up @@ -170,7 +169,9 @@ let _buildPerspectiveCameraProjectionGameObjectIndexData =
componentIndices
|> ArrayService.push(
perspectiveCameraActualIndexMap
|> WonderCommonlib.MutableSparseMapService.unsafeGet(camera),
|> WonderCommonlib.MutableSparseMapService.unsafeGet(
camera,
),
),
)
| _ => (gameObjectIndices, componentIndices)
Expand All @@ -179,14 +180,13 @@ let _buildPerspectiveCameraProjectionGameObjectIndexData =
([||], [||]),
);

let buildEmptyGameObjectIndexData = () : WDType.componentGameObjectIndexData => {
let buildEmptyGameObjectIndexData = (): WDType.componentGameObjectIndexData => {
gameObjectIndices: [||],
componentIndices: [||],
};

let convertToPerspectiveCameraProjectionGameObjectIndexData =
(nodes, cameras)
: WDType.componentGameObjectIndexData =>
(nodes, cameras): WDType.componentGameObjectIndexData =>
switch (cameras) {
| None => buildEmptyGameObjectIndexData()
| Some(cameras) =>
Expand All @@ -207,8 +207,7 @@ let convertToPerspectiveCameraProjectionGameObjectIndexData =
};

let convertToArcballCameraControllerGameObjectIndexData =
nodes
: WDType.componentGameObjectIndexData => {
nodes: WDType.componentGameObjectIndexData => {
let (gameObjectIndices, componentIndices) =
nodes
|> WonderCommonlib.ArrayService.reduceOneParami(
Expand Down Expand Up @@ -351,7 +350,7 @@ let convertToGeometryGameObjectIndexData = nodes => {
|> _checkGameObjectAndComponentIndicesCountShouldEqual;
};

let convertToMeshRendererGameObjectIndexData = nodes => {
let convertToMeshRendererGameObjectIndexData = (nodes, meshes) => {
let (gameObjectIndices, componentIndices) =
nodes
|> WonderCommonlib.ArrayService.reduceOneParami(
Expand All @@ -370,13 +369,17 @@ let convertToMeshRendererGameObjectIndexData = nodes => {
| _ =>
switch (mesh) {
| None => (gameObjectIndices, componentIndices)
| Some(mesh) => (
gameObjectIndices |> ArrayService.push(index),
componentIndices
|> ArrayService.push(
(gameObjectIndices |> Js.Array.length) - 1,
),
)
| Some(mesh) =>
Array.unsafe_get(meshes, mesh)
|> ConvertMeshUtils.doesMeshHasMaterial ?
(
gameObjectIndices |> ArrayService.push(index),
componentIndices
|> ArrayService.push(
(gameObjectIndices |> Js.Array.length) - 1,
),
) :
(gameObjectIndices, componentIndices)
}
},
([||], [||]),
Expand Down Expand Up @@ -429,7 +432,9 @@ let _buildLightGameObjectIndexData =
componentIndices
|> ArrayService.push(
lightActualIndexMap
|> WonderCommonlib.MutableSparseMapService.unsafeGet(light),
|> WonderCommonlib.MutableSparseMapService.unsafeGet(
light,
),
),
)
| _ => (gameObjectIndices, componentIndices)
Expand All @@ -440,8 +445,7 @@ let _buildLightGameObjectIndexData =
);

let convertToLightGameObjectIndexData =
(lightType, nodes, extensions)
: WDType.componentGameObjectIndexData =>
(lightType, nodes, extensions): WDType.componentGameObjectIndexData =>
switch (extensions) {
| None => buildEmptyGameObjectIndexData()
| Some(({khr_lights}: GLTFType.extensions)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let convertToGameObjectIndexData =
meshRendererGameObjectIndexData:
ConvertComponentIndexDataSystem.convertToMeshRendererGameObjectIndexData(
nodes,
meshes
),
directionLightGameObjectIndexData:
ConvertComponentIndexDataSystem.convertToLightGameObjectIndexData(
Expand Down
5 changes: 5 additions & 0 deletions src/asset/converter/utils/ConvertMeshUtils.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let doesPrimitiveHasMaterial = ({material}: GLTFType.primitive) =>
material |> Js.Option.isSome;

let doesMeshHasMaterial = ({primitives}: GLTFType.mesh) =>
ConvertCommon.getPrimitiveData(primitives) |> doesPrimitiveHasMaterial;
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ let _ =
});
});

describe("test set default material", () => {
/* describe("test set default material", () => {
describe("test if node has any one material extras", () =>
test("not add default lightMaterial", () =>
ConvertGLBTool.testGLTFResultByGLTF(
Expand Down Expand Up @@ -419,7 +419,7 @@ let _ =
)
);
describe("else, test mesh has no material", () => {
describe("else, if mesh has no material", () => {
test("add default lightMaterial", () =>
ConvertGLBTool.testGLTFResultByGLTF(
~sandbox=sandbox^,
Expand Down Expand Up @@ -477,7 +477,7 @@ let _ =
)
);
});
});
}); */

test("test asset", () =>
ConvertGLBTool.testGLTFResultByGLTF(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ let _ =
~embeddedGLTFJsonStr=ConvertGLBTool.buildGLTFJsonOfCameras(),
~targetJsonStr=
{|
"nodes":[{"children":[1,2,3],"extras":{"isRoot":true}},{"name":"gameObject_0","rotation":[-0.382999986410141,0,0,0.9237499833106995],"mesh":0,"extras":{"lightMaterial":0,"meshRenderer":0}},{"name":"gameObject_1","translation":[0.5,0.5,3],"camera":0,"extras":{"basicCameraView":0}},{"name":"gameObject_2","translation":[0.5,0.5,3],"extras":{"basicCameraView":1}}]
,"nodes":[{"children":[1,2,3],"extras":{"isRoot":true}},{"name":"gameObject_0","rotation":[-0.382999986410141,0,0,0.9237499833106995],"mesh":0},{"name":"gameObject_1","translation":[0.5,0.5,3],"camera":0,"extras":{"basicCameraView":0}},{"name":"gameObject_2","translation":[0.5,0.5,3],"extras":{"basicCameraView":1}}]
|},
~state,
(),
Expand Down

0 comments on commit 3fed95d

Please sign in to comment.