Skip to content
Permalink
Browse files

feat(asset-bundle): fix "generate single sab": now can get imageUint8…

…Array data
  • Loading branch information...
yyc-git committed Apr 25, 2019
1 parent 1bc90c4 commit b035e61c345a6cbaadea0cacbba714a75314fc33
@@ -46,8 +46,7 @@ let generateSingleSAB = (sceneGameObject, imageUint8ArrayMap, state) => {
IndicesGeometryMainService.getIndices16,
IndicesGeometryMainService.getIndices32,
),
imageUint8Array =>
_writeUint32DataToUint8Array(imageUint8Array |> Uint8Array.length),
imageUint8Array => imageUint8Array,
),
state,
);
@@ -1,5 +1,7 @@
open Wonder_jest;

open Js.Typed_array;

let _ =
describe("generate single sab", () => {
open Expect;
@@ -11,13 +13,13 @@ let _ =

beforeEach(() => {
sandbox := createSandbox();
state := TestTool.init(~sandbox, ());
state := TestTool.initWithoutBuildFakeDom(~sandbox, ());

GenerateSingleSABTool.prepare(sandbox^);
});
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("generate single wdb", () =>
describe("generate single wdb", () => {
describe("test basic", () => {
let _createGameObject1 = state => {
open GameObjectAPI;
@@ -162,6 +164,80 @@ let _ =
isRoots: WonderCommonlib.MutableSparseMapService.createEmpty(),
};
});
})
);
});

describe("test image", () => {
let _prepareGameObject = state => {
open GameObjectAPI;

let state = state^;

let rootGameObject = SceneAPI.getSceneGameObject(state);

let sceneGameObjectTransform =
GameObjectAPI.unsafeGetGameObjectTransformComponent(
rootGameObject,
state,
);

let imageName = "image1";

let (state, gameObject1, transform1, (material1, texture1)) =
GenerateSABTool.createGameObjectWithMap(imageName, state);

let state = state |> SceneAPI.addSceneChild(transform1);

let (canvas, context, (base64Str1, base64Str2)) =
GenerateSceneGraphSystemTool.prepareCanvas(sandbox);

(state, rootGameObject, (imageName, base64Str1));
};

test("test images", () => {
let (state, rootGameObject, (imageName, base64Str1)) =
_prepareGameObject(state);

let (state, sab) =
GenerateSABSystem.generateSingleSAB(
rootGameObject,
WonderCommonlib.MutableSparseMapService.createEmpty(),
state,
);

let content =
GenerateSingleSABTool.SceneAssetBundleContent.getSceneAssetBundleContent(
sab,
);

content.images
|> expect
== Some([|
{name: imageName, bufferView: 4, mimeType: "image/png"},
|]);
});
test("test image buffer data", () => {
let (state, rootGameObject, (_, base64Str1)) =
_prepareGameObject(state);

let (state, sab) =
GenerateSABSystem.generateSingleSAB(
rootGameObject,
WonderCommonlib.MutableSparseMapService.createEmpty(),
state,
);

let content =
GenerateSingleSABTool.SceneAssetBundleContent.getSceneAssetBundleContent(
sab,
);

(content.bufferViews |> Array.unsafe_get(_, 4)).byteLength
|> expect
== (
BufferUtils.convertBase64ToBinary(base64Str1)
|> Uint8Array.byteLength
);
});
});
});
});
@@ -1,16 +1,7 @@
open Js.Typed_array;

let buildDependencyRelation = dependencyRelationArrArr =>
dependencyRelationArrArr
|> WonderCommonlib.ArrayService.reduceOneParam(
(. relationMap, dependencyRelationArr) =>
relationMap
|> WonderCommonlib.ImmutableHashMapService.set(
dependencyRelationArr |> ArrayService.unsafeGetFirst,
dependencyRelationArr |> Js.Array.sliceFrom(1),
),
WonderCommonlib.ImmutableHashMapService.createEmpty(),
);
GenerateAllABSystem.buildDependencyRelation(dependencyRelationArrArr);

