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); }
//! //! function create the object from mesh data //! @param node object which holds the data //! @param parentTransform parent object //! private GameObject createLight(NodeLight nodeLight, Transform parentTransform) { // Tranform Vector3 pos = new Vector3(-nodeLight.position[0], nodeLight.position[1], nodeLight.position[2]); Quaternion rot = new Quaternion(-nodeLight.rotation[0], nodeLight.rotation[1], nodeLight.rotation[2], nodeLight.rotation[3]); Vector3 scl = new Vector3(nodeLight.scale[0], nodeLight.scale[1], nodeLight.scale[2]); // set up object basics GameObject objMain = new GameObject(); objMain.name = nodeLight.name; //place object objMain.transform.SetParent(parentTransform, false); objMain.transform.localPosition = pos; objMain.transform.localRotation = rot; objMain.transform.localScale = scl; // Add light prefab GameObject lightUber = Resources.Load <GameObject>("VPET/Prefabs/UberLight"); GameObject _lightUberInstance = Instantiate(lightUber); _lightUberInstance.name = lightUber.name; Light lightComponent = _lightUberInstance.GetComponent <Light>(); lightComponent.type = nodeLight.lightType; lightComponent.color = new Color(nodeLight.color[0], nodeLight.color[1], nodeLight.color[2]); lightComponent.intensity = nodeLight.intensity / VPETSettings.Instance.lightIntensityFactor; print("Create Light: " + nodeLight.name + " of type: " + ((LightTypeKatana)(nodeLight.lightType)).ToString() + " Intensity: " + nodeLight.intensity + " Pos: " + pos); // Add light specific settings if (nodeLight.lightType == LightType.Directional) { } else if (nodeLight.lightType == LightType.Spot) { lightComponent.spotAngle = Mathf.Min(150, nodeLight.angle); lightComponent.range = 200; } else if (nodeLight.lightType == LightType.Area) { lightComponent.spotAngle = Mathf.Min(150, nodeLight.angle); lightComponent.range = 200; } else { } // parent _lightUberInstance.transform.SetParent(objMain.transform, false); // add scene object for interactivity at the light quad SceneObject sco = objMain.AddComponent <SceneObject>(); sco.exposure = nodeLight.exposure; // TODO: what for ?? objMain.layer = 0; return(objMain); }