Пример #1
0
        public override void OnInspectorGUI()
        {
            CogBlockVolumeRenderer renderer = target as CogBlockVolumeRenderer;

            float labelWidth = 120.0f;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Receive Shadows:", GUILayout.Width(labelWidth));
            renderer.receiveShadows = EditorGUILayout.Toggle(renderer.receiveShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cast Shadows:", GUILayout.Width(labelWidth));
            renderer.castShadows = EditorGUILayout.Toggle(renderer.castShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            renderer.material = EditorGUILayout.ObjectField("Material: ", renderer.material, typeof(Material), true) as Material;
            EditorGUILayout.EndHorizontal();



            if (!GUI.changed)
            {
                return;
            }

            CogBlockVolume vol = renderer.gameObject.GetComponentInChildren <CogBlockVolume>() as CogBlockVolume;

            if (vol != null)
            {
                //Debug.Log("GuiChange detected");
                //for some reason, trying to get the octreenode from here resulted in CATASTROPHIC MELTDOWN where OctreeNodeAlt reported no children.
                //Do I understand? Nupe. This works better anyway by talking only to volume
                vol.RelayComponentChanges = true;
            }
        }
Пример #2
0
        /// <summary>
        /// Synchronize this instance.
        /// </summary>
        protected override void Synchronize()
        {
            //super!
            base.Synchronize();


            //Not sure if this needs to be done every synchronization but okay
            CogBlockVolumeRenderer volRend = gameObject.GetComponent <CogBlockVolumeRenderer>();

            //initialize the volume renderer so that it's normals face in the correct direction
            if (volRend != null)            //I miss actionscript with lazy evaluation so I could string these all together in one big if..
            {
                if (volRend.material != null)
                {
                    // We compute surface normals using derivative operations in the fragment shader, but for some reason
                    // these are backwards on Linux. We can correct for this in the shader by setting the multiplier below.
                                        #if UNITY_STANDALONE_LINUX && !UNITY_EDITOR
                    float normalMultiplier = -1.0f;
                                        #else
                    float normalMultiplier = 1.0f;
                                        #endif
                    volRend.material.SetFloat("normalMultiplier", normalMultiplier);
                }
            }

            // Check to make sure we have anything to Synchronize
            if (data == null)
            {
                return;
            }

            //still checking
            if (!data.volumeHandle.HasValue)
            {
                return;
            }

            //update the volume
            CubiquityDLL.UpdateVolume(data.volumeHandle.Value);

            //try to synchronize the octrees
            if (CubiquityDLL.HasRootOctreeNode(data.volumeHandle.Value) == 1)
            {
                if (rootOctreeNode == null || rootOctreeNodeGameObject == null)
                {
                    //Debug.Log("Creating RootOctreeNode from null");
                    uint rootNodeHandle = CubiquityDLL.GetRootOctreeNode(data.volumeHandle.Value);
                    rootOctreeNode           = OctreeNodeAlt.CreateOctreeNode(typeof(CogBlockOctreeNode), rootNodeHandle, gameObject) as CogBlockOctreeNode;
                    rootOctreeNodeGameObject = rootOctreeNode.gameObject;
                }

                //Sync the Node and remember SyncNode will return syncs remaining. If some are remaining, the mesh is syncronized.
                isMeshSyncronized = (rootOctreeNode.SyncNode(maxNodesPerSync) != 0);

                //Where Sync nodes handles re-informed a bunch of nodes based on mesh changes, RelayComponentChanges assumes that something happened
                //which every node of the octree needs to know about. By setting this flag = true, we can relay those changes quickly down through the whole tree.
                //of course since RelayComponentChanges doesn't really 'yield' after a certain number of units are updated, it is important to realize this function is
                //called sparingly, usually only in edit mode, and should not perform incredibly complex per-update operations.
                if (RelayComponentChanges)
                {
                    rootOctreeNode.RelayComponentChanges();
                }
            }
        }