Ejemplo n.º 1
0
        /**
         * Given a SuperMeshInfo with game objects, attach the relevant shaders to the game objects.
         * This function will find all MeshRenderers and attach the specified Opaque/Transparent shader
         * where appropriate
         * @param info SuperMeshInfo object that contains the GameObjects to attach shaders to
         */
        private void AttachShader(SuperMeshInfo info)
        {
            if (info.gameObj == null)
            {
                return;
            }

            var renderers = info.gameObj.GetComponentsInChildren <Renderer>();

            foreach (var r in renderers)
            {
                var materials = r.sharedMaterials;
                foreach (var material in materials)
                {
                    material.shader = material.name.Contains("Transparent") ? transShader: opaqueShader;
                }

                string superMesh = r.gameObject.name.Remove(r.gameObject.name.LastIndexOf('_'));
                string model     = r.gameObject.transform.root.name;

                int height = 0;
                int width  = 0;
                CalculateTextureSquare(info.nSubMeshes, out width, out height);
                attachComponentCallback?.Invoke(r.gameObject, width, height);
            }
        }
Ejemplo n.º 2
0
        private SuperMeshInfo ProcessSuperMeshInfo(AssetMapping assetMapping)
        {
            SuperMeshInfo info = new SuperMeshInfo();

            info.nSubMeshes = assetMapping.mapping.Length;

            return(info);
        }
Ejemplo n.º 3
0
        private Model LoadModel(DataModels.JSONModels.AssetInfo modelInfo)
        {
            var assetBundlesURI = modelInfo.vrAssets;

            if (modelInfo.vrAssets == null || modelInfo.vrAssets.Length == 0)
            {
                if (modelInfo.assets != null && modelInfo.assets.Length > 0)
                {
                    Debug.LogWarning("Win 64 bundles are not generated for this model. Using WebGL bundles...");
                    assetBundlesURI = modelInfo.assets;
                }
                else
                {
                    throw new RepoModelLoadingException("This model does not have any unity bundles.");
                }
            }

            Vector3 relativeOffset = Vector3.zero;

            if (worldOffset == null)
            {
                worldOffset = modelInfo.offset;
            }
            else
            {
                relativeOffset = new Vector3((float)(modelInfo.offset[0] - worldOffset[0]),
                                             (float)(modelInfo.offset[1] - worldOffset[1]),
                                             (float)-(modelInfo.offset[2] - worldOffset[2]));   //unity goes towards the other direction than WebGL
            }

            GameObject[]    gameObjects = new GameObject[assetBundlesURI.Length];
            SuperMeshInfo[] smInfo      = new SuperMeshInfo[modelInfo.jsonFiles.Length];

            //TODO: this can be done asynchronously
            for (int i = 0; i < modelInfo.jsonFiles.Length; ++i)
            {
                smInfo[i] = ProcessSuperMeshInfo(repoHttpClient.LoadBundleJSON(modelInfo.jsonFiles[i]));
            }

            //TODO: this can be done asynchronously
            for (int i = 0; i < assetBundlesURI.Length; ++i)
            {
                AssetBundle bundle = repoHttpClient.LoadBundle(assetBundlesURI[i]);

                var names     = bundle.GetAllAssetNames();
                var bundleObj = bundle.LoadAsset(names[0]) as GameObject;
                gameObjects[i] = UnityEngine.Object.Instantiate(bundleObj);
                gameObjects[i].transform.position += relativeOffset;
                gameObjects[i].name = bundleObj.name;
                AttachShader(gameObjects[i], smInfo[i]);
                bundle.Unload(false);
            }

            return(new Model(modelInfo.database + "." + modelInfo.model, gameObjects, new Vector3((float)modelInfo.offset[0], (float)modelInfo.offset[1], (float)modelInfo.offset[2])));
        }
Ejemplo n.º 4
0
        /**
         * Given an AssetMapping object, process the information Super mesh information
         * @params assetMapping an AssetMapping object to digest
         * @return returns a SuperMeshInfo object containing the digested information.
         */
        private SuperMeshInfo ProcessSuperMeshInfo(AssetMapping assetMapping)
        {
            SuperMeshInfo info = new SuperMeshInfo();

            info.nSubMeshes = assetMapping.mapping.Length;
            info.indexToId  = new string[info.nSubMeshes];

            if (assetMapping.mapping.Length > 0)
            {
                var supermeshId = assetMapping.mapping[0].usage[0];
                info.name = supermeshId.Remove(supermeshId.LastIndexOf('_'));

                for (int i = 0; i < assetMapping.mapping.Length; ++i)
                {
                    info.indexToId[i] = assetMapping.mapping[i].name;
                }
            }

            return(info);
        }
Ejemplo n.º 5
0
        /**
         * Given an AssetMapping object, process the information Super mesh information
         * @params assetMapping an AssetMapping object to digest
         * @return returns a SuperMeshInfo object containing the digested information.
         */
        private SuperMeshInfo ProcessSuperMeshInfo(AssetMapping assetMapping, Dictionary <string, List <MeshLocation> > meshLocations, Dictionary <string, Bounds> meshBboxEntries)
        {
            SuperMeshInfo info = new SuperMeshInfo();

            info.nSubMeshes = assetMapping.mapping.Length;
            info.indexToId  = new string[info.nSubMeshes];

            if (assetMapping.mapping.Length > 0)
            {
                var supermeshId = assetMapping.mapping[0].usage[0];
                info.name = supermeshId.Remove(supermeshId.LastIndexOf('_'));

                for (int i = 0; i < assetMapping.mapping.Length; ++i)
                {
                    var meshId = assetMapping.mapping[i].name;
                    info.indexToId[i] = meshId;
                    if (!meshLocations.ContainsKey(meshId))
                    {
                        meshLocations[meshId] = new List <MeshLocation>();
                    }
                    meshLocations[meshId].Add(new MeshLocation(supermeshId, i));
                    Bounds bbox = new Bounds();
                    bbox.SetMinMax(ArrayToVector3d(assetMapping.mapping[i].min), ArrayToVector3d(assetMapping.mapping[i].max));
                    if (!meshBboxEntries.ContainsKey(meshId))
                    {
                        meshBboxEntries[meshId] = bbox;
                    }
                    else
                    {
                        meshBboxEntries[meshId].Encapsulate(bbox);
                    }
                }
            }

            return(info);
        }