public override void Parse(ref byte[] data, ref int dataIdx) { base.Parse(ref data, ref dataIdx); sliceValues = new byte[size_int]; Array.Copy(data, dataIdx, sliceValues, 0, size_int); SceneObjectKatana.checkEndian(ref sliceValues); geoId = BitConverter.ToInt32(sliceValues, 0); dataIdx += size_int; sliceValues = new byte[size_int]; Array.Copy(data, dataIdx, sliceValues, 0, size_int); SceneObjectKatana.checkEndian(ref sliceValues); textureId = BitConverter.ToInt32(sliceValues, 0); dataIdx += size_int; sliceValues = new byte[3 * size_float]; Array.Copy(data, dataIdx, sliceValues, 0, 3 * size_float); SceneObjectKatana.checkEndian(ref sliceValues); for (int i = 0; i < 3; i++) { color[i] = BitConverter.ToSingle(sliceValues, i * size_float); } dataIdx += 3 * size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); roughness = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; }
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 virtual void Parse(ref byte[] data, ref int dataIdx) { Array.Copy(data, dataIdx, sliceInt, 0, size_int); SceneObjectKatana.checkEndian(ref sliceInt); numValues = BitConverter.ToInt32(sliceInt, 0); dataIdx += size_int; sliceValues = new byte[numValues]; Array.Copy(data, dataIdx, sliceValues, 0, numValues); name = ASCIIEncoding.ASCII.GetString(data, dataIdx, numValues); dataIdx += numValues; sliceValues = new byte[3 * size_float]; Array.Copy(data, dataIdx, sliceValues, 0, 3 * size_float); SceneObjectKatana.checkEndian(ref sliceValues); for (int i = 0; i < 3; i++) { position[i] = BitConverter.ToSingle(sliceValues, i * size_float); } dataIdx += 3 * size_float; sliceValues = new byte[4 * size_float]; Array.Copy(data, dataIdx, sliceValues, 0, 4 * size_float); SceneObjectKatana.checkEndian(ref sliceValues); for (int i = 0; i < 4; i++) { rotation[i] = BitConverter.ToSingle(sliceValues, i * size_float); } dataIdx += 4 * size_float; // Debug.Log( name + ": " + rotation[0] + " " + rotation[1] + " " + rotation[2] + " " + rotation[3] ); sliceValues = new byte[3 * size_float]; Array.Copy(data, dataIdx, sliceValues, 0, 3 * size_float); SceneObjectKatana.checkEndian(ref sliceValues); for (int i = 0; i < 3; i++) { scale[i] = BitConverter.ToSingle(sliceValues, i * size_float); } dataIdx += 3 * size_float; sliceValues = new byte[size_int]; Array.Copy(data, dataIdx, sliceValues, 0, size_int); childCount = BitConverter.ToInt32(sliceValues, 0); dataIdx += size_int; sliceValues = new byte[sizeof(bool)]; Array.Copy(data, dataIdx, sliceValues, 0, sizeof(bool)); editable = BitConverter.ToBoolean(sliceValues, 0); dataIdx += sizeof(bool); }
//! //! function ?? //! @param ?? ?? //! private void createMeshes(SceneObjectKatana scnObjKtn) { for (int k = 0; k < scnObjKtn.rawVertexList.Count; k++) { // vertices Vector3[] verts = new Vector3[scnObjKtn.rawVertexList[k].Length / 3]; for (int i = 0; i < verts.Length; i++) { // convert handiness verts[i] = new Vector3(-scnObjKtn.rawVertexList[k][i * 3], scnObjKtn.rawVertexList[k][i * 3 + 1], scnObjKtn.rawVertexList[k][i * 3 + 2]); } // uvs Vector2 per vertex point Vector2[] uvs = new Vector2[verts.Length]; for (int i = 0; i < verts.Length; i++) { uvs[i] = new Vector2(scnObjKtn.rawUvList[k][i * 2], scnObjKtn.rawUvList[k][i * 2 + 1]); } // normals Vector3 per vertex point Vector3[] norms = new Vector3[verts.Length]; for (int i = 0; i < verts.Length; i++) { // convert handiness norms[i] = new Vector3(-scnObjKtn.rawNormalList[k][i * 3], scnObjKtn.rawNormalList[k][i * 3 + 1], scnObjKtn.rawNormalList[k][i * 3 + 2]); } // Triangles int[] tris = new int[scnObjKtn.rawIndexList[k].Length]; tris = scnObjKtn.rawIndexList[k]; //print( " verts length " + verts.Length ); createSplitMesh(verts, norms, uvs, tris); } /* * for( int i=0; i<sceneMeshList.Count; i++ ) * { * foreach( Mesh m in sceneMeshList[i] ) * { * GameObject obj = new GameObject(); * obj.AddComponent<MeshFilter>(); * obj.GetComponent<MeshFilter>().mesh = m; * obj.AddComponent<MeshRenderer>(); * } * } */ }
//! //! none //! public void sceneReceiverResource() { print("Trying to load scene."); OnProgress(0.1f, "Init Scene Receiver.."); SceneObjectKatana sceneObjectKatana = new SceneObjectKatana(); bool success = false; if (VPETSettings.Instance.doLoadTextures) { print("textu"); byte[] byteStreamTextures = loadBinary("textu"); print("byteStreamTextures size: " + byteStreamTextures.Length); success = sceneObjectKatana.parseTexture(byteStreamTextures); print("Texture Count: " + sceneObjectKatana.rawTextureList.Count); OnProgress(0.33f, "..Received Texture.."); } print("objec"); byte[] byteStreamObjects = loadBinary("objec"); print("byteStreamObjects size: " + byteStreamObjects.Length); success = sceneObjectKatana.parseObject(byteStreamObjects); print("Object Count: " + sceneObjectKatana.rawVertexList.Count); OnProgress(0.80f, "..Received Objects.."); print("nodes"); byte[] byteStreamNodes = loadBinary("nodes"); print("byteStreamNodess size: " + byteStreamNodes.Length); success = sceneObjectKatana.parseNode(byteStreamNodes); print("Node count: " + sceneObjectKatana.rawNodeList.Count); OnProgress(0.9f, "..Received Nodes.."); if (success) { receiveObjectQueue.Add(sceneObjectKatana); } print("done load scene"); OnProgress(1.0f, "..Building Scene.."); }
public override void Parse(ref byte[] data, ref int dataIdx) { base.Parse(ref data, ref dataIdx); sliceValues = new byte[size_int]; Array.Copy(data, dataIdx, sliceValues, 0, size_int); SceneObjectKatana.checkEndian(ref sliceValues); lightType = (LightType)BitConverter.ToInt32(sliceValues, 0); dataIdx += size_int; /* * char value = Convert.ToChar( data[dataIdx] ); * lightType = (LightType)int.Parse( value.ToString() ); * dataIdx += 1; */ sliceValues = new byte[3 * size_float]; Array.Copy(data, dataIdx, sliceValues, 0, 3 * size_float); SceneObjectKatana.checkEndian(ref sliceValues); for (int i = 0; i < 3; i++) { color[i] = BitConverter.ToSingle(sliceValues, i * size_float); } dataIdx += 3 * size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); intensity = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); angle = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); exposure = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; }
public void createSceneGraph(SceneObjectKatana scnObjKtn) { // create textures if (VPETSettings.Instance.doLoadTextures) { createTextures(scnObjKtn); } scnObjKtn.rawTextureList.Clear(); // create meshes createMeshes(scnObjKtn); scnObjKtn.rawVertexList.Clear(); scnObjKtn.rawIndexList.Clear(); scnObjKtn.rawNormalList.Clear(); scnObjKtn.rawUvList.Clear(); // iterate nodes createSceneGraphIter(scnObjKtn, scnRoot.transform, 0); scnObjKtn.rawNodeList.Clear(); // make editable foreach (GameObject g in sceneEditableObjects) { SceneObject sobj = g.GetComponent <SceneObject>(); if (sobj == null) { g.AddComponent <SceneObject>(); } } /* * Transform geoTransform = GameObject.Find( "geo" ).transform; * if ( geoTransform != null ) * { * print( "Set geo transform" ); * JoystickInput joystickScript = GameObject.Find( "JoystickInput" ).gameObject.GetComponent<JoystickInput>(); * joystickScript.WorldTransform = geoTransform; * } */ }
private void createTextures(SceneObjectKatana scnObjKtn) { foreach (byte[] tex in scnObjKtn.rawTextureList) { //print( "text byte size: " + tex.Length ); //GameObject obj = GameObject.CreatePrimitive( PrimitiveType.Plane ); //Material mat = new Material( Shader.Find( "Standard" ) ); Texture2D tex_2d = new Texture2D(16, 16, TextureFormat.DXT5Crunched, false); tex_2d.LoadImage(tex); //mat.SetTexture( "_MainTex", tex_2d ); //obj.GetComponent<Renderer>().material = mat; /* * if ( tex_2d.width > 1000 || tex_2d.height > 1000) * { * tex_2d.Resize( 64, 64, TextureFormat.RGB24, false ); * //tex_2d.Apply(); * } */ sceneTextureList.Add(tex_2d); } }
public override void Parse(ref byte[] data, ref int dataIdx) { base.Parse(ref data, ref dataIdx); sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); fov = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); near = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; sliceValues = new byte[size_float]; Array.Copy(data, dataIdx, sliceValues, 0, size_float); SceneObjectKatana.checkEndian(ref sliceValues); far = BitConverter.ToSingle(sliceValues, 0); dataIdx += size_float; }
//! //! receiver function, receiving the initial scene from the katana server (executed in separate thread) //! public void sceneReceiver() { //create NetMQ context NetMQContext ctx = NetMQContext.Create(); print("Trying to receive scene."); OnProgress(0.1f, "Init Scene Receiver.."); NetMQ.Sockets.RequestSocket sceneReceiver = ctx.CreateRequestSocket(); sceneReceiver.Connect("tcp://" + VPETSettings.Instance.serverIP + ":5565"); print("Server set up."); SceneObjectKatana sceneObjectKatana = new SceneObjectKatana(); bool success = false; if (VPETSettings.Instance.doLoadTextures) { print("textu"); sceneReceiver.Send("textu"); byte[] byteStreamTextures = sceneReceiver.Receive() as byte[]; print("byteStreamTextures size: " + byteStreamTextures.Length); success = sceneObjectKatana.parseTexture(byteStreamTextures); print("Texture Count: " + sceneObjectKatana.rawTextureList.Count); if (doWriteScene) { writeBinary(byteStreamTextures, "textu"); } OnProgress(0.33f, "..Received Texture.."); } print("objec"); sceneReceiver.Send("objec"); byte[] byteStreamObjects = sceneReceiver.Receive() as byte[]; print("byteStreamObjects size: " + byteStreamObjects.Length); success = sceneObjectKatana.parseObject(byteStreamObjects); print("Object Count: " + sceneObjectKatana.rawVertexList.Count); if (doWriteScene) { writeBinary(byteStreamObjects, "objec"); } OnProgress(0.80f, "..Received Objects.."); print("nodes"); sceneReceiver.Send("nodes"); byte[] byteStreamNodes = sceneReceiver.Receive() as byte[]; print("byteStreamNodess size: " + byteStreamNodes.Length); success = sceneObjectKatana.parseNode(byteStreamNodes); print("Node count: " + sceneObjectKatana.rawNodeList.Count); if (doWriteScene) { writeBinary(byteStreamNodes, "nodes"); } OnProgress(0.9f, "..Received Nodes.."); if (success) { receiveObjectQueue.Add(sceneObjectKatana); } sceneReceiver.Disconnect("tcp://" + VPETSettings.Instance.serverIP + ":5565"); sceneReceiver.Close(); print("done receive scene"); OnProgress(1.0f, "..Building Scene.."); }