Esempio n. 1
0
        public static ChiselModelGeneratedObjects Create(ChiselModel model)
        {
            // Make sure there's not a dangling container out there from a previous version
            var existingContainer = model.FindChildByName(kGeneratedContainerName);

            ChiselObjectUtility.SafeDestroy(existingContainer, ignoreHierarchyEvents: true);

            var modelState         = GameObjectState.Create(model);
            var parent             = model.transform;
            var container          = ChiselObjectUtility.CreateGameObject(kGeneratedContainerName, parent, modelState);
            var containerTransform = container.transform;
            var colliderContainer  = ChiselObjectUtility.CreateGameObject(kGeneratedMeshColliderName, containerTransform, modelState);

            Debug.Assert((int)LayerUsageFlags.Renderable == 1);
            Debug.Assert((int)LayerUsageFlags.CastShadows == 2);
            Debug.Assert((int)LayerUsageFlags.ReceiveShadows == 4);
            Debug.Assert((int)LayerUsageFlags.RenderReceiveCastShadows == (1 | 2 | 4));

            var renderables = new ChiselRenderObjects[]
            {
                null,//ChiselRenderObjects Create(kGeneratedMeshRendererNames[0], containerTransform, modelState, LayerUsageFlags.None),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[1], containerTransform, modelState, LayerUsageFlags.Renderable),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[2], containerTransform, modelState, LayerUsageFlags.CastShadows),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[3], containerTransform, modelState, LayerUsageFlags.Renderable | LayerUsageFlags.CastShadows),
                null, //ChiselRenderObjects.Create(kGeneratedMeshRendererNames[4], containerTransform, modelState,                                                     LayerUsageFlags.ReceiveShadows),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[5], containerTransform, modelState, LayerUsageFlags.Renderable | LayerUsageFlags.ReceiveShadows),
                null, //ChiselRenderObjects.Create(kGeneratedMeshRendererNames[6], containerTransform, modelState,                       LayerUsageFlags.CastShadows | LayerUsageFlags.ReceiveShadows),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[7], containerTransform, modelState, LayerUsageFlags.Renderable | LayerUsageFlags.CastShadows | LayerUsageFlags.ReceiveShadows),
            };

            var meshRenderers = new MeshRenderer[]
            {
                renderables[1].meshRenderer,
                renderables[2].meshRenderer,
                renderables[3].meshRenderer,
                renderables[5].meshRenderer,
                renderables[7].meshRenderer
            };

            return(new ChiselModelGeneratedObjects
            {
                generatedDataContainer = container,
                colliderContainer = colliderContainer,
                colliders = new ChiselColliderObjects[0],
                renderables = renderables,
                meshRenderers = meshRenderers
            });
        }
        public static ChiselGeneratedObjects Create(GameObject parentGameObject)
        {
            var parentTransform = parentGameObject.transform;

            // Make sure there's not a dangling container out there from a previous version
            var existingContainer = parentTransform.FindChildByName(kGeneratedContainerName);

            ChiselObjectUtility.SafeDestroy(existingContainer, ignoreHierarchyEvents: true);

            var gameObjectState    = GameObjectState.Create(parentGameObject);
            var container          = ChiselObjectUtility.CreateGameObject(kGeneratedContainerName, parentTransform, gameObjectState);
            var containerTransform = container.transform;
            var colliderContainer  = ChiselObjectUtility.CreateGameObject(kGeneratedMeshColliderName, containerTransform, gameObjectState);

            Debug.Assert((int)LayerUsageFlags.Renderable == 1);
            Debug.Assert((int)LayerUsageFlags.CastShadows == 2);
            Debug.Assert((int)LayerUsageFlags.ReceiveShadows == 4);
            Debug.Assert((int)LayerUsageFlags.RenderReceiveCastShadows == (1 | 2 | 4));

            var renderables = new ChiselRenderObjects[]
            {
                new ChiselRenderObjects()
                {
                    invalid = true
                },
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[1], containerTransform, gameObjectState, LayerUsageFlags.Renderable),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[2], containerTransform, gameObjectState, LayerUsageFlags.CastShadows),
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[3], containerTransform, gameObjectState, LayerUsageFlags.Renderable | LayerUsageFlags.CastShadows),
                new ChiselRenderObjects()
                {
                    invalid = true
                },
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[5], containerTransform, gameObjectState, LayerUsageFlags.Renderable | LayerUsageFlags.ReceiveShadows),
                new ChiselRenderObjects()
                {
                    invalid = true
                },
                ChiselRenderObjects.Create(kGeneratedMeshRendererNames[7], containerTransform, gameObjectState, LayerUsageFlags.Renderable | LayerUsageFlags.CastShadows | LayerUsageFlags.ReceiveShadows),
            };

            var meshRenderers = new MeshRenderer[]
            {
                renderables[1].meshRenderer,
                renderables[2].meshRenderer,
                renderables[3].meshRenderer,
                renderables[5].meshRenderer,
                renderables[7].meshRenderer
            };

            renderables[1].invalid = false;
            renderables[2].invalid = false;
            renderables[3].invalid = false;
            renderables[5].invalid = false;
            renderables[7].invalid = false;

            var debugHelpers       = new ChiselRenderObjects[kDebugHelperCount];
            var debugMeshRenderers = new MeshRenderer[kDebugHelperCount];

            for (int i = 0; i < kDebugHelperCount; i++)
            {
                debugHelpers[i]         = ChiselRenderObjects.Create(kGeneratedDebugRendererNames[i], containerTransform, gameObjectState, AssignMeshesJob.kGeneratedDebugRendererFlags[i].Item1, debugHelperRenderer: true);
                debugMeshRenderers[i]   = debugHelpers[0].meshRenderer;
                debugHelpers[i].invalid = false;
            }

            var result = new ChiselGeneratedObjects
            {
                generatedDataContainer = container,
                colliderContainer      = colliderContainer,
                colliders          = new ChiselColliderObjects[0],
                renderables        = renderables,
                meshRenderers      = meshRenderers,
                debugHelpers       = debugHelpers,
                debugMeshRenderers = debugMeshRenderers
            };

            Debug.Assert(IsValid(result));

            return(result);
        }