Esempio n. 1
0
        //!
        //! function create the object from mesh data
        //! @param  node   object which holds the data
        //! @param  parentTransform   parent object
        //!
        private GameObject createCamera(NodeCam nodeCam, Transform parentTransform)
        {
            // Tranform
            Vector3    pos = new Vector3(-nodeCam.position[0], nodeCam.position[1], nodeCam.position[2]);
            Quaternion rot = new Quaternion(-nodeCam.rotation[0], nodeCam.rotation[1], nodeCam.rotation[2], nodeCam.rotation[3]);
            Vector3    scl = new Vector3(nodeCam.scale[0], nodeCam.scale[1], nodeCam.scale[2]);

            // set up object basics
            GameObject objMain = new GameObject();

            objMain.name = nodeCam.name;

            // add camera data script and set values
            CameraObject camScript = objMain.AddComponent <CameraObject>();

            camScript.fov  = nodeCam.fov;
            camScript.near = nodeCam.near;
            camScript.far  = nodeCam.far;

            // place camera
            objMain.transform.parent        = parentTransform;
            objMain.transform.localPosition = pos;
            objMain.transform.localRotation = rot;
            objMain.transform.localScale    = scl;
            // Rotate 180 around y-axis because lights and cameras have additional eye space coordinate system
            objMain.transform.Rotate(new Vector3(0, 180f, 0), Space.Self);

            // TODO: what for ??
            objMain.layer = 0;

            // add to list for later access as camera location
            sceneCameraList.Add(objMain);

            return(objMain);
        }
Esempio n. 2
0
        private int createSceneGraphIter(SceneObjectKatana scnObjKtn, Transform parent, int idx)
        {
            GameObject obj = null;     // = new GameObject( scnObjKtn.rawNodeList[idx].name );

            Node node = scnObjKtn.rawNodeList[idx];


            if (node.GetType() == typeof(NodeGeo))
            {
                NodeGeo nodeGeo = (NodeGeo)Convert.ChangeType(node, typeof(NodeGeo));
                obj = createObject(nodeGeo, parent);
            }
            else if (node.GetType() == typeof(NodeLight))
            {
                NodeLight nodeLight = (NodeLight)Convert.ChangeType(node, typeof(NodeLight));
                // HACK: remove and support skydomes
                if (nodeLight.name.ToLower() == "skydome")
                {
                    print("Do Support SkyDome !");
                }
                else
                {
                    obj = createLight(nodeLight, parent);
                }
            }
            else if (node.GetType() == typeof(NodeCam))
            {
                NodeCam nodeCam = (NodeCam)Convert.ChangeType(node, typeof(NodeCam));
                obj = createCamera(nodeCam, parent);
            }
            else
            {
                obj = createNode(node, parent);
            }

            if (node.editable)
            {
                sceneEditableObjects.Add(obj);
            }



            int idxChild = idx;

            for (int k = 1; k <= node.childCount; k++)
            {
                idxChild = createSceneGraphIter(scnObjKtn, obj.transform, idxChild + 1);
            }



            return(idxChild);
        }
    public bool parseNode(byte[] data)
    {
        int dataIdx = 0;

        byte[] sliceInt = new byte[size_int];

        while (dataIdx < data.Length - 1)
        {
            Array.Copy(data, dataIdx, sliceInt, 0, size_int);
            checkEndian(ref sliceInt);
            NodeType nodeType = (NodeType)BitConverter.ToInt32(sliceInt, 0);
            dataIdx += size_int;

            switch (nodeType)
            {
            case NodeType.GROUP:
                Node node = new Node();
                node.type = nodeType;
                node.Parse(ref data, ref dataIdx);
                rawNodeList.Add(node);
                break;

            case NodeType.GEO:
                NodeGeo nodeGeo = new NodeGeo();
                nodeGeo.type = nodeType;
                nodeGeo.Parse(ref data, ref dataIdx);
                rawNodeList.Add(nodeGeo);
                break;

            case NodeType.LIGHT:
                NodeLight nodeLight = new NodeLight();
                nodeLight.type = nodeType;
                nodeLight.Parse(ref data, ref dataIdx);
                rawNodeList.Add(nodeLight);
                break;

            case NodeType.CAMERA:
                NodeCam nodeCam = new NodeCam();
                nodeCam.type = nodeType;
                nodeCam.Parse(ref data, ref dataIdx);
                rawNodeList.Add(nodeCam);
                break;
            }

            // Debug.Log( "Process Node: " + rawNodeList[rawNodeList.Count-1].name );
        }

        return(true);
    }