Package com.ngt.jopenmetaverse.shared.structureddata

Examples of com.ngt.jopenmetaverse.shared.structureddata.OSDMap


                if (!meshAsset.Decode())
                {
                    return false;
                }

                OSDMap MeshData = meshAsset.MeshData;

                mesh[0] = new FacetedMesh();

                mesh[0].Faces = new ArrayList<Face>();
                mesh[0].Prim = prim;
                mesh[0].Profile.Faces = new ArrayList<ProfileFace>();
                mesh[0].Profile.Positions = new ArrayList<Vector3>();
                mesh[0].Path.Points = new ArrayList<PathPoint>();

                OSD facesOSD = null;

                switch (LOD)
                {
                    default:
                    case Highest:
                        facesOSD = MeshData.get("high_lod");
                        break;

                    case High:
                        facesOSD = MeshData.get("medium_lod");
                        break;

                    case Medium:
                        facesOSD = MeshData.get("low_lod");
                        break;

                    case Low:
                        facesOSD = MeshData.get("lowest_lod");
                        break;
                }

                if (facesOSD == null || !(facesOSD instanceof OSDArray))
                {
                    return false;
                }

                OSDArray decodedMeshOsdArray = (OSDArray)facesOSD;

                for (int faceNr = 0; faceNr < decodedMeshOsdArray.count(); faceNr++)
                {
                    OSD subMeshOsd = decodedMeshOsdArray.get(faceNr);

                    // Decode each individual face
                    if (subMeshOsd instanceof OSDMap)
                    {
                        Face oface = new Face();
                        oface.ID = faceNr;
                        oface.Vertices = new ArrayList<Vertex>();
                        oface.Indices = new ArrayList<Integer>();
                        oface.TextureFace = prim.Textures.GetFace(faceNr);

                        OSDMap subMeshMap = (OSDMap)subMeshOsd;

                        Vector3 posMax;
                        Vector3 posMin;

                        // If PositionDomain is not specified, the default is from -0.5 to 0.5
                        if (subMeshMap.containsKey("PositionDomain"))
                        {
                            posMax = ((OSDMap)subMeshMap.get("PositionDomain")).get("Max").asVector3();
                            posMin = ((OSDMap)subMeshMap.get("PositionDomain")).get("Min").asVector3();
                        }
                        else
                        {
                            posMax = new Vector3(0.5f, 0.5f, 0.5f);
                            posMin = new Vector3(-0.5f, -0.5f, -0.5f);
                        }

                        // Vertex positions
                        byte[] posBytes = subMeshMap.get("Position").asBinary();

                        // Normals
                        byte[] norBytes = null;
                        if (subMeshMap.containsKey("Normal"))
                        {
                            norBytes = subMeshMap.get("Normal").asBinary();
                        }

                        // UV texture map
                        Vector2 texPosMax = Vector2.Zero;
                        Vector2 texPosMin = Vector2.Zero;
                        byte[] texBytes = null;
                        if (subMeshMap.containsKey("TexCoord0"))
                        {
                            texBytes = subMeshMap.get("TexCoord0").asBinary();
                            texPosMax = ((OSDMap)subMeshMap.get("TexCoord0Domain")).get("Max").asVector2();
                            texPosMin = ((OSDMap)subMeshMap.get("TexCoord0Domain")).get("Min").asVector2();
                        }

                        // Extract the vertex position data
                        // If present normals and texture coordinates too
                        for (int i = 0; i < posBytes.length; i += 6)
                        {
                            int uX = Utils.bytesToUInt16(posBytes, i);
                            int uY = Utils.bytesToUInt16(posBytes, i + 2);
                            int uZ = Utils.bytesToUInt16(posBytes, i + 4);

                            Vertex vx = new Vertex();

                            vx.Position = new Vector3(
                                Utils.uint16ToFloat(uX, posMin.X, posMax.X),
                                Utils.uint16ToFloat(uY, posMin.Y, posMax.Y),
                                Utils.uint16ToFloat(uZ, posMin.Z, posMax.Z));

                            if (norBytes != null && norBytes.length >= i + 4)
                            {
                                int nX = Utils.bytesToUInt16(norBytes, i);
                                int nY = Utils.bytesToUInt16(norBytes, i + 2);
                                int nZ = Utils.bytesToUInt16(norBytes, i + 4);

                                vx.Normal = new Vector3(
                                    Utils.uint16ToFloat(nX, posMin.X, posMax.X),
                                    Utils.uint16ToFloat(nY, posMin.Y, posMax.Y),
                                    Utils.uint16ToFloat(nZ, posMin.Z, posMax.Z));
                            }

                            int vertexIndexOffset = oface.Vertices.size() * 4;

                            if (texBytes != null && texBytes.length >= vertexIndexOffset + 4)
                            {
                                int tX = Utils.bytesToUInt16(texBytes, vertexIndexOffset);
                                int tY = Utils.bytesToUInt16(texBytes, vertexIndexOffset + 2);

                                vx.TexCoord = new Vector2(
                                    Utils.uint16ToFloat(tX, texPosMin.X, texPosMax.X),
                                    Utils.uint16ToFloat(tY, texPosMin.Y, texPosMax.Y));
                            }

                            oface.Vertices.add(vx);
                        }

                        byte[] triangleBytes = subMeshMap.get("TriangleList").asBinary();
                        for (int i = 0; i < triangleBytes.length; i += 6)
                        {
                            int v1 = Utils.bytesToUInt16(triangleBytes, i);
                            oface.Indices.add(v1);
                            int v2 = Utils.bytesToUInt16(triangleBytes, i + 2);
View Full Code Here


        /// </summary>
        /// <param name="prims">Primitives to convert to a serializable object</param>
        /// <returns>An object that can be serialized with LLSD</returns>
        public static OSD PrimListToOSD(List<Primitive> prims)
        {
            OSDMap map = new OSDMap(prims.size());

            for (int i = 0; i < prims.size(); i++)
                map.put(Long.toString(prims.get(i).LocalID), prims.get(i).GetOSD());

            return map;
        }
View Full Code Here

        public static List<Primitive> OSDToPrimList(OSD osd)
        {
            if (osd.getType() != OSDType.Map)
                throw new IllegalArgumentException("LLSD must be in the Map structure");

            OSDMap map = (OSDMap)osd;
            List<Primitive> prims = new ArrayList<Primitive>(map.count());

            for(Map.Entry<String, OSD> kvp : map.entrySet())
            {
                Primitive prim = Primitive.FromOSD(kvp.getValue());
                prim.LocalID = Long.parseLong(kvp.getKey());
                prims.add(prim);
            }
View Full Code Here

    /// Serializes the message
    /// </summary>
    /// <returns>Serialized OSD</returns>
    public OSDMap Serialize()
    {
      OSDMap ret = new OSDMap();
      OSDArray array = new OSDArray();

      for (int i = 0; i < ObjectPhysicsProperties.length; i++)
      {
        array.add(ObjectPhysicsProperties[i].GetOSD());
      }

      ret.put("ObjectData", array);
      return ret;

    }
View Full Code Here

    /// Serialize the object
    /// </summary>
    /// <returns>An <see cref="OSDMap"/> containing the objects data</returns>
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(3);

      map.put("current_url", OSD.FromString(URL));
      map.put("object_id", OSD.FromUUID(PrimID));
      map.put("texture_index", OSD.FromInteger(Face));

      return map;
    }
View Full Code Here

    /// <returns>Serialized object as OSDMap</returns>

    @Override
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(2);
      map.put("object_id", OSD.FromUUID(PrimID));
      map.put("verb", OSD.FromString(Verb));
      return map;
    }
View Full Code Here

    /// <returns>Serialized object as OSDMap</returns>

    @Override
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(2);
      map.put("object_id", OSD.FromUUID(PrimID));

      if (FaceMedia == null)
      {
        map.put("object_media_data", new OSDArray());
      }
      else
      {
        OSDArray mediaData = new OSDArray(FaceMedia.length);

        for (int i = 0; i < FaceMedia.length; i++)
        {
          if (FaceMedia[i] == null)
            mediaData.add(new OSD());
          else
            mediaData.add(FaceMedia[i].GetOSD());
        }

        map.put("object_media_data", mediaData);
      }

      map.put("object_media_version", OSD.FromString(Version));
      return map;
    }
View Full Code Here

    /// <returns>Serialized object as OSDMap</returns>

    @Override
    public OSDMap Serialize()
    {
      OSDMap map = new OSDMap(2);
      map.put("object_id", OSD.FromUUID(PrimID));

      if (FaceMedia == null)
      {
        map.put("object_media_data", new OSDArray());
      }
      else
      {
        OSDArray mediaData = new OSDArray(FaceMedia.length);

        for (int i = 0; i < FaceMedia.length; i++)
        {
          if (FaceMedia[i] == null)
            mediaData.add(new OSD());
          else
            mediaData.add(FaceMedia[i].GetOSD());
        }

        map.put("object_media_data", mediaData);
      }

      map.put("verb", OSD.FromString(Verb));
      return map;
    }
View Full Code Here

      ID = obj.get("id").asUUID();
      Name = obj.get("name").asString();
      Location = obj.get("location").asVector3d();
      GroupOwned = obj.get("is_group_owned").asBoolean();
      OwnerID = obj.get("owner_id").asUUID();
      OSDMap resources = (OSDMap)obj.get("resources");
      Resources = new HashMap<String, Integer>(resources.keys().size());
      for (Entry<String, OSD> kvp : resources.entrySet())
      {
        Resources.put(kvp.getKey(), kvp.getValue().asInteger());
      }
    }
View Full Code Here

    public void Deserialize(OSDMap map)
    {
      SummaryAvailable = new HashMap<String, Integer>();
      SummaryUsed = new HashMap<String, Integer>();

      OSDMap summary = (OSDMap)map.get("summary");
      OSDArray available = (OSDArray)summary.get("available");
      OSDArray used = (OSDArray)summary.get("used");

      for (int i = 0; i < available.count(); i++)
      {
        OSDMap limit = (OSDMap)available.get(i);
        SummaryAvailable.put(limit.get("type").asString(), limit.get("amount").asInteger());
      }

      for (int i = 0; i < used.count(); i++)
      {
        OSDMap limit = (OSDMap)used.get(i);
        SummaryUsed.put(limit.get("type").asString(), limit.get("amount").asInteger());
      }
    }
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.structureddata.OSDMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.