Ejemplo n.º 1
0
        public void AddTriangle(MeshFilter mf, Triangle t)
        {
            Triangles.Add(t);
            List <Triangle> triList;

            if (!MeshFilterTriangles.TryGetValue(mf.GetInstanceID(), out triList))
            {
                triList = new List <Triangle>();
                MeshFilterTriangles.Add(mf.GetInstanceID(), triList);
            }
            triList.Add(t);
        }
Ejemplo n.º 2
0
        public override void From(Object component)
        {
            MeshFilter meshFilter = (MeshFilter)component;

            mesh       = meshFilter.sharedMesh;
            instanceID = meshFilter.GetInstanceID();
        }
 /// <summary>
 /// Remove the corresponding mesh filter's geometry from Spatial Audio.
 /// </summary>
 /// <param name="meshFilter"></param>
 static public void RemoveGeometrySet(MeshFilter meshFilter)
 {
     if (meshFilter != null)
     {
         AkSoundEngine.RemoveGeometry((ulong)meshFilter.GetInstanceID());
     }
 }
        public override void AddTo(ref JSONObject instanceIDs, ref JSONObject resources)
        {
            JSONObject data         = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject materialJson = material.ToJSONObject();

            data.AddField("instanceID", instanceID.ToString());
            data.AddField("type", "MeshRenderer");
            data.AddField("meshFilter", meshFilter.GetInstanceID().ToString());
            data.AddField("material", material.GetInstanceID().ToString());
            data.AddField("castShadows", castShadows);
            data.AddField("receiveShadows", receiveShadows);

            instanceIDs.Add(instanceID.ToString());
            resources.SetField(instanceID.ToString(), data);
            resources.SetField(material.GetInstanceID().ToString(), materialJson);
        }
Ejemplo n.º 5
0
        public void RemoveTriangles(MeshFilter mf)
        {
            List <Triangle> triList;

            if (MeshFilterTriangles.TryGetValue(mf.GetInstanceID(), out triList))
            {
                for (int i = 0; i < triList.Count; i++)
                {
                    Triangles.Remove(triList[i]);
                }
                triList.Clear();
            }
            for (int i = 0; i < Children.Count; i++)
            {
                Children[i].RemoveTriangles(mf);
            }
        }
    /// <summary>
    /// Sends the mesh filter's triangles and their acoustic texture to Spatial Audio
    /// </summary>
    /// <param name="acousticTexture"></param>
    /// <param name="meshFilter"></param>
    static public void AddGeometrySet(AK.Wwise.AcousticTexture acousticTexture, MeshFilter meshFilter)
    {
        if (meshFilter == null)
        {
            Debug.Log(meshFilter.name + ": No mesh found!");
        }
        else
        {
            Mesh      mesh      = meshFilter.sharedMesh;
            Vector3[] vertices  = mesh.vertices;
            int[]     triangles = mesh.triangles;

            int count = mesh.triangles.Length / 3;
            using (AkTriangleArray triangleArray = new AkTriangleArray(count))
            {
                for (int i = 0; i < count; ++i)
                {
                    using (var triangle = triangleArray.GetTriangle(i))
                    {
                        Vector3 point0 = meshFilter.transform.TransformPoint(vertices[triangles[3 * i + 0]]);
                        Vector3 point1 = meshFilter.transform.TransformPoint(vertices[triangles[3 * i + 1]]);
                        Vector3 point2 = meshFilter.transform.TransformPoint(vertices[triangles[3 * i + 2]]);

                        triangle.point0.X = point0.x;
                        triangle.point0.Y = point0.y;
                        triangle.point0.Z = point0.z;

                        triangle.point1.X = point1.x;
                        triangle.point1.Y = point1.y;
                        triangle.point1.Z = point1.z;

                        triangle.point2.X = point2.x;
                        triangle.point2.Y = point2.y;
                        triangle.point2.Z = point2.z;

                        triangle.textureID            = (uint)acousticTexture.ID;
                        triangle.reflectorChannelMask = unchecked ((uint)(-1));

                        triangle.strName = meshFilter.gameObject.name + "_" + i;
                    }
                }

                AkSoundEngine.SetGeometry((ulong)meshFilter.GetInstanceID(), triangleArray, (uint)count);
            }
        }
    }
