Exemplo n.º 1
0
        public void MoveTarget(DetourAgent agent, Vector3 target)
        {
            Assert.IsTrue(_crowd.Handle.ToInt64() != 0);
            Assert.IsTrue(_tileCache.NavQueryHandle.Handle.ToInt64() != 0);

            setMoveTarget(_tileCache.NavQueryHandle.Handle, _crowd.Handle, agent.ID, target.ToFloat(), false, agent.FilterIndex);
        }
Exemplo n.º 2
0
        public bool RandomValidPointInCircle(Vector3 cercleCenter, float maxRadius, ref Vector3 dest)
        {
            Assert.IsTrue(_crowd.Handle.ToInt64() != 0);

            if (randomPointInCircle(_crowd.Handle, cercleCenter.ToFloat(), maxRadius, randomSample))
            {
                dest = randomSample.ToVector3();
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        public void ConvertFromUnity()
        {
            ExporterWindow.ReportProgress(0, "Starting exportation process...");
            gameObjects = Object.FindObjectsOfType(typeof(GameObject)) as GameObject[];
            if (gameObjects.Length == 0)
            {
                ExporterWindow.ShowMessage("No gameobject! - Please add at least a gameobject to export");
                return;
            }

            // Create scene metadata
            SceneBuilder.Metadata = new SceneMetaData();

            // Parse all scene game objects
            var index = 0;
            var itemsCount = gameObjects.Length;
            var particleSystems = new List<BabylonExport.Entities.BabylonParticleSystem>();
            var lensFlareSystems = new List<UnityFlareSystem>();
            ExporterWindow.ReportProgress(0, "Exporting game objects from scene...");
            babylonScene.physicsEngine = (exportationOptions.DefaultPhysicsEngine == 1) ? "oimo" : "cannon";
            try
            {
                bool foundController = false;
                foreach (var gameObject in gameObjects)
                {
                    var progress = ((float)index / itemsCount);
                    index++;

                    // Unity metadata
                    var metaData = new UnityMetaData();
                    metaData.objectId = GetID(gameObject);
                    metaData.objectName = gameObject.name;
                    metaData.tagName = gameObject.tag;
                    metaData.layerIndex = gameObject.layer;
                    metaData.layerName = LayerMask.LayerToName(gameObject.layer);

                    // Export hooking
                    var exportObject = gameObject;
                    var exportOptions = exportationOptions;
                    BabylonScene sceneBuilder = babylonScene;
                    if (SceneController != null)
                    {
                        SceneController.OnExportGameObject(ref exportOptions, ref exportObject, ref metaData, ref sceneBuilder, OutputPath);
                    }

                    // Components tags
                    string componentTags = String.Empty;
                    if (!String.IsNullOrEmpty(gameObject.tag) && !gameObject.tag.Equals("Untagged", StringComparison.OrdinalIgnoreCase))
                    {
                        componentTags = gameObject.tag;
                    }

                    // Navigation area
                    metaData.areaIndex = -1;
                    bool navigationStatic = GameObjectUtility.AreStaticEditorFlagsSet(gameObject, StaticEditorFlags.NavigationStatic);
                    if (navigationStatic)
                    {
                        metaData.areaIndex = GameObjectUtility.GetNavMeshArea(gameObject);
                    }

                    // Navigation agent
                    metaData.navAgent = null;
                    var navigationAgent = gameObject.GetComponent<NavMeshAgent>();
                    if (navigationAgent != null)
                    {
                        componentTags += " [NAVAGENT]";
                        Dictionary<string, object> agentInfo = new Dictionary<string, object>();
                        agentInfo.Add("name", navigationAgent.name);
                        agentInfo.Add("radius", navigationAgent.radius);
                        agentInfo.Add("height", navigationAgent.height);
                        agentInfo.Add("speed", navigationAgent.speed);
                        agentInfo.Add("acceleration", navigationAgent.acceleration);
                        agentInfo.Add("angularSpeed", navigationAgent.angularSpeed);
                        agentInfo.Add("areaMask", navigationAgent.areaMask);
                        agentInfo.Add("autoBraking", navigationAgent.autoBraking);
                        agentInfo.Add("autoTraverseOffMeshLink", navigationAgent.autoTraverseOffMeshLink);
                        agentInfo.Add("avoidancePriority", navigationAgent.avoidancePriority);
                        agentInfo.Add("baseOffset", navigationAgent.baseOffset);
                        agentInfo.Add("obstacleAvoidanceType", navigationAgent.obstacleAvoidanceType.ToString());
                        agentInfo.Add("stoppingDistance", navigationAgent.stoppingDistance);
                        metaData.navAgent = agentInfo;
                    }

                    // Navigation link
                    metaData.meshLink = null;
                    var navigationLink = gameObject.GetComponent<OffMeshLink>();
                    if (navigationLink != null)
                    {
                        componentTags += " [MESHLINK]";
                        Dictionary<string, object> linkInfo = new Dictionary<string, object>();
                        linkInfo.Add("name", navigationLink.name);
                        linkInfo.Add("activated", navigationLink.activated);
                        linkInfo.Add("area", navigationLink.area);
                        linkInfo.Add("autoUpdatePositions", navigationLink.autoUpdatePositions);
                        linkInfo.Add("biDirectional", navigationLink.biDirectional);
                        linkInfo.Add("costOverride", navigationLink.costOverride);
                        linkInfo.Add("occupied", navigationLink.occupied);
                        linkInfo.Add("start", GetTransformPropertyValue(navigationLink.startTransform));
                        linkInfo.Add("end", GetTransformPropertyValue(navigationLink.endTransform));
                        metaData.meshLink = linkInfo;
                    }

                    // Navigation obstacle
                    metaData.meshObstacle = null;
                    var navigationObstacle = gameObject.GetComponent<NavMeshObstacle>();
                    if (navigationObstacle != null)
                    {
                        componentTags += " [MESHOBSTACLE]";
                        Dictionary<string, object> obstacleInfo = new Dictionary<string, object>();
                        obstacleInfo.Add("name", navigationObstacle.name);
                        obstacleInfo.Add("carving", navigationObstacle.carving);
                        obstacleInfo.Add("carveOnlyStationary", navigationObstacle.carveOnlyStationary);
                        obstacleInfo.Add("carvingMoveThreshold", navigationObstacle.carvingMoveThreshold);
                        obstacleInfo.Add("carvingTimeToStationary", navigationObstacle.carvingTimeToStationary);
                        obstacleInfo.Add("shape", navigationObstacle.shape.ToString());
                        obstacleInfo.Add("radius", navigationObstacle.radius);
                        obstacleInfo.Add("center", navigationObstacle.center.ToFloat());
                        obstacleInfo.Add("size", navigationObstacle.size.ToFloat());
                        metaData.meshObstacle = obstacleInfo;
                    }

                    // Tags component
                    var tagsComponent = gameObject.GetComponent<BabylonTagsComponent>();
                    if (tagsComponent != null)
                    {
                        if (!String.IsNullOrEmpty(tagsComponent.babylonTags))
                        {
                            componentTags += (" " + tagsComponent.babylonTags);
                        }
                    }

                    // Script components
                    var gameComponents = gameObject.GetComponents<BabylonScriptComponent>();
                    if (gameComponents != null)
                    {
                        var components = new List<object>();
                        foreach (var gameComponent in gameComponents)
                        {
                            Type componentType = gameComponent.GetType();
                            string componentName = componentType.FullName;
                            var component = new UnityScriptComponent();
                            MonoScript componentScript = MonoScript.FromMonoBehaviour(gameComponent);
                            component.order = MonoImporter.GetExecutionOrder(componentScript);
                            component.name = componentName;
                            component.klass = gameComponent.babylonClass;
                            component.update = (gameComponent.updateOption == BabylonTickOptions.EnableTick);
                            component.controller = (gameComponent is BabylonSceneController);
                            if (component.controller == true)
                            {
                                component.order = -1;
                                if (foundController == false)
                                {
                                    foundController = true;
                                    componentTags += " [CONTROLLER]";
                                    object userInterface = null;
                                    BabylonSceneController scx = (gameComponent as BabylonSceneController);
                                    EmbeddedAsset guiAsset = scx.sceneOptions.graphicUserInterface;
                                    if (guiAsset != null && scx.sceneOptions.userInterfaceMode != BabylonGuiMode.None)
                                    {
                                        userInterface = GetEmbeddedAssetPropertyValue(guiAsset);
                                    }
                                    SceneBuilder.Metadata.properties.Add("autoDraw", scx.sceneOptions.autoDrawInterface);
                                    SceneBuilder.Metadata.properties.Add("interfaceMode", scx.sceneOptions.userInterfaceMode.ToString());
                                    SceneBuilder.Metadata.properties.Add("userInterface", userInterface);
                                    SceneBuilder.Metadata.properties.Add("controllerPresent", true);
                                    SceneBuilder.Metadata.properties.Add("controllerObjectId", metaData.objectId);
                                }
                                else
                                {
                                    Debug.LogError("Duplicate scene controller detected: " + component.name);
                                }
                            }
                            FieldInfo[] componentFields = componentType.GetFields();
                            if (componentFields != null)
                            {
                                foreach (var componentField in componentFields)
                                {
                                    var componentAttribute = (BabylonPropertyAttribute)Attribute.GetCustomAttribute(componentField, typeof(BabylonPropertyAttribute));
                                    if (componentAttribute != null && componentField.Name != "babylonClass")
                                    {
                                        component.properties.Add(componentField.Name, GetComponentPropertyValue(componentField, gameComponent));
                                    }
                                }
                            }
                            gameComponent.OnExportProperties(ref exportOptions, ref exportObject, ref component.properties, OutputPath);
                            components.Add(component);
                        }
                        if (components.Count > 0)
                        {
                            metaData.components = components;
                        }
                    }

                    // Format tags
                    if (!String.IsNullOrEmpty(componentTags))
                    {
                        componentTags = componentTags.Trim();
                    }

                    // Audio sources
                    var audioComponents = gameObject.GetComponents<BabylonAudioSource>();
                    if (audioComponents != null)
                    {
                        foreach (var item in audioComponents)
                        {
                            if (item != null && item.exportAudio && item.sound != null)
                            {
                                string soundPath = AssetDatabase.GetAssetPath(item.sound);
                                if (!String.IsNullOrEmpty(soundPath))
                                {
                                    string soundName = Path.GetFileName(soundPath).Replace(" ", "");
                                    string outputFile = Path.Combine(OutputPath, soundName);
                                    if (File.Exists(soundPath))
                                    {
                                        File.Copy(soundPath, outputFile, true);
                                        var sound = new BabylonSound();
                                        sound.name = soundName;
                                        sound.volume = item.options.volume;
                                        sound.playbackRate = item.options.playbackRate;
                                        sound.autoplay = item.options.autoplay;
                                        sound.loop = item.options.loop;
                                        sound.soundTrackId = item.options.soundTrackId;
                                        sound.spatialSound = item.options.spatialSound;
                                        sound.position = item.options.position.ToFloat();
                                        sound.refDistance = item.options.refDistance;
                                        sound.rolloffFactor = item.options.rolloffFactor;
                                        sound.maxDistance = item.options.maxDistance;
                                        sound.distanceModel = item.options.distanceModel;
                                        sound.panningModel = item.options.panningModel;
                                        sound.isDirectional = item.options.isDirectional;
                                        sound.coneInnerAngle = item.options.coneInnerAngle;
                                        sound.coneOuterAngle = item.options.coneOuterAngle;
                                        sound.coneOuterGain = item.options.coneOuterGain;
                                        sound.localDirectionToMesh = item.options.directionToMesh.ToFloat();
                                        babylonScene.SoundsList.Add(sound);
                                    }
                                    else
                                    {
                                        Debug.LogError("Fail to locate audio file: " + soundPath);
                                    }
                                }
                                else
                                {
                                    Debug.LogError("Null audio clip path for: " + item.sound.name);
                                }
                            }
                        }
                    }

                    // Terrain meshes
                    var terrainMesh = gameObject.GetComponent<Terrain>();
                    if (terrainMesh != null)
                    {
                        ConvertUnityTerrainToBabylon(terrainMesh, gameObject, progress, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags);
                        continue;
                    }

                    // Collision meshes
                    BabylonMesh collisionMesh = null;
                    var collider = gameObject.GetComponent<Collider>();
                    if (collider != null)
                    {
                        if (collider.enabled)
                        {
                            int segments = 12;
                            BabylonColliderDetail detail = (BabylonColliderDetail)exportationOptions.DefaultColliderDetail;
                            var collisionData = new UnityMetaData();
                            collisionData.objectId = Guid.NewGuid().ToString();
                            collisionData.objectName = gameObject.name + "_Metadata";
                            if (collider is MeshCollider)
                            {
                                var meshCollider = collider as MeshCollider;
                                collisionMesh = new BabylonMesh();
                                collisionMesh.tags = "[MESHCOLLIDER]";
                                // Generate Mesh Collider Geometry
                                if(!meshCollider.sharedMesh)
                                {
                                    UnityEngine.Debug.LogWarning(meshCollider.gameObject+" has a Mesh Collider component without a mesh");
                                }
                                else
                                {
                                    Tools.GenerateBabylonMeshData(meshCollider.sharedMesh, collisionMesh);
                                }
                                collisionMesh.position = Vector3.zero.ToFloat();
                                collisionMesh.rotation = Vector3.zero.ToFloat();
                                float factorX = 1f, factorY = 1f, factorZ = 1f;
                                if (meshCollider.inflateMesh && meshCollider.skinWidth > 0f)
                                {
                                    Vector3 localScale = gameObject.transform.localScale;
                                    factorX += (meshCollider.skinWidth / localScale.x);
                                    factorY += (meshCollider.skinWidth / localScale.y);
                                    factorZ += (meshCollider.skinWidth / localScale.z);
                                }
                                collisionMesh.scaling = new Vector3(factorX, factorY, factorZ).ToFloat();
                                // Export Mesh Collider Metadata
                                collisionData.tagName = "MeshCollider";
                                collisionData.properties.Add("type", "Mesh");
                                collisionData.properties.Add("convex", meshCollider.convex);
                                collisionData.properties.Add("inflateMesh", meshCollider.inflateMesh);
                                collisionData.properties.Add("skinWidth", meshCollider.skinWidth);
                            }
                            else if (collider is CapsuleCollider)
                            {
                                var capsuleCollider = collider as CapsuleCollider;
                                collisionMesh = new BabylonMesh();
                                collisionMesh.tags = "[CAPSULECOLLIDER]";
                                switch (detail)
                                {
                                    case BabylonColliderDetail.FullResolution:
                                        segments = 48;
                                        break;
                                    case BabylonColliderDetail.HighResolution:
                                        segments = 32;
                                        break;
                                    case BabylonColliderDetail.MediumResolution:
                                        segments = 24;
                                        break;
                                    case BabylonColliderDetail.LowResolution:
                                        segments = 12;
                                        break;
                                    case BabylonColliderDetail.VeryLowResolution:
                                        segments = 8;
                                        break;
                                    case BabylonColliderDetail.MinimumResolution:
                                        segments = 6;
                                        break;
                                    default:
                                        segments = 12;
                                        break;
                                }
                                // Generate Capsule Collider Geometry
                                Mesh capsuleMesh = Tools.CreateCapsuleMesh(capsuleCollider.height, capsuleCollider.radius, segments);
                                Tools.GenerateBabylonMeshData(capsuleMesh, collisionMesh);
                                collisionMesh.position = new float[3];
                                collisionMesh.position[0] = capsuleCollider.center.x;
                                collisionMesh.position[1] = capsuleCollider.center.y;
                                collisionMesh.position[2] = capsuleCollider.center.z;
                                collisionMesh.rotation = new float[3];
                                collisionMesh.rotation[0] = (capsuleCollider.direction == 2) ? 90f * (float)Math.PI / 180f : 0f;
                                collisionMesh.rotation[1] = 0f;
                                collisionMesh.rotation[2] = (capsuleCollider.direction == 0) ? 90f * (float)Math.PI / 180f : 0f;
                                collisionMesh.scaling = new Vector3(1, 1, 1).ToFloat();
                                // Export Capsule Collider Metadata
                                collisionData.tagName = "CapsuleCollider";
                                collisionData.properties.Add("type", "Capsule");
                                collisionData.properties.Add("center", capsuleCollider.center.ToFloat());
                                collisionData.properties.Add("radius", capsuleCollider.radius);
                                collisionData.properties.Add("height", capsuleCollider.height);
                                collisionData.properties.Add("direction", capsuleCollider.direction);
                            }
                            else if (collider is SphereCollider)
                            {
                                var sphereCollider = collider as SphereCollider;
                                collisionMesh = new BabylonMesh();
                                collisionMesh.tags = "[SPHERECOLLIDER]";
                                switch (detail)
                                {
                                    case BabylonColliderDetail.FullResolution:
                                        segments = 48;
                                        break;
                                    case BabylonColliderDetail.HighResolution:
                                        segments = 32;
                                        break;
                                    case BabylonColliderDetail.MediumResolution:
                                        segments = 24;
                                        break;
                                    case BabylonColliderDetail.LowResolution:
                                        segments = 12;
                                        break;
                                    case BabylonColliderDetail.VeryLowResolution:
                                        segments = 8;
                                        break;
                                    case BabylonColliderDetail.MinimumResolution:
                                        segments = 6;
                                        break;
                                    default:
                                        segments = 12;
                                        break;
                                }
                                // Generate Sphere Collider Geometry
                                Mesh sphereMesh = Tools.CreateSphereMesh(sphereCollider.radius, segments);
                                Tools.GenerateBabylonMeshData(sphereMesh, collisionMesh);
                                collisionMesh.position = new float[3];
                                collisionMesh.position[0] = sphereCollider.center.x;
                                collisionMesh.position[1] = sphereCollider.center.y;
                                collisionMesh.position[2] = sphereCollider.center.z;
                                collisionMesh.rotation = Vector3.zero.ToFloat();
                                collisionMesh.scaling = new Vector3(1f, 1f, 1f).ToFloat();
                                // Export Sphere Collider Metadata
                                collisionData.tagName = "SphereCollider";
                                collisionData.properties.Add("type", "Sphere");
                                collisionData.properties.Add("center", sphereCollider.center.ToFloat());
                                collisionData.properties.Add("radius", sphereCollider.radius);
                            }
                            else if (collider is WheelCollider)
                            {
                                var wheelCollider = collider as WheelCollider;
                                collisionMesh = new BabylonMesh();
                                collisionMesh.tags = "[WHEELCOLLIDER]";
                                switch (detail)
                                {
                                    case BabylonColliderDetail.FullResolution:
                                        segments = 128;
                                        break;
                                    case BabylonColliderDetail.HighResolution:
                                        segments = 64;
                                        break;
                                    case BabylonColliderDetail.MediumResolution:
                                        segments = 48;
                                        break;
                                    case BabylonColliderDetail.LowResolution:
                                        segments = 32;
                                        break;
                                    case BabylonColliderDetail.VeryLowResolution:
                                        segments = 24;
                                        break;
                                    case BabylonColliderDetail.MinimumResolution:
                                        segments = 16;
                                        break;
                                    default:
                                        segments = 32;
                                        break;
                                }
                                // Generate Wheel Collider Geometry
                                Mesh wheelMesh = Tools.CreateWheelMesh(wheelCollider.suspensionDistance, wheelCollider.radius, segments);
                                Tools.GenerateBabylonMeshData(wheelMesh, collisionMesh);
                                collisionMesh.position = new float[3];
                                collisionMesh.position[0] = wheelCollider.center.x;
                                collisionMesh.position[1] = wheelCollider.center.y;
                                collisionMesh.position[2] = wheelCollider.center.z;
                                collisionMesh.rotation = new float[3];
                                collisionMesh.rotation[0] = 0f;
                                collisionMesh.rotation[1] = 0f;
                                collisionMesh.rotation[2] = 90f * (float)Math.PI / 180;
                                collisionMesh.scaling = new Vector3(1f, 1f, 1f).ToFloat();
                                // Export Wheel Collider Metadata
                                collisionData.tagName = "WheelCollider";
                                collisionData.properties.Add("type", "Wheel");
                                collisionData.properties.Add("center", wheelCollider.center.ToFloat());
                                collisionData.properties.Add("radius", wheelCollider.radius);
                            }
                            else if (collider is BoxCollider)
                            {
                                var boxCollider = collider as BoxCollider;
                                collisionMesh = new BabylonMesh();
                                collisionMesh.tags = "[BOXCOLLIDER]";
                                // Generate Box Collider Geometry
                                Mesh boxMesh = Tools.CreateBoxMesh(boxCollider.size.x, boxCollider.size.y, boxCollider.size.z);
                                Tools.GenerateBabylonMeshData(boxMesh, collisionMesh);
                                collisionMesh.position = new float[3];
                                collisionMesh.position[0] = boxCollider.center.x;
                                collisionMesh.position[1] = boxCollider.center.y;
                                collisionMesh.position[2] = boxCollider.center.z;
                                collisionMesh.rotation = Vector3.zero.ToFloat();
                                collisionMesh.scaling = new Vector3(1f, 1f, 1f).ToFloat();
                                // Export Box Collider Metadata
                                collisionData.tagName = "BoxCollider";
                                collisionData.properties.Add("type", "Box");
                                collisionData.properties.Add("center", boxCollider.center.ToFloat());
                                collisionData.properties.Add("size", boxCollider.size.ToFloat());
                            }
                            if (collisionMesh != null)
                            {
                                collisionMesh.id = Guid.NewGuid().ToString();
                                collisionMesh.name = gameObject.name + "_Collider";
                                // Default Check Collisions False
                                collisionMesh.checkCollisions = false;
                                collisionMesh.isVisible = false;
                                collisionData.properties.Add("parrentId", metaData.objectId);
                                collisionData.properties.Add("transform", GetTransformPropertyValue(gameObject.transform));
                                collisionMesh.metadata = collisionData;
                                babylonScene.MeshesList.Add(collisionMesh);
                                SceneBuilder.Metadata.properties["hasCollisionMeshes"] = true;
                            }
                        }
                    }

                    // Static meshes
                    var meshFilter = gameObject.GetComponent<MeshFilter>();
                    if (meshFilter != null)
                    {
                        ConvertUnityMeshToBabylon(meshFilter.sharedMesh, meshFilter.transform, gameObject, progress, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags, collisionMesh, collider);
                        continue;
                    }

                    // Skinned meshes
                    var skinnedMesh = gameObject.GetComponent<SkinnedMeshRenderer>();
                    if (skinnedMesh != null)
                    {
                        var babylonMesh = ConvertUnityMeshToBabylon(skinnedMesh.sharedMesh, skinnedMesh.transform, gameObject, progress, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags, collisionMesh, collider);
                        var skeleton = ConvertUnitySkeletonToBabylon(skinnedMesh.bones, skinnedMesh.sharedMesh.bindposes, skinnedMesh.transform, gameObject, progress);
                        babylonMesh.skeletonId = skeleton.id;
                        ExportSkeletonAnimation(skinnedMesh, babylonMesh, skeleton);
                        continue;
                    }

                    // Scene lights
                    var light = gameObject.GetComponent<Light>();
                    if (light != null)
                    {
                        ConvertUnityLightToBabylon(light, gameObject, progress, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags);
                        continue;
                    }

                    // Scene cameras
                    var camera = gameObject.GetComponent<Camera>();
                    if (camera != null)
                    {
                        ConvertUnityCameraToBabylon(camera, gameObject, progress, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags);
                        if (SceneController != null && SceneController.skyboxOptions.exportSkybox)
                        {
                            ConvertUnitySkyboxToBabylon(camera, progress);
                        }
                        continue;
                    }

                    // Empty objects
                    ConvertUnityEmptyObjectToBabylon(gameObject, ref metaData, ref particleSystems, ref lensFlareSystems, ref componentTags, collisionMesh, collider);
                }

                // Materials
                foreach (var mat in materialsDictionary)
                {
                    babylonScene.MaterialsList.Add(mat.Value);
                }
                foreach (var multiMat in multiMatDictionary)
                {
                    babylonScene.MultiMaterialsList.Add(multiMat.Value);
                }

                // Collisions
                if (exportationOptions.ExportCollisions)
                {
                    babylonScene.workerCollisions = exportationOptions.WorkerCollisions;
                    if (SceneController != null) {
                        babylonScene.gravity = SceneController.sceneOptions.defaultGravity.ToFloat();
                    }
                }

                // Babylon Physics
                if (exportationOptions.ExportPhysics)
                {
                    babylonScene.physicsEnabled = true;
                    if (SceneController != null) {
                        babylonScene.physicsGravity = SceneController.sceneOptions.defaultGravity.ToFloat();
                    }
                }

                // Scene Controller
                if (SceneController != null)
                {
                    Color ambientColor = SceneController.sceneOptions.ambientColor;
                    float ambientLevel = SceneController.lightingOptions.lightLevel;
                    Color ambientSpecular = SceneController.lightingOptions.specularColor;
                    babylonScene.autoClear = SceneController.sceneOptions.autoClear;
                    int fogmode = 0;
                    if (RenderSettings.fog)
                    {
                        switch (RenderSettings.fogMode)
                        {
                            case FogMode.Exponential:
                                fogmode = 1;
                                break;
                            case FogMode.ExponentialSquared:
                                fogmode = 2;
                                break;
                            case FogMode.Linear:
                                fogmode = 3;
                                break;
                        }
                    }
                    babylonScene.fogMode = fogmode;
                    babylonScene.fogDensity = RenderSettings.fogDensity;
                    babylonScene.fogColor = RenderSettings.fogColor.ToFloat();
                    babylonScene.fogStart = RenderSettings.fogStartDistance;
                    babylonScene.fogEnd = RenderSettings.fogEndDistance;
                    if (exportationOptions.DefaultLightmapMode != (int)BabylonLightmapMode.FullLightBaking && SceneController.lightingOptions.lightMode == BabylonAmbientLighting.UnityAmbientLighting)
                    {
                        var ambientLight = new BabylonLight
                        {
                            name = "Ambient Light",
                            id = Guid.NewGuid().ToString(),
                            parentId = null,
                            metadata = null,
                            position = null,
                            exponent = 1.0f,
                            angle = 0.0f,
                            type = 3
                        };
                        var ambientDirection = new Vector3(0.0f, 1.0f, 0.0f);
                        Color ambientDiffuse = (RenderSettings.ambientMode == UnityEngine.Rendering.AmbientMode.Skybox) ? RenderSettings.ambientSkyColor : RenderSettings.ambientLight;
                        ambientLight.intensity = RenderSettings.ambientIntensity * ambientLevel;
                        ambientLight.direction = ambientDirection.ToFloat(); ;
                        ambientLight.diffuse = ambientDiffuse.ToFloat();
                        ambientLight.specular = ambientSpecular.ToFloat();
                        ambientLight.groundColor = RenderSettings.ambientGroundColor.ToFloat();
                        babylonScene.ambientColor = ambientColor.ToFloat();
                        babylonScene.LightsList.Add(ambientLight);
                        ExporterWindow.ReportProgress(0, "Exporting ambient light intensity at: " + ambientLight.intensity.ToString());
                    }
                    if (SceneController.sceneOptions.navigationMesh == BabylonNavigationMesh.EnableNavigation)
                    {
                        ExporterWindow.ReportProgress(0, "Parsing scene navigation mesh...");
                        NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation();
                        if (triangulatedNavMesh.vertices != null && triangulatedNavMesh.vertices.Length > 0 && triangulatedNavMesh.indices != null && triangulatedNavMesh.indices.Length > 0)
                        {
                            int vertexCount = triangulatedNavMesh.vertices.Length;
                            if (vertexCount <= SceneBuilder.MAX_VERTEX_COUNT)
                            {
                                ExporterWindow.ReportProgress(0, "Generating navigation mesh vertices: " + vertexCount.ToString());
                                var navData = new UnityMetaData();
                                navData.type = "NavMesh";
                                navData.objectId = Guid.NewGuid().ToString();
                                navData.objectName = "Navigation_Mesh";
                                var areaTable = new List<object>();
                                string[] areaNavigation = GameObjectUtility.GetNavMeshAreaNames();
                                foreach (string areaName in areaNavigation)
                                {
                                    var bag = new Dictionary<string, object>();
                                    int areaIndex = NavMesh.GetAreaFromName(areaName);
                                    float areaCost = NavMesh.GetAreaCost(areaIndex);
                                    bag.Add("index", areaIndex);
                                    bag.Add("area", areaName);
                                    bag.Add("cost", areaCost);
                                    areaTable.Add(bag);
                                }
                                navData.properties.Add("table", areaTable);
                                navData.properties.Add("areas", triangulatedNavMesh.areas);

                                Mesh mesh = new Mesh();
                                mesh.name = "sceneNavigationMesh";
                                mesh.vertices = triangulatedNavMesh.vertices;
                                mesh.triangles = triangulatedNavMesh.indices;
                                mesh.RecalculateNormals();

                                BabylonMesh babylonMesh = new BabylonMesh();
                                babylonMesh.tags = "[NAVMESH]";
                                babylonMesh.metadata = navData;
                                babylonMesh.name = mesh.name;
                                babylonMesh.id = Guid.NewGuid().ToString();
                                babylonMesh.parentId = null;
                                babylonMesh.position = Vector3.zero.ToFloat();
                                babylonMesh.rotation = Vector3.zero.ToFloat();
                                babylonMesh.scaling = new Vector3(1, 1, 1).ToFloat();
                                babylonMesh.isVisible = false;
                                babylonMesh.visibility = 0.75f;
                                babylonMesh.checkCollisions = false;
                                Tools.GenerateBabylonMeshData(mesh, babylonMesh);
                                babylonScene.MeshesList.Add(babylonMesh);
                                SceneBuilder.Metadata.properties["hasNavigationMesh"] = true;
                            }
                            else
                            {
                                UnityEngine.Debug.LogError("Navigation mesh exceeds max (65000) vertex limit: " + vertexCount.ToString());
                            }
                        }
                    }
                    if (SceneController.sceneOptions.particleSystems)
                    {
                        if (particleSystems != null && particleSystems.Count > 0)
                        {
                            babylonScene.particleSystems = particleSystems.ToArray();
                        }
                    }
                    if (SceneController.sceneOptions.lensFlareSystems)
                    {
                        if (lensFlareSystems != null && lensFlareSystems.Count > 0)
                        {
                            var lfs_buffer = new List<BabylonLensFlareSystem>();
                            foreach (var ulfs in lensFlareSystems)
                            {
                                var lfs = new BabylonLensFlareSystem();
                                lfs.borderLimit = ulfs.borderLimit;
                                lfs.emitterId = ulfs.emitterId;
                                var lfx = new List<BabylonLensFlare>();
                                foreach (var ulf in ulfs.lensFlares)
                                {
                                    var lf = new BabylonLensFlare();
                                    lf.textureName = ulf.textureName;
                                    lf.position = ulf.position;
                                    lf.color = ulf.color;
                                    lf.size = ulf.size;
                                    lfx.Add(lf);
                                }
                                lfs.flares = lfx.ToArray();
                                lfs_buffer.Add(lfs);
                            }
                            babylonScene.lensFlareSystems = lfs_buffer.ToArray();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                babylonScene.metadata = SceneBuilder.Metadata;
            }
        }
Exemplo n.º 4
0
 public bool IsPointValid(Vector3 point)
 {
     return(isPointValid(_crowd.Handle, point.ToFloat()));
 }
Exemplo n.º 5
0
        public bool RandomValidPointInCircle(Vector3 cercleCenter, float maxRadius, ref Vector3 dest)
        {
            Assert.IsTrue(_crowd.Handle.ToInt64() != 0);

            if (randomPointInCircle(_crowd.Handle, cercleCenter.ToFloat(), maxRadius, randomSample))
            {
                dest = randomSample.ToVector3();
                return true;
            }

            return false;
        }
Exemplo n.º 6
0
 public bool IsPointValid(Vector3 point)
 {
     return isPointValid(_crowd.Handle, point.ToFloat());
 }
Exemplo n.º 7
0
        public void MoveTarget(DetourAgent agent, Vector3 target)
        {
            Assert.IsTrue(_crowd.Handle.ToInt64() != 0);
            Assert.IsTrue(_tileCache.NavQueryHandle.Handle.ToInt64() != 0);

            setMoveTarget(_tileCache.NavQueryHandle.Handle, _crowd.Handle, agent.ID, target.ToFloat(), false, agent.FilterIndex);
        }