public ModelLoadManager LoadLocal()
    {
        if (localPrefab != null)
        {
            // Load object specific content
            GameObject localModel = GameObject.Instantiate(localPrefab);
            localModel.name = "X3D Parent";
            Collider   collider = localModel.transform.GetChild(0).GetComponent <Collider>();
            ObjectInfo info     = localModel.GetComponent <ObjectInfo>();

            info.Bounds = collider.bounds;

            AttachementManager attachmentManager = localModel.AddComponent <AttachementManager>();
            attachmentManager.Init();

            CreateBoundingBox(localModel, info.Bounds);

            CreateGamificationGame(info.ModelName.ToLower());

            if (callback != null)
            {
                callback();
            }
        }
        else
        {
            Debug.Log("Tried to load local null model");
        }
        return(this);
    }
Esempio n. 2
0
    /// <summary>
    /// Creates Gameobjects from the pieces of the X3DObject
    /// </summary>
    /// <returns>The parent GameObject which contains all pieces as children</returns>
    public GameObject CreateGameObjects()
    {
        // create the parent object
        parent = new GameObject("X3D Parent");
        ObjectInfo objInfo = parent.AddComponent <ObjectInfo>();

        objInfo.ModelName = ModelName;

        AttachementManager attachementManager = parent.AddComponent <AttachementManager>();

        parentBounds = new Bounds();
        foreach (X3DPiece piece in pieces)
        {
            List <GameObject> pieceObjects = piece.CreateGameObject(shader);
            foreach (GameObject subObject in pieceObjects)
            {
                Renderer renderer = subObject.GetComponent <Renderer>();
                parentBounds.Encapsulate(renderer.bounds);
                // assign the parent
                subObject.transform.parent = parent.transform;
                // assign the TapNotifier; it can notfiy the parents about tap events
                TapNotifier tapNotifier = subObject.AddComponent <TapNotifier>();
            }
        }

        objInfo.Bounds = parentBounds;

        // initialize the attachement manager => this creates the annotation manager and informs the tap notifier
        attachementManager.Init();


        // normalize size so that maximum axis size is 1

        float max = Math.Max(Math.Max(parentBounds.size.x, parentBounds.size.y), parentBounds.size.z);

        float factor = 1 / max;


        parent.transform.localScale = new Vector3(
            parent.transform.localScale.x * factor,
            parent.transform.localScale.y * factor,
            parent.transform.localScale.z * factor);

        parentBounds.size *= factor;


        // reset any offset so that the object is centered
        parent.transform.localPosition -= parentBounds.center * factor;

        return(parent);
    }