Ejemplo n.º 7
0
 public static string MakeInstName(MeshFilter aFilter)
 {
     return(string.Format("{0}{1}_{2}", cProcMeshPrefix, aFilter.gameObject.name, aFilter.GetInstanceID()));
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Add a ModelDataDescriptors of the mesh inside the transform to the
    /// commandDescriptor
    /// </summary>
    /// <param name="transform">
    /// Transform, which is searched for possible meshes.
    /// </param>
    /// <param name="useAllChildNodes">
    /// If true: Also process child nodes, which are administered by another
    /// VLModelTrackableBehaviour
    /// </param>
    /// <param name="addDataDescriptor">
    /// Fills the ModelDataDescriptor with a DataDescriptor, a description of the
    /// data structure of the model data.
    /// </param>
    /// <param name="commandDescriptor">
    /// Reference to the command structure of the json command, which will be
    /// filled by this function.
    /// </param>
    /// <returns><c>True</c> if the model could be serialized into the visionlib.</c>False</c> if the data could not be gathered.</returns>
    private bool AddModelDescription(
        Transform transform,
        bool useAllChildNodes,
        bool addDataDescription,
        ref AddModelDataCommandDescription commandDescriptor)
    {
        // If transform is not active, do not add the model
        if (!transform.gameObject.activeInHierarchy)
        {
            return(false);
        }

        // See if another VLModelTrackableBehaviour is active in this transform. If
        // this is the case, break execution of this node and its children.
        VLModelTrackableBehaviour trackable =
            transform.GetComponent <VLModelTrackableBehaviour>();

        if (!useAllChildNodes &&
            trackable &&
            trackable != this &&
            trackable.enabled)
        {
            return(false);
        }
        if (trackable == null)
        {
            trackable = this;
        }


        Quaternion rotation    = transform.rotation;
        Vector3    globalScale = GetGlobalScale(transform);
        Vector3    position    = transform.position;

        // On HoloLens, the content node is added to the camera and thus the
        // transformation of the mesh will be changed. This change has to be
        // removed when streaming the data into the vlSDK
        Transform contentTransform = getContentTransform();

        if (contentTransform != null)
        {
            Vector3 contentGlobalScale = GetGlobalScale(contentTransform);
            rotation =
                Quaternion.Inverse(contentTransform.rotation) * rotation;
            globalScale = new Vector3(
                globalScale.x / contentGlobalScale.x,
                globalScale.y / contentGlobalScale.y,
                globalScale.z / contentGlobalScale.z);
            position =
                Quaternion.Inverse(contentTransform.rotation) *
                (position - contentTransform.position);
        }

        VLUnityCameraHelper.ToVLInPlace(ref position, ref rotation, modelTrackerBehaviour.workerBehaviour.flipCoordinateSystemHandedness);

        MeshFilter mesh = transform.GetComponent <MeshFilter>();
        string     uniqueUnityModelID = mesh.GetInstanceID().ToString();

        ModelTransform modelTransform = new ModelTransform();

        modelTransform.t = new float[] { position.x, position.y, position.z };
        modelTransform.s = new float[]
        { globalScale.x, globalScale.y, globalScale.z };
        modelTransform.q = new float[]
        { rotation.x, rotation.y, rotation.z, rotation.w };

        ModelDataDescriptor descriptor = new ModelDataDescriptor();

        descriptor.name      = uniqueUnityModelID;
        descriptor.type      = "model";
        descriptor.enabled   = trackable.useForTracking;
        descriptor.occluder  = trackable.occluder;
        descriptor.transform = modelTransform;
        if (addDataDescription)
        {
            descriptor.subModels = new BinaryDataDescriptor[]
            { CreateDataDescriptor(mesh) };
        }

        commandDescriptor.models.Add(descriptor);

        return(true);
    }