Esempio n. 1
0
    private static void UpdateGeometry(IEditorCylinderTargetBehaviour ct, float sideLength, float topDiameter, float bottomDiameter, bool hasTopGeometry, bool hasBottomGeometry)
    {
        GameObject   gameObject = ct.gameObject;
        MeshRenderer component  = gameObject.GetComponent <MeshRenderer>();

        if (component == null)
        {
            component = gameObject.AddComponent <MeshRenderer>();
        }
        component.hideFlags = HideFlags.NotEditable;
        MeshFilter filter = gameObject.GetComponent <MeshFilter>();

        if (filter == null)
        {
            filter = gameObject.AddComponent <MeshFilter>();
        }
        filter.hideFlags = HideFlags.NotEditable;
        Mesh mesh = CylinderMeshFactory.CreateCylinderMesh(sideLength, topDiameter, bottomDiameter, 0x20, hasTopGeometry, hasBottomGeometry, true);

        filter.sharedMesh = mesh;
        MaskOutAbstractBehaviour behaviour = gameObject.GetComponent <MaskOutAbstractBehaviour>();

        if (behaviour == null)
        {
            Material material = (Material)AssetDatabase.LoadAssetAtPath("Assets/Qualcomm Augmented Reality/Materials/DepthMask.mat", typeof(Material));
            behaviour = BehaviourComponentFactory.Instance.AddMaskOutBehaviour(gameObject);
            behaviour.maskMaterial = material;
        }
        behaviour.hideFlags = HideFlags.NotEditable;
        EditorUtility.UnloadUnusedAssets();
    }
    /// <summary>
    /// Create a mesh for a cylinder, cone, or conical frustum.
    /// </summary>
    /// <param name="sideLength">Distance between point on top circle and corresponding point on bottom circle. Height for cylinders, slant height for cones. </param>
    /// <param name="topDiameter">Top diameter. For an upward cone it is zero. For a cylinder it is equal to the bottom diameter.</param>
    /// <param name="bottomDiameter">Bottom diameter. For a downward cone it is zero. For a cylinder it is equal to the top diameter. </param>
    /// <param name="numPerimeterVertices">Tesselation of the mesh is defined by setting the number of vertices per circle.</param>
    /// <param name="hasTopGeometry">Define if optional top geometry should be generated.</param>
    /// <param name="hasBottomGeometry">Define if optional bottom geometry should be generated.</param>
    /// <returns></returns>
    public static Mesh CreateCylinderMesh(float sideLength, float topDiameter, float bottomDiameter, int numPerimeterVertices,
                                          bool hasTopGeometry, bool hasBottomGeometry, bool insideMaterial = false)
    {
        var factory = new CylinderMeshFactory(sideLength, topDiameter, bottomDiameter);

        return(factory.CreateCylinderMesh(numPerimeterVertices, hasTopGeometry, hasBottomGeometry, insideMaterial));
    }
    /// <summary>
    /// Updates CylinderTarget. Deletes all parts and recreates them.
    /// Creates a mesh with vertices, normals, and texture coordinates.
    /// Top and bottom geometry are represented as separate submeshes,
    /// i.e. resulting mesh contains 1, 2, or 3 submeshes.
    /// </summary>
    private static void UpdateGeometry(IEditorCylinderTargetBehaviour ct,
                                       float sideLength, float topDiameter, float bottomDiameter,
                                       bool hasTopGeometry, bool hasBottomGeometry)
    {
        GameObject gameObject = ct.gameObject;

        MeshRenderer meshRenderer = gameObject.GetComponent <MeshRenderer>();

        if (!meshRenderer)
        {
            meshRenderer = gameObject.AddComponent <MeshRenderer>();
        }
        //disable the editing functionality of meshRenderer in inspector UI
        meshRenderer.hideFlags = HideFlags.NotEditable;


        MeshFilter meshFilter = gameObject.GetComponent <MeshFilter>();

        if (!meshFilter)
        {
            meshFilter = gameObject.AddComponent <MeshFilter>();
        }
        //disable the editing functionality of meshFilter in inspector UI
        meshFilter.hideFlags = HideFlags.NotEditable;

        Mesh cylinderMesh = CylinderMeshFactory.CreateCylinderMesh(sideLength, topDiameter, bottomDiameter,
                                                                   NUM_PERIMETER_VERTICES, hasTopGeometry,
                                                                   hasBottomGeometry, INSIDE_MATERIAL);

        meshFilter.sharedMesh = cylinderMesh;

        //create and attach mask-out material (if not existing yet)
        MaskOutBehaviour script = gameObject.GetComponent <MaskOutBehaviour>();

        if (!script)
        {
            Material maskMaterial =
                (Material)AssetDatabase.LoadAssetAtPath(
                    QCARUtilities.GlobalVars.MASK_MATERIAL_PATH,
                    typeof(Material));

            script = gameObject.AddComponent <MaskOutBehaviour>();
            script.maskMaterial = maskMaterial;
        }
        //disable the editing functionality of the script in inspector UI
        script.hideFlags = HideFlags.NotEditable;


        // Cleanup assets that have been created temporarily.
        EditorUtility.UnloadUnusedAssets();
    }
 /// <summary>
 /// Create a mesh for a cylinder, cone, or conical frustum.
 /// </summary>
 /// <param name="sideLength">Distance between point on top circle and corresponding point on bottom circle. Height for cylinders, slant height for cones. </param>
 /// <param name="topDiameter">Top diameter. For an upward cone it is zero. For a cylinder it is equal to the bottom diameter.</param>
 /// <param name="bottomDiameter">Bottom diameter. For a downward cone it is zero. For a cylinder it is equal to the top diameter. </param>
 /// <param name="numPerimeterVertices">Tesselation of the mesh is defined by setting the number of vertices per circle.</param>
 /// <param name="hasTopGeometry">Define if optional top geometry should be generated.</param>
 /// <param name="hasBottomGeometry">Define if optional bottom geometry should be generated.</param>
 /// <returns></returns>
 public static Mesh CreateCylinderMesh(float sideLength, float topDiameter, float bottomDiameter, int numPerimeterVertices, 
     bool hasTopGeometry, bool hasBottomGeometry, bool insideMaterial = false)
 {
     var factory = new CylinderMeshFactory(sideLength, topDiameter, bottomDiameter);
     return factory.CreateCylinderMesh(numPerimeterVertices, hasTopGeometry, hasBottomGeometry, insideMaterial);
 }
    public static Mesh CreateCylinderMesh(float sideLength, float topDiameter, float bottomDiameter, int numPerimeterVertices, bool hasTopGeometry, bool hasBottomGeometry, [Optional, DefaultParameterValue(false)] bool insideMaterial)
    {
        CylinderMeshFactory factory = new CylinderMeshFactory(sideLength, topDiameter, bottomDiameter);

        return(factory.CreateCylinderMesh(numPerimeterVertices, hasTopGeometry, hasBottomGeometry, insideMaterial));
    }