diff --git a/.gitignore b/.gitignore index 26aaad743..f2d2d267a 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,6 @@ oculussig_* third_party user.properties* + +# Node modules +node_modules diff --git a/README.md b/README.md index 8a72948e0..cd586684f 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,15 @@ geckoViewLocalArm=/path/to/your/build/geckoview-nightly-armeabi-v7a-64.0.2018092 geckoViewLocalX86=/path/to/your/build/geckoview-nightly-x86-64.0.20180924100359.aar ``` +## Compress assets + +ETC2 compression is used to improve performance and memory usage. Raw assets are placed in the `uncompressed_assets` folder. You can generate the compressed textures using the compressor utility in `tools/compressor`. You need to set up [etc2comp](https://github.com/google/etc2comp) and make it available on your PATH before running the script. Run this command to generate the compressed assets: + +```bash +npm install +gulp compress +``` + ## Development troubleshooting ### `Device supports , but APK only supports armeabi-v7a[...]` diff --git a/app/src/googlevr/assets/vr_controller_daydream.mtl b/app/src/googlevr/assets/vr_controller_daydream.mtl index edb371587..57972293b 100644 --- a/app/src/googlevr/assets/vr_controller_daydream.mtl +++ b/app/src/googlevr/assets/vr_controller_daydream.mtl @@ -10,5 +10,5 @@ Ke 0.000000 0.000000 0.000000 Ni 1.500000 d 1.000000 illum 2 -map_Kd vr_controller_daydream_tex.png -map_Ka vr_controller_daydream_tex.png +map_Kd vr_controller_daydream_tex.ktx +map_Ka vr_controller_daydream_tex.ktx diff --git a/app/src/googlevr/assets/vr_controller_daydream_tex.ktx b/app/src/googlevr/assets/vr_controller_daydream_tex.ktx new file mode 100644 index 000000000..04baf4bcd Binary files /dev/null and b/app/src/googlevr/assets/vr_controller_daydream_tex.ktx differ diff --git a/app/src/main/assets/cubemap/cave/negx.ktx b/app/src/main/assets/cubemap/cave/negx.ktx new file mode 100644 index 000000000..82ab5faf5 Binary files /dev/null and b/app/src/main/assets/cubemap/cave/negx.ktx differ diff --git a/app/src/main/assets/cubemap/cave/negy.ktx b/app/src/main/assets/cubemap/cave/negy.ktx new file mode 100644 index 000000000..1a9242504 Binary files /dev/null and b/app/src/main/assets/cubemap/cave/negy.ktx differ diff --git a/app/src/main/assets/cubemap/cave/negz.ktx b/app/src/main/assets/cubemap/cave/negz.ktx new file mode 100644 index 000000000..24f67f99d Binary files /dev/null and b/app/src/main/assets/cubemap/cave/negz.ktx differ diff --git a/app/src/main/assets/cubemap/cave/posx.ktx b/app/src/main/assets/cubemap/cave/posx.ktx new file mode 100644 index 000000000..ad2c48c5b Binary files /dev/null and b/app/src/main/assets/cubemap/cave/posx.ktx differ diff --git a/app/src/main/assets/cubemap/cave/posy.ktx b/app/src/main/assets/cubemap/cave/posy.ktx new file mode 100644 index 000000000..de39d9730 Binary files /dev/null and b/app/src/main/assets/cubemap/cave/posy.ktx differ diff --git a/app/src/main/assets/cubemap/cave/posz.ktx b/app/src/main/assets/cubemap/cave/posz.ktx new file mode 100644 index 000000000..e43fd19a8 Binary files /dev/null and b/app/src/main/assets/cubemap/cave/posz.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/negx.ktx b/app/src/main/assets/cubemap/meadow/negx.ktx new file mode 100644 index 000000000..6e7d59806 Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/negx.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/negy.ktx b/app/src/main/assets/cubemap/meadow/negy.ktx new file mode 100644 index 000000000..c85daed11 Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/negy.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/negz.ktx b/app/src/main/assets/cubemap/meadow/negz.ktx new file mode 100644 index 000000000..d210a3530 Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/negz.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/posx.ktx b/app/src/main/assets/cubemap/meadow/posx.ktx new file mode 100644 index 000000000..262023938 Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/posx.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/posy.ktx b/app/src/main/assets/cubemap/meadow/posy.ktx new file mode 100644 index 000000000..04486177a Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/posy.ktx differ diff --git a/app/src/main/assets/cubemap/meadow/posz.ktx b/app/src/main/assets/cubemap/meadow/posz.ktx new file mode 100644 index 000000000..c5884b57d Binary files /dev/null and b/app/src/main/assets/cubemap/meadow/posz.ktx differ diff --git a/app/src/main/assets/cubemap/space/negx.ktx b/app/src/main/assets/cubemap/space/negx.ktx new file mode 100644 index 000000000..b771d5e40 Binary files /dev/null and b/app/src/main/assets/cubemap/space/negx.ktx differ diff --git a/app/src/main/assets/cubemap/space/negy.ktx b/app/src/main/assets/cubemap/space/negy.ktx new file mode 100644 index 000000000..e1d5a2b81 Binary files /dev/null and b/app/src/main/assets/cubemap/space/negy.ktx differ diff --git a/app/src/main/assets/cubemap/space/negz.ktx b/app/src/main/assets/cubemap/space/negz.ktx new file mode 100644 index 000000000..af8833e30 Binary files /dev/null and b/app/src/main/assets/cubemap/space/negz.ktx differ diff --git a/app/src/main/assets/cubemap/space/posx.ktx b/app/src/main/assets/cubemap/space/posx.ktx new file mode 100644 index 000000000..99b028839 Binary files /dev/null and b/app/src/main/assets/cubemap/space/posx.ktx differ diff --git a/app/src/main/assets/cubemap/space/posy.ktx b/app/src/main/assets/cubemap/space/posy.ktx new file mode 100644 index 000000000..9896e2175 Binary files /dev/null and b/app/src/main/assets/cubemap/space/posy.ktx differ diff --git a/app/src/main/assets/cubemap/space/posz.ktx b/app/src/main/assets/cubemap/space/posz.ktx new file mode 100644 index 000000000..394e594b1 Binary files /dev/null and b/app/src/main/assets/cubemap/space/posz.ktx differ diff --git a/app/src/main/assets/spinners_v3.ktx b/app/src/main/assets/spinners_v3.ktx new file mode 100644 index 000000000..eabee51e8 Binary files /dev/null and b/app/src/main/assets/spinners_v3.ktx differ diff --git a/app/src/main/assets/spinners_v3.mtl b/app/src/main/assets/spinners_v3.mtl index ffbc55986..3686212ab 100755 --- a/app/src/main/assets/spinners_v3.mtl +++ b/app/src/main/assets/spinners_v3.mtl @@ -10,4 +10,4 @@ Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 -map_Kd spinners_v3.jpg +map_Kd spinners_v3.ktx diff --git a/app/src/main/assets/webvr_spinner.png b/app/src/main/assets/webvr_spinner.png deleted file mode 100644 index 057000234..000000000 Binary files a/app/src/main/assets/webvr_spinner.png and /dev/null differ diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index 2d0ba41a1..88854808e 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -505,14 +505,16 @@ BrowserWorld::InitializeJava(JNIEnv* aEnv, jobject& aActivity, jobject& aAssetMa m.loadingAnimation->LoadModels(m.loader); m.rootController->AddNode(m.controllers->GetRoot()); std::string skyboxPath = VRBrowser::GetActiveEnvironment(); + std::string extension; if (VRBrowser::isOverrideEnvPathEnabled()) { std::string storagePath = VRBrowser::GetStorageAbsolutePath(INJECT_SKYBOX_PATH); if (std::ifstream(storagePath)) { skyboxPath = storagePath; + extension = ".jpg"; } } #if !defined(SNAPDRAGONVR) - CreateSkyBox(skyboxPath.c_str()); + CreateSkyBox(skyboxPath.c_str(), extension); // Don't load the env model, we are going for skyboxes in v1.0 // CreateFloor(); #endif @@ -650,7 +652,7 @@ BrowserWorld::UpdateEnvironment() { ASSERT_ON_RENDER_THREAD(); std::string env = VRBrowser::GetActiveEnvironment(); VRB_LOG("Setting environment: %s", env.c_str()); - CreateSkyBox(env.c_str()); + CreateSkyBox(env.c_str(), ""); } void @@ -1071,21 +1073,23 @@ BrowserWorld::DrawSplashAnimation() { } void -BrowserWorld::CreateSkyBox(const std::string& basePath) { +BrowserWorld::CreateSkyBox(const std::string& aBasePath, const std::string& aExtension) { ASSERT_ON_RENDER_THREAD(); - const bool empty = basePath == "cubemap/void"; + const bool empty = aBasePath == "cubemap/void"; + const std::string extension = aExtension.empty() ? ".ktx" : aExtension; if (m.skybox && empty) { m.skybox->SetVisible(false); return; } else if (m.skybox) { m.skybox->SetVisible(true); - m.skybox->Load(m.loader, basePath); + m.skybox->Load(m.loader, aBasePath, extension); return; } else if (!empty) { - VRLayerCubePtr layer = m.device->CreateLayerCube(1024, 1024); + GLenum glFormat = extension == ".ktx" ? GL_COMPRESSED_RGB8_ETC2 : GL_RGB8; + VRLayerCubePtr layer = m.device->CreateLayerCube(1024, 1024, glFormat); m.skybox = Skybox::Create(m.create, layer); m.rootOpaqueParent->AddNode(m.skybox->GetRoot()); - m.skybox->Load(m.loader, basePath); + m.skybox->Load(m.loader, aBasePath, extension); } } diff --git a/app/src/main/cpp/BrowserWorld.h b/app/src/main/cpp/BrowserWorld.h index 949cce73e..b86d09984 100644 --- a/app/src/main/cpp/BrowserWorld.h +++ b/app/src/main/cpp/BrowserWorld.h @@ -65,7 +65,7 @@ class BrowserWorld { void DrawImmersive(); void DrawLoadingAnimation(); void DrawSplashAnimation(); - void CreateSkyBox(const std::string& basePath); + void CreateSkyBox(const std::string& aBasePath, const std::string& aExtension); void CreateFloor(); float DistanceToPlane(const vrb::NodePtr& aNode, const vrb::Vector& aPosition, const vrb::Vector& aDirection) const; private: diff --git a/app/src/main/cpp/DeviceDelegate.h b/app/src/main/cpp/DeviceDelegate.h index 634b8c97b..0fa318f99 100644 --- a/app/src/main/cpp/DeviceDelegate.h +++ b/app/src/main/cpp/DeviceDelegate.h @@ -65,7 +65,7 @@ class DeviceDelegate { virtual VRLayerQuadPtr CreateLayerQuad(int32_t aWidth, int32_t aHeight, VRLayerQuad::SurfaceType aSurfaceType) { return nullptr; } - virtual VRLayerCubePtr CreateLayerCube(int32_t aWidth, int32_t aHeight) { return nullptr; } + virtual VRLayerCubePtr CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint aInternalFormat) { return nullptr; } virtual VRLayerEquirectPtr CreateLayerEquirect(const VRLayerQuadPtr &aSource) { return nullptr; } virtual void DeleteLayer(const VRLayerPtr& aLayer) {}; protected: diff --git a/app/src/main/cpp/Skybox.cpp b/app/src/main/cpp/Skybox.cpp index 4b1bc080b..419f237d7 100644 --- a/app/src/main/cpp/Skybox.cpp +++ b/app/src/main/cpp/Skybox.cpp @@ -25,7 +25,8 @@ using namespace vrb; namespace crow { -static TextureCubeMapPtr LoadTextureCube(vrb::CreationContextPtr& aContext, const std::string& aBasePath, GLuint targetTexture = 0) { +static TextureCubeMapPtr LoadTextureCube(vrb::CreationContextPtr& aContext, const std::string& aBasePath, + const std::string& aExtension, GLuint targetTexture = 0) { TextureCubeMapPtr cubemap = vrb::TextureCubeMap::Create(aContext, targetTexture); cubemap->SetTextureParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR); cubemap->SetTextureParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -33,7 +34,7 @@ static TextureCubeMapPtr LoadTextureCube(vrb::CreationContextPtr& aContext, cons cubemap->SetTextureParameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); cubemap->SetTextureParameter(GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - auto path = [&](const std::string &name) { return aBasePath + "/" + name + ".jpg"; }; + auto path = [&](const std::string &name) { return aBasePath + "/" + name + aExtension; }; vrb::TextureCubeMap::Load(aContext, cubemap, path("posx"), path("negx"), path("posy"), path("negy"), path("posz"), path("negz")); return cubemap; @@ -48,6 +49,7 @@ struct Skybox::State { vrb::GeometryPtr geometry; vrb::ModelLoaderAndroidPtr loader; std::string basePath; + std::string extension; TextureCubeMapPtr texture; State(): layerTextureHandle(0) @@ -116,7 +118,7 @@ struct Skybox::State { } - texture = LoadTextureCube(aContext, basePath); + texture = LoadTextureCube(aContext, basePath, extension); vrb::RenderStatePtr state = geometry->GetRenderState(); state->SetTexture(texture); state->SetMaterial(Color(1.0f, 1.0f, 1.0f), Color(1.0f, 1.0f, 1.0f), Color(0.0f, 0.0f, 0.0f), @@ -135,19 +137,20 @@ struct Skybox::State { return; } vrb::CreationContextPtr create = context.lock(); - texture = LoadTextureCube(create, basePath, layerTextureHandle); + texture = LoadTextureCube(create, basePath, extension, layerTextureHandle); texture->Bind(); layer->SetLoaded(true); } }; void -Skybox::Load(const vrb::ModelLoaderAndroidPtr& aLoader, const std::string& aBasePath) { +Skybox::Load(const vrb::ModelLoaderAndroidPtr& aLoader, const std::string& aBasePath, const std::string& aExtension) { if (m.basePath == aBasePath) { return; } m.loader = aLoader; m.basePath = aBasePath; + m.extension = aExtension; if (m.layer) { m.LoadLayer(); } else { diff --git a/app/src/main/cpp/Skybox.h b/app/src/main/cpp/Skybox.h index b196d80b8..5234ffb88 100644 --- a/app/src/main/cpp/Skybox.h +++ b/app/src/main/cpp/Skybox.h @@ -20,7 +20,7 @@ typedef std::shared_ptr VRLayerCubePtr; class Skybox { public: static SkyboxPtr Create(vrb::CreationContextPtr aContext, const VRLayerCubePtr& aLayer = nullptr); - void Load(const vrb::ModelLoaderAndroidPtr& aLoader, const std::string &basePath); + void Load(const vrb::ModelLoaderAndroidPtr& aLoader, const std::string& aBasePath, const std::string& aExtension); void SetVisible(bool aVisible); void SetTransform(const vrb::Matrix& aTransform); void SetTintColor(const vrb::Color& aTintColor); diff --git a/app/src/main/cpp/vrb b/app/src/main/cpp/vrb index 18a5830d3..01c7f9e5d 160000 --- a/app/src/main/cpp/vrb +++ b/app/src/main/cpp/vrb @@ -1 +1 @@ -Subproject commit 18a5830d3dd75b021caaeee21a0f2da31deab270 +Subproject commit 01c7f9e5d24adcc48f4231ea0243a0b775a3c935 diff --git a/app/src/oculusvr/assets/vr_controller_oculusgo.mtl b/app/src/oculusvr/assets/vr_controller_oculusgo.mtl index e041297f1..69a4a7bf6 100644 --- a/app/src/oculusvr/assets/vr_controller_oculusgo.mtl +++ b/app/src/oculusvr/assets/vr_controller_oculusgo.mtl @@ -10,5 +10,5 @@ Ke 0.000000 0.000000 0.000000 Ni 1.500000 d 1.000000 illum 2 -map_Kd vr_controller_oculusgo_tex.png -map_Ka vr_controller_oculusgo_tex.png +map_Kd vr_controller_oculusgo_tex.ktx +map_Ka vr_controller_oculusgo_tex.ktx diff --git a/app/src/oculusvr/assets/vr_controller_oculusgo_tex.ktx b/app/src/oculusvr/assets/vr_controller_oculusgo_tex.ktx new file mode 100644 index 000000000..a5687ca8a Binary files /dev/null and b/app/src/oculusvr/assets/vr_controller_oculusgo_tex.ktx differ diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index 9fd38c7dd..784a534f5 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -326,9 +326,10 @@ typedef std::shared_ptr OculusLayerCubePtr; class OculusLayerCube: public OculusLayer { public: - static OculusLayerCubePtr Create(const VRLayerCubePtr& aLayer) { + static OculusLayerCubePtr Create(const VRLayerCubePtr& aLayer, GLint aInternalFormat) { auto result = std::make_shared(); result->layer = aLayer; + result->glFormat = aInternalFormat; return result; } @@ -341,7 +342,7 @@ class OculusLayerCube: public OculusLayer { ovrLayer.Offset.x = 0.0f; ovrLayer.Offset.y = 0.0f; ovrLayer.Offset.z = 0.0f; - swapChain = vrapi_CreateTextureSwapChain(VRAPI_TEXTURE_TYPE_CUBE, VRAPI_TEXTURE_FORMAT_8888, layer->GetWidth(), layer->GetHeight(), 1, false); + swapChain = vrapi_CreateTextureSwapChain3(VRAPI_TEXTURE_TYPE_CUBE, glFormat, layer->GetWidth(), layer->GetHeight(), 1, 1); layer->SetTextureHandle(vrapi_GetTextureSwapChainHandle(swapChain, 0)); OculusLayer::Init(); } @@ -375,6 +376,8 @@ class OculusLayerCube: public OculusLayer { const ovrLayerHeader2 * Header() const override { return &ovrLayer.Header; } +protected: + GLint glFormat; }; @@ -1059,7 +1062,7 @@ DeviceDelegateOculusVR::CreateLayerQuad(int32_t aWidth, int32_t aHeight, } VRLayerCubePtr -DeviceDelegateOculusVR::CreateLayerCube(int32_t aWidth, int32_t aHeight) { +DeviceDelegateOculusVR::CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint aInternalFormat) { if (!m.layersEnabled) { return nullptr; } @@ -1067,7 +1070,7 @@ DeviceDelegateOculusVR::CreateLayerCube(int32_t aWidth, int32_t aHeight) { m.cubeLayer->Destroy(); } VRLayerCubePtr layer = VRLayerCube::Create(aWidth, aHeight); - m.cubeLayer = OculusLayerCube::Create(layer); + m.cubeLayer = OculusLayerCube::Create(layer, aInternalFormat); if (m.ovr) { m.cubeLayer->Init(); } diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.h b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.h index 1aac67a34..3da872c6c 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.h +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.h @@ -43,7 +43,7 @@ class DeviceDelegateOculusVR : public DeviceDelegate { void EndFrame(const bool aDiscard) override; VRLayerQuadPtr CreateLayerQuad(int32_t aWidth, int32_t aHeight, VRLayerQuad::SurfaceType aSurfaceType) override; - VRLayerCubePtr CreateLayerCube(int32_t aWidth, int32_t aHeight) override; + VRLayerCubePtr CreateLayerCube(int32_t aWidth, int32_t aHeight, GLint aInternalFormat) override; VRLayerEquirectPtr CreateLayerEquirect(const VRLayerQuadPtr &aSource) override; void DeleteLayer(const VRLayerPtr& aLayer) override; // Custom methods for NativeActivity render loop based devices. diff --git a/app/src/googlevr/assets/vr_controller_daydream_tex.png b/app/src/uncompressed_assets/googlevr/assets/vr_controller_daydream_tex.png similarity index 100% rename from app/src/googlevr/assets/vr_controller_daydream_tex.png rename to app/src/uncompressed_assets/googlevr/assets/vr_controller_daydream_tex.png diff --git a/app/src/main/assets/cubemap/cave/negx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/negx.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/negx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/negx.jpg diff --git a/app/src/main/assets/cubemap/cave/negy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/negy.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/negy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/negy.jpg diff --git a/app/src/main/assets/cubemap/cave/negz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/negz.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/negz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/negz.jpg diff --git a/app/src/main/assets/cubemap/cave/posx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/posx.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/posx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/posx.jpg diff --git a/app/src/main/assets/cubemap/cave/posy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/posy.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/posy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/posy.jpg diff --git a/app/src/main/assets/cubemap/cave/posz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/cave/posz.jpg similarity index 100% rename from app/src/main/assets/cubemap/cave/posz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/cave/posz.jpg diff --git a/app/src/main/assets/cubemap/meadow/negx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/negx.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/negx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/negx.jpg diff --git a/app/src/main/assets/cubemap/meadow/negy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/negy.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/negy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/negy.jpg diff --git a/app/src/main/assets/cubemap/meadow/negz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/negz.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/negz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/negz.jpg diff --git a/app/src/main/assets/cubemap/meadow/posx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/posx.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/posx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/posx.jpg diff --git a/app/src/main/assets/cubemap/meadow/posy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/posy.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/posy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/posy.jpg diff --git a/app/src/main/assets/cubemap/meadow/posz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/meadow/posz.jpg similarity index 100% rename from app/src/main/assets/cubemap/meadow/posz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/meadow/posz.jpg diff --git a/app/src/main/assets/cubemap/space/negx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/negx.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/negx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/negx.jpg diff --git a/app/src/main/assets/cubemap/space/negy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/negy.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/negy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/negy.jpg diff --git a/app/src/main/assets/cubemap/space/negz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/negz.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/negz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/negz.jpg diff --git a/app/src/main/assets/cubemap/space/posx.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/posx.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/posx.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/posx.jpg diff --git a/app/src/main/assets/cubemap/space/posy.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/posy.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/posy.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/posy.jpg diff --git a/app/src/main/assets/cubemap/space/posz.jpg b/app/src/uncompressed_assets/main/assets/cubemap/space/posz.jpg similarity index 100% rename from app/src/main/assets/cubemap/space/posz.jpg rename to app/src/uncompressed_assets/main/assets/cubemap/space/posz.jpg diff --git a/app/src/main/assets/spinners_v3.jpg b/app/src/uncompressed_assets/main/assets/spinners_v3.jpg similarity index 100% rename from app/src/main/assets/spinners_v3.jpg rename to app/src/uncompressed_assets/main/assets/spinners_v3.jpg diff --git a/app/src/oculusvr/assets/vr_controller_oculusgo_tex.png b/app/src/uncompressed_assets/oculusvr/assets/vr_controller_oculusgo_tex.png similarity index 100% rename from app/src/oculusvr/assets/vr_controller_oculusgo_tex.png rename to app/src/uncompressed_assets/oculusvr/assets/vr_controller_oculusgo_tex.png diff --git a/app/src/wavevr/assets/vr_controller_focus_tex.png b/app/src/uncompressed_assets/wavevr/assets/vr_controller_focus_tex.png similarity index 100% rename from app/src/wavevr/assets/vr_controller_focus_tex.png rename to app/src/uncompressed_assets/wavevr/assets/vr_controller_focus_tex.png diff --git a/app/src/wavevr/assets/vr_controller_focus.mtl b/app/src/wavevr/assets/vr_controller_focus.mtl index c5e5df473..ed213e737 100644 --- a/app/src/wavevr/assets/vr_controller_focus.mtl +++ b/app/src/wavevr/assets/vr_controller_focus.mtl @@ -10,5 +10,5 @@ Ke 0.000000 0.000000 0.000000 Ni 1.500000 d 1.000000 illum 2 -map_Kd vr_controller_focus_tex.png -map_Ka vr_controller_focus_tex.png +map_Kd vr_controller_focus_tex.ktx +map_Ka vr_controller_focus_tex.ktx diff --git a/app/src/wavevr/assets/vr_controller_focus_tex.ktx b/app/src/wavevr/assets/vr_controller_focus_tex.ktx new file mode 100644 index 000000000..1cb07d2f1 Binary files /dev/null and b/app/src/wavevr/assets/vr_controller_focus_tex.ktx differ diff --git a/tools/compressor/gulpfile.js b/tools/compressor/gulpfile.js new file mode 100644 index 000000000..f2f59346d --- /dev/null +++ b/tools/compressor/gulpfile.js @@ -0,0 +1,80 @@ +const fs = require('fs'); +const path = require('path'); +const gulp = require('gulp'); +const sharp = require('sharp'); +const tmp = require('tmp'); +const execSync = require('child_process').execSync; +const readdirp = require('readdirp'); + +const assetsPath = '../../app/src/uncompressed_assets'; +const assetFilter = ['*.jpg', '*.jpeg', '*.png']; + +function compressAsset(source, target, rgba, done) { + if (fs.existsSync(target)) { + console.log("Already compressed: " + target); + done(); + return; + } + + const extension = path.extname(source); + if (extension !== ".png") { + // Etc2Tool requires png format + const tempImage = tmp.tmpNameSync() + ".png"; + sharp(source) + .toFile(tempImage) + .then(data => { + compressAsset(tempImage, target, false, done); + }) + .catch(err => { + console.log("PNG conversion failed for " + source + ": " + err); + done(err); + }); + return; + } + + try { + console.log("About to compress: " + target); + var format = rgba ? "RGBA8" : "RGB8"; + var out = execSync(`EtcTool ${source} -output ${target} -format ${format} -effort 100 -v`).toString(); + console.log(out); + done(); + } catch (err) { + console.error(err.message); + done(err); + } +} + +gulp.task('compress', function(done) { + let pending = 0; + let finished = false; + const settings = { + root: assetsPath, + fileFilter: assetFilter + }; + readdirp(settings) + .on('data', function (entry) { + pending++; + const name = entry.fullPath; + const extension = path.extname(name); + let target = name.slice(0, -extension.length) + ".ktx"; + target = target.replace("uncompressed_assets/", ""); + compressAsset(name, target, true, function() { + pending--; + if (finished && !pending) { + done(); + } + }); + }) + .on('warn', function(warn){ + console.log("Warn: ", warn); + }) + .on('error', function(err){ + console.log("Error: ", err); + }) + .on('end', function(){ + finished = true; + if (!pending) { + done(); + } + }); +}); \ No newline at end of file diff --git a/tools/compressor/package.json b/tools/compressor/package.json new file mode 100644 index 000000000..b0a821f52 --- /dev/null +++ b/tools/compressor/package.json @@ -0,0 +1,24 @@ +{ + "name": "fxr-compressor", + "version": "1.0.0", + "description": "FxR asset compressor", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "fxr", + "asset", + "compressor" + ], + "author": "Mozilla", + "license": "Apache-2.0", + "devDependencies": { + "gulp": "^4.0.0" + }, + "dependencies": { + "readdirp": "^2.2.1", + "sharp": "^0.21.1", + "tmp": "0.0.33" + } +}