Beispiel #1
0
        private bool CreatePrim(ref JsonObjectUpdated update)
        {
            SimData data;
            if (!Ox.DataStore.World.SimCollection.TryGet(update.simID, out data)) return false;

            ObjectData objectData;
            if (!data.PrimCollection.TryGet(update.id, out objectData)) return false;

            PrimData primData;
            if (!(objectData is PrimData))
                return false;

            primData = objectData as PrimData;

            if (!primData.Loaded)
                return false;

            SceneNode node = null;
            if (list.ContainsKey(update.id))
            {
                node = list[update.id];
                list.Remove(update.id);
            }

            if (string.IsNullOrEmpty(primData.SceneName))
            {
                if (primData.Meshes == null)
                    return false;

                // If node isn't null, Update mesh.
                if (node == null)
                {
                    Mesh mesh = CreateMesh(primData.Meshes);
                    if (mesh == null)
                        return false;

                    node = Render.Scene.AddMeshSceneNode(mesh, Root, -1);
                    node.TriangleSelector = Render.Scene.CreateTriangleSelector(mesh, node);
                    //node.DebugDataVisible = DebugSceneType.BoundingBox;
                }
                else
                {
                    if (node is MeshSceneNode)
                    {
                        MeshSceneNode msn = node as MeshSceneNode;
                        Mesh mesh = msn.GetMesh();
                        msn.SetMesh(UpdateMesh(primData.Meshes, mesh));
                    }
                }

                if (node == null)
                    return false;
            }
            else
            {
                node = Render.Scene.AddEmptySceneNode(Root, -1);
                if (node == null)
                    return false;

                string path = Path.Combine(Ox.Paths.Cache, primData.SceneName);
                if (File.Exists(path))
                {
                    string tmp = Directory.GetCurrentDirectory();
                    Directory.SetCurrentDirectory(Ox.Paths.Cache);
                    Render.Scene.LoadScene(primData.SceneName, node);
                    Directory.SetCurrentDirectory(tmp);
                }
            }

            list.Add(update.id, node);

            return true;
        }
Beispiel #2
0
        private void UpdatePrim(ref JsonObjectUpdated update)
        {
            if (!list.ContainsKey(update.id))
                if (!CreatePrim(ref update))
                    return;

            SceneNode node = list[update.id];

            SimData data;
            if (!Ox.DataStore.World.SimCollection.TryGet(update.simID, out data))
                return;

            ObjectData objectData;
            if (!data.PrimCollection.TryGet(update.id, out objectData))
                return;

            if (!string.IsNullOrEmpty(objectData.ParentID))
            {
                if (!data.Contaion(objectData.ParentID))
                {
                    node.Visible = false;
                    return;
                }
            }

            PrimData primData = null;
            if (!(objectData is PrimData))
                return;

            primData = objectData as PrimData;
            if (string.IsNullOrEmpty(primData.SceneName))
            {
                node.Rotation = Util.ToRotationRH(objectData.Rotation);

                if (node is MeshSceneNode)
                    UpdateBoundingBox((node as MeshSceneNode));

                node.Scale = Util.ToVector3D(objectData.Scale);
            }
            else
            {
                node.Rotation = Util.ToRotationRH(new float[]{
                    objectData.Rotation[0] + Util.ROTATION_OFFSET.X,
                    objectData.Rotation[1] + Util.ROTATION_OFFSET.Y,
                    objectData.Rotation[2] + Util.ROTATION_OFFSET.Z});

                node.Scale = Util.ToScale(objectData.Scale);
            }
            node.Position = Util.ToPositionRH(objectData.Position);
            node.Visible = true;
        }
Beispiel #3
0
        private void UpdateAvatarAnimation(ref JsonObjectUpdated update)
        {
            if (!list.ContainsKey(update.id))
                return;

            ObjectData objectData;
            if (!Ox.DataStore.World.SimCollection.TryGetObject(update.simID, update.id, out objectData))
                return;

            AvatarData avatar;
            if (!(objectData is AvatarData))
                return;

            avatar = objectData as AvatarData;

            if (avatar.Animations == null)
                return;

            int seq = -1;
            string animationID = string.Empty;
            foreach (AvatarData.Animation animation in avatar.Animations)
            {
                if (string.IsNullOrEmpty(animation.id))
                    continue;

                if (seq < animation.sequenceID)
                {
                    seq = animation.sequenceID;
                    animationID = animation.id;
                }
            }

            if (string.IsNullOrEmpty(animationID))
                return;

            string key = AK.GetNameFromKey(animationID);

            AvatarAnimationData aad = list[update.id].Animation;
            if (aad == null)
                return;

            aad.Request(key);
        }
