//! private GameObject createMocap(SceneNodeMocap node, Transform parentTransform) { // setup as node GameObject objMain = createNode(node, parentTransform); return(objMain); }
//! public static GameObject createMocap(SceneNodeMocap node, Transform parentTransform) { // setup as node GameObject objMain = NodeBuilderBasic.CreateNode(node, parentTransform); return(objMain); }
public static SceneNode ParseNode(NodeType nodeType, ref byte[] nodesByteData, ref int dataIdx) { if (nodeType == NodeType.MOCAP) { SceneNodeMocap sceneNodeMocap = SceneDataHandler.ByteArrayToStructure <SceneNodeMocap>(nodesByteData, ref dataIdx); return(sceneNodeMocap); } return(null); }
public static GameObject BuildNode(ref SceneNode node, Transform parent, GameObject obj) { if (node.GetType() == typeof(SceneNodeMocap)) { SceneNodeMocap nodeMocap = (SceneNodeMocap)Convert.ChangeType(node, typeof(SceneNodeMocap)); return(createMocap(nodeMocap, parent)); } return(null); }
private int createSceneGraphIter(Transform parent, int idx) { GameObject obj = null; // = new GameObject( scnObjKtn.rawNodeList[idx].name ); SceneNode node = sceneDataHandler.NodeList[idx]; if (node.GetType() == typeof(SceneNodeGeo)) { SceneNodeGeo nodeGeo = (SceneNodeGeo)Convert.ChangeType(node, typeof(SceneNodeGeo)); obj = createObject(nodeGeo, parent); } else if (node.GetType() == typeof(SceneNodeLight)) { SceneNodeLight nodeLight = (SceneNodeLight)Convert.ChangeType(node, typeof(SceneNodeLight)); obj = createLight(nodeLight, parent); } else if (node.GetType() == typeof(SceneNodeCam)) { SceneNodeCam nodeCam = (SceneNodeCam)Convert.ChangeType(node, typeof(SceneNodeCam)); obj = createCamera(nodeCam, parent); // make the camera editable nodeCam.editable = true; } else if (node.GetType() == typeof(SceneNodeMocap)) { SceneNodeMocap nodeMocap = (SceneNodeMocap)Convert.ChangeType(node, typeof(SceneNodeMocap)); obj = createMocap(nodeMocap, parent); // HACK SceneObject scnObj = obj.AddComponent <SceneObject>(); scnObj.isMocapTrigger = true; } else { obj = createNode(node, parent); } // add scene object to editable if (node.editable) { sceneEditableObjects.Add(obj); } // recursive call int idxChild = idx; for (int k = 1; k <= node.childCount; k++) { idxChild = createSceneGraphIter(obj.transform, idxChild + 1); } return(idxChild); }
private byte[] getNodesByteArrayV1100() { Byte[] nodesByteData = new byte[0]; foreach (SceneNode node in sceneDataHandler.NodeList) { byte[] nodeBinary; byte[] nodeTypeBinary; if (node.GetType() == typeof(SceneNodeGeo)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.GEO); SceneNodeGeo nodeGeo = (SceneNodeGeo)Convert.ChangeType(node, typeof(SceneNodeGeo)); // change to V1100 geo node SceneNodeGeoV1100 nodeGeoV1100 = new SceneNodeGeoV1100(); copyProperties(nodeGeo, nodeGeoV1100); nodeGeoV1100.materialId = -1; //PrintProperties(nodeGeoV1100); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeGeoV1100>(nodeGeoV1100); } else if (node.GetType() == typeof(SceneNodeLight)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.LIGHT); SceneNodeLight nodeLight = (SceneNodeLight)Convert.ChangeType(node, typeof(SceneNodeLight)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeLight>(nodeLight); } else if (node.GetType() == typeof(SceneNodeCam)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.CAMERA); SceneNodeCam nodeCam = (SceneNodeCam)Convert.ChangeType(node, typeof(SceneNodeCam)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeCam>(nodeCam); } else if (node.GetType() == typeof(SceneNodeMocap)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.MOCAP); SceneNodeMocap nodeMocap = (SceneNodeMocap)Convert.ChangeType(node, typeof(SceneNodeMocap)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeMocap>(nodeMocap); } else { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.GROUP); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNode>(node); } // concate arrays nodesByteData = SceneDataHandler.Concat <byte>(nodesByteData, nodeTypeBinary); nodesByteData = SceneDataHandler.Concat <byte>(nodesByteData, nodeBinary); } return(nodesByteData); }
private void convertNodesByteStream() { m_nodeList = new List <SceneNode>(); int dataIdx = 0; while (dataIdx < m_nodesByteData.Length - 1) { SceneNode node = new SceneNode(); int numValues = BitConverter.ToInt32(m_nodesByteData, dataIdx); dataIdx += size_int; //checkEndian(ref sliceInt); NodeType nodeType = (NodeType)numValues; switch (nodeType) { case NodeType.GROUP: SceneNode sceneNode = SceneDataHandler.ByteArrayToStructure <SceneNode>(m_nodesByteData, ref dataIdx); node = sceneNode; break; case NodeType.GEO: SceneNodeGeo sceneNodeGeo = SceneDataHandler.ByteArrayToStructure <SceneNodeGeo>(m_nodesByteData, ref dataIdx); node = sceneNodeGeo; break; case NodeType.LIGHT: SceneNodeLight sceneNodeLight = SceneDataHandler.ByteArrayToStructure <SceneNodeLight>(m_nodesByteData, ref dataIdx); node = sceneNodeLight; break; case NodeType.CAMERA: SceneNodeCam sceneNodeCamera = SceneDataHandler.ByteArrayToStructure <SceneNodeCam>(m_nodesByteData, ref dataIdx); node = sceneNodeCamera; break; case NodeType.MOCAP: SceneNodeMocap sceneNodeMocap = SceneDataHandler.ByteArrayToStructure <SceneNodeMocap>(m_nodesByteData, ref dataIdx); node = sceneNodeMocap; break; } m_nodeList.Add(node); } Array.Clear(m_nodesByteData, 0, m_nodesByteData.Length); m_nodesByteData = null; GC.Collect(); }
private void getNodesByteArray() { nodesByteData = new byte[0]; foreach (SceneNode node in nodeList) { byte[] nodeBinary; byte[] nodeTypeBinary; if (node.GetType() == typeof(SceneNodeGeo)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.GEO); SceneNodeGeo nodeGeo = (SceneNodeGeo)Convert.ChangeType(node, typeof(SceneNodeGeo)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeGeo>(nodeGeo); } else if (node.GetType() == typeof(SceneNodeLight)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.LIGHT); SceneNodeLight nodeLight = (SceneNodeLight)Convert.ChangeType(node, typeof(SceneNodeLight)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeLight>(nodeLight); } else if (node.GetType() == typeof(SceneNodeCam)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.CAMERA); SceneNodeCam nodeCam = (SceneNodeCam)Convert.ChangeType(node, typeof(SceneNodeCam)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeCam>(nodeCam); } else if (node.GetType() == typeof(SceneNodeMocap)) { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.MOCAP); SceneNodeMocap nodeMocap = (SceneNodeMocap)Convert.ChangeType(node, typeof(SceneNodeMocap)); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNodeMocap>(nodeMocap); } else { nodeTypeBinary = BitConverter.GetBytes((int)NodeType.GROUP); nodeBinary = SceneDataHandler.StructureToByteArray <SceneNode>(node); } // concate arrays nodesByteData = SceneDataHandler.Concat <byte>(nodesByteData, nodeTypeBinary); nodesByteData = SceneDataHandler.Concat <byte>(nodesByteData, nodeBinary); } }
private bool iterLocation(Transform location) { // check LOD and retur if not match if (location.gameObject.layer != lodLowLayer && location.gameObject.layer != lodMixedLayer) { return(false); } SceneNode node = new SceneNode(); // print("Location: " + location); if (location.GetComponent <Light>() != null) { SceneNodeLight nodeLight = new SceneNodeLight(); Light light = location.GetComponent <Light>(); nodeLight.intensity = light.intensity; nodeLight.color = new float[3] { light.color.r, light.color.g, light.color.b }; nodeLight.lightType = light.type; nodeLight.exposure = 0; nodeLight.angle = light.spotAngle; nodeLight.range = light.range; node = nodeLight; } else if (location.GetComponent <Camera>() != null) { SceneNodeCam nodeCamera = new SceneNodeCam(); Camera camera = location.GetComponent <Camera>(); nodeCamera.fov = camera.fieldOfView; nodeCamera.near = camera.nearClipPlane; nodeCamera.far = camera.farClipPlane; node = nodeCamera; } else if (location.GetComponent <MeshFilter>() != null) { SceneNodeGeo nodeGeo = new SceneNodeGeo(); nodeGeo.geoId = processGeometry(location.GetComponent <MeshFilter>().sharedMesh); if (location.GetComponent <Renderer>() != null && location.GetComponent <Renderer>().sharedMaterial != null) { Material mat = location.GetComponent <Renderer>().sharedMaterial; #if TRUNK // if materials's shader is not standard, add this material to material package. // Currently this will only get the material name and try to load it on client side. If this fails, it will fallback to Standard. nodeGeo.materialId = processMaterial(location.GetComponent <Renderer>().sharedMaterial); #endif if (mat.HasProperty("_Color")) { nodeGeo.color = new float[3] { mat.color.r, mat.color.g, mat.color.b }; } if (mat.HasProperty("_Glossiness")) { nodeGeo.roughness = mat.GetFloat("_Glossiness"); } if (mat.mainTexture != null) { Texture2D mainTex = (Texture2D)mat.mainTexture; nodeGeo.textureId = processTexture(mainTex); } else { nodeGeo.textureId = -1; } } else { nodeGeo.textureId = -1; } node = nodeGeo; } else if (location.GetComponent <SkinnedMeshRenderer>() != null) { SceneNodeGeo nodeGeo = new SceneNodeGeo(); nodeGeo.geoId = processGeometry(location.GetComponent <SkinnedMeshRenderer>().sharedMesh); if (location.GetComponent <SkinnedMeshRenderer>().material != null) { Material mat = location.GetComponent <SkinnedMeshRenderer>().material; if (mat.HasProperty("_Color")) { nodeGeo.color = new float[3] { mat.color.r, mat.color.g, mat.color.b }; } if (mat.HasProperty("_Glossiness")) { nodeGeo.roughness = mat.GetFloat("_Glossiness"); } if (mat.mainTexture != null) { Texture2D mainTex = (Texture2D)mat.mainTexture; nodeGeo.textureId = processTexture(mainTex); } else { nodeGeo.textureId = -1; } } else { nodeGeo.textureId = -1; } node = nodeGeo; } else if (location.parent.GetComponent <AnimatorObject>() != null) { SceneNodeMocap nodeMocap = new SceneNodeMocap(); node = nodeMocap; } node.editable = (location.gameObject.tag == "editable"); node.position = new float[3] { location.localPosition.x, location.localPosition.y, location.localPosition.z }; node.scale = new float[3] { location.localScale.x, location.localScale.y, location.localScale.z }; node.rotation = new float[4] { location.localRotation.x, location.localRotation.y, location.localRotation.z, location.localRotation.w }; node.name = Encoding.ASCII.GetBytes(location.name); //TODO: MAC Naming ccorrupted by this function? if (location.name != "root") { // print("Added: " + location.name); nodeList.Add(node); } // recursive children int childCounter = 0; if (location.childCount > 0) { foreach (Transform child in location) { if (!child.gameObject.activeSelf) { continue; } if (iterLocation(child)) { childCounter++; } } } node.childCount = childCounter; if (doAssignSceneObjects) { if (location.gameObject.tag == "editable") { #if UNITY_EDITOR // add recorder if (sceneName != "" && shotName != "" && takeName != "") { UnityAnimationRecorder animRecorder = location.gameObject.AddComponent <UnityAnimationRecorder>(); animRecorder.savePath = recordPath; animRecorder.fileName = String.Format("{0}_{1}_{2}_{3}", sceneName, shotName, takeName, location.name); animRecorder.showLogGUI = true; } #endif } else if (location.GetComponent <Light>() != null) { // Add light prefab GameObject lightUber = Resources.Load <GameObject>("VPET/Prefabs/UberLight"); GameObject _lightUberInstance = Instantiate(lightUber); _lightUberInstance.name = lightUber.name; _lightUberInstance.transform.SetParent(location, false); SceneNodeLight nodeLight = (SceneNodeLight)Convert.ChangeType(node, typeof(SceneNodeLight)); 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; lightComponent.spotAngle = Mathf.Min(150, nodeLight.angle); lightComponent.range = nodeLight.range; location.GetComponent <Light>().enabled = false; #if UNITY_EDITOR // add recorder if (sceneName != "" && shotName != "" && takeName != "") { UnityAnimationRecorder animRecorder = location.gameObject.AddComponent <UnityAnimationRecorder>(); animRecorder.savePath = recordPath; animRecorder.fileName = String.Format("{0}_{1}_{2}_{3}", sceneName, shotName, takeName, location.name); animRecorder.showLogGUI = true; } #endif } else if (location.GetComponent <Camera>() != null) { // add camera dummy mesh GameObject cameraObject = Resources.Load <GameObject>("VPET/Prefabs/cameraObject"); GameObject cameraInstance = Instantiate(cameraObject); cameraInstance.SetActive(false); cameraInstance.name = cameraObject.name; cameraInstance.transform.SetParent(location.transform, false); cameraInstance.transform.localScale = new Vector3(1, 1, 1); cameraInstance.transform.localPosition = new Vector3(0, 0, -0.5f); #if UNITY_EDITOR // add recorder if (sceneName != "" && shotName != "" && takeName != "") { UnityAnimationRecorder animRecorder = location.gameObject.AddComponent <UnityAnimationRecorder>(); animRecorder.savePath = recordPath; animRecorder.fileName = String.Format("{0}_{1}_{2}_{3}", sceneName, shotName, takeName, location.name); animRecorder.showLogGUI = true; } #endif } } return(true); }