let buildRABData = (rabRelativePath, rab) => (rabRelativePath, rab);

@@ -338,73 +329,8 @@ module TestWABWithOneSABAndOneRAB = {

module TestDuplicateDataForSAB = {
module TestDuplicateImageData = {
let _createTexture1 = state => {
let (state, texture) =
BasicSourceTextureAPI.createBasicSourceTexture(state);

let name = "texture_1";

let state =
BasicSourceTextureAPI.setBasicSourceTextureName(texture, name, state);

let state =
BasicSourceTextureAPI.setBasicSourceTextureWrapS(
texture,
SourceTextureType.Repeat,
state,
)
|> BasicSourceTextureAPI.setBasicSourceTextureMagFilter(
texture,
SourceTextureType.Linear,
);

let width = 30;
let height = 50;

let source = BasicSourceTextureTool.buildSource(width, height);

let state =
BasicSourceTextureAPI.setBasicSourceTextureSource(
texture,
source,
state,
);

(state, (texture, name), (source, width, height));
};

let createGameObject1 = (imageName, state) => {
open GameObjectAPI;
open LightMaterialAPI;
open MeshRendererAPI;

let (state, material) = createLightMaterial(state);

let (state, (texture, _), (source, width, height)) =
_createTexture1(state);

ImageUtils.setImageName(source, imageName);

let state =
LightMaterialAPI.setLightMaterialDiffuseMap(material, texture, state);

let (state, geometry) = BoxGeometryTool.createBoxGeometry(state);
let (state, meshRenderer) = createMeshRenderer(state);
let (state, gameObject) = state |> createGameObject;
let state =
state
|> addGameObjectLightMaterialComponent(gameObject, material)
|> addGameObjectGeometryComponent(gameObject, geometry)
|> addGameObjectMeshRendererComponent(gameObject, meshRenderer);

let transform =
GameObjectAPI.unsafeGetGameObjectTransformComponent(
gameObject,
state,
);

(state, gameObject, transform, (material, texture));
};
let createGameObject1 = (imageName, state) =>
GenerateSABTool.createGameObjectWithMap(imageName, state);
};

module TestDuplicateGeometryData = {
@@ -0,0 +1,60 @@
let _createTexture1 = state => {
let (state, texture) =
BasicSourceTextureAPI.createBasicSourceTexture(state);

let name = "texture_1";

let state =
BasicSourceTextureAPI.setBasicSourceTextureName(texture, name, state);

let state =
BasicSourceTextureAPI.setBasicSourceTextureWrapS(
texture,
SourceTextureType.Repeat,
state,
)
|> BasicSourceTextureAPI.setBasicSourceTextureMagFilter(
texture,
SourceTextureType.Linear,
);

let width = 30;
let height = 50;

let source = BasicSourceTextureTool.buildSource(width, height);

let state =
BasicSourceTextureAPI.setBasicSourceTextureSource(texture, source, state);

(state, (texture, name), (source, width, height));
};

let createGameObjectWithMap = (imageName, state) => {
open GameObjectAPI;
open LightMaterialAPI;
open MeshRendererAPI;

let (state, material) = createLightMaterial(state);

let (state, (texture, _), (source, width, height)) =
_createTexture1(state);

ImageUtils.setImageName(source, imageName);

let state =
LightMaterialAPI.setLightMaterialDiffuseMap(material, texture, state);

let (state, geometry) = BoxGeometryTool.createBoxGeometry(state);
let (state, meshRenderer) = createMeshRenderer(state);
let (state, gameObject) = state |> createGameObject;
let state =
state
|> addGameObjectLightMaterialComponent(gameObject, material)
|> addGameObjectGeometryComponent(gameObject, geometry)
|> addGameObjectMeshRendererComponent(gameObject, meshRenderer);

let transform =
GameObjectAPI.unsafeGetGameObjectTransformComponent(gameObject, state);

(state, gameObject, transform, (material, texture));
};

0 comments on commit b035e61

Please sign in to comment.
You can’t perform that action at this time.