Beispiel #4
0
        private void UpdateAvatar(ref JsonObjectUpdated update)
        {
            if (!list.ContainsKey(update.id))
                CreateAvatar(ref update);

            ObjectData objectData;
            if (!Ox.DataStore.World.SimCollection.TryGetObject(update.simID, update.id, out objectData))
                return;

            AvatarData avatar;
            if (!(objectData is AvatarData))
                return;

            avatar = objectData as AvatarData;

            AnimatedMeshSceneNode node = list[update.id].Node;

            Vector3D position = Util.ToPositionRH(avatar.Position) + AVATAR_OFFSET;
            if (list[update.id].Move == null)
            {
                list[update.id].Move = new AvatarMoveData(ref position);
                node.Position = position;
            }
            AvatarMoveData move = list[update.id].Move;

            bool sync = false;
            // position must sync when avatar is sitting
            sync |= !string.IsNullOrEmpty(avatar.ParentID);
            // position must sync when avatar teleported
            //sync |= teleport-flag;

            if (sync)
            {
                move.Current = position;
            }

            float length = MathHelper.Length(avatar.Velocity);
            move.Update(ref position, length);

            if (avatar.Myself)
            {
                Render.RenderData.AgentPosition = position;

                node.Rotation = Util.ToRotationRH(new float[] {
                    0 + Util.ROTATION_AND_3DS_OFFSET.X,
                    0 + Util.ROTATION_AND_3DS_OFFSET.Y,
                    (float)(Ox.DataStore.World.Agent.Head * NewMath.RADTODEG) + Util.ROTATION_AND_3DS_OFFSET.Z
                });
            }
            else
            {
                node.Rotation = Util.ToRotationRH(new float[] {
                    avatar.Rotation[0] + Util.ROTATION_AND_3DS_OFFSET.X,
                    avatar.Rotation[1] + Util.ROTATION_AND_3DS_OFFSET.Y,
                    avatar.Rotation[2] + Util.ROTATION_AND_3DS_OFFSET.Z });
            }
        }
Beispiel #5
0
        private void CreateAvatar(ref JsonObjectUpdated update)
        {
            if (list.ContainsKey(update.id))
                return;

            AnimatedMesh mesh = Render.Scene.GetMesh(Path.Combine(dir, DEFAULT_MODEL_FILENAME));
            if (mesh == null) return;

            AnimatedMeshSceneNode node = Render.Scene.AddAnimatedMeshSceneNode(mesh);
            if (node == null) return;

            Root.AddChild(node);
            node.Name = update.id;
            node.Scale = new Vector3D(0.012f, 0.012f, 0.012f);
            node.AnimationSpeed = 30;
            node.SetFrameLoop(187, 217);
            node.SetTransitionTime(0.15f);
            node.AnimationEnd += new AnimationEnd(node_AnimationEnd);
            //node.DebugDataVisible = DebugSceneType.BoundingBox;

            Data data = new Data();
            data.Animation = new AvatarAnimationData();
            data.Animation.Parse(Path.Combine(dir, DEFAULT_MODEL_ANIMATION_FILENAME));
            data.Node = node;

            ObjectData objectData;
            if (!Ox.DataStore.World.SimCollection.TryGetObject(update.simID, update.id, out objectData))
                return;

            AvatarData avatar;
            if (!(objectData is AvatarData))
                return;

            avatar = objectData as AvatarData;
            avatar.UpdateAnimation(new AvatarData.Animation[] { new AvatarData.Animation(AK.GetKeyFromName(AnimationType.Standing.ToString()), 0) });

            list.Add(update.id, data);

            if (update.id == Ox.DataStore.World.Agent.ID)
            {
                string[] animations = data.Animation.GetAnimationNames();
                Ox.EventFire(JsonUtil.SerializeMessage(JsonType.AgentAnimationList, new JsonAgentAnimationList(update.id, animations)), true);
            }
        }
Beispiel #6
0
        private void UpdateObject(ref JsonObjectUpdated j)
        {
            SimData data;
            if (!Ox.DataStore.World.SimCollection.TryGet(j.simID, out data))
                return;

            ObjectData objectData;
            if (!data.TryGet(j.id, out objectData))
                return;

            ObjectData parentData = null;
            if (!string.IsNullOrEmpty(objectData.ParentID))
            {
                if (data.Contaion(objectData.ParentID))
                {
                    if (!data.TryGet(objectData.ParentID, out parentData))
                        return;
                }
                else
                    return;
            }

            Q qo = new Q(objectData.OQuaternion[0], objectData.OQuaternion[1], objectData.OQuaternion[2], objectData.OQuaternion[3]);
            if (parentData == null)
            {
                for (int i = 0; i < objectData.OPosition.Length; i++)
                    objectData.Position[i] = objectData.OPosition[i];
            }
            else
            {
                Q qp = new Q(parentData.OQuaternion[0], parentData.OQuaternion[1], parentData.OQuaternion[2], parentData.OQuaternion[3]);
                qo = qo * qp;

                float[] v = MathHelper.RotateVect(qp.Matrix, objectData.OPosition);
                objectData.Position[0] = parentData.OPosition[0] + v[0];
                objectData.Position[1] = parentData.OPosition[1] + v[1];
                objectData.Position[2] = parentData.OPosition[2] + v[2];
            }
            float[] deg = MathHelper.RotationDegree(qo.Matrix);
            objectData.Rotation[0] = deg[0];
            objectData.Rotation[1] = deg[1];
            objectData.Rotation[2] = deg[2];
        }
Beispiel #7
0
 private void MeshFactoryEnqueue(JsonObjectUpdated prim)
 {
     Monitor.Enter(queueMeshFactory);
     try
     {
         queueMeshFactory.Enqueue(prim);
         Monitor.Pulse(queueMeshFactory);
     }
     finally
     {
         Monitor.Exit(queueMeshFactory);
     }
 }