public void OnObjectUpdate(CloudObject cloudObject) { if (cloudObject.HasExtension) { OmModelPrimitiveExt modelPrimitiveExt = cloudObject.GetExtension <OmModelPrimitiveExt>(); string modelUrl = modelPrimitiveExt.ModelUrl; if (!DeckProgram.AssetManager.IsBlackListed(modelUrl)) { if (!DeckProgram.AssetManager.IsAssetDownloaded(modelUrl) && !DeckProgram.AssetManager.IsAssetDownloading(modelUrl)) { LogUtil.Info("Loading referenced model: " + modelUrl); DeckProgram.AssetManager.DownloadAsset(modelUrl); } if (DeckProgram.AssetManager.IsAssetDownloaded(modelUrl)) { if (!m_objectUpdateQueue.Contains(cloudObject.ObjectId)) { DeckProgram.AssetManager.EnsureModelIsLoadedToRenderer(modelUrl); m_objectUpdateQueue.Add(cloudObject.ObjectId); } } else { if (!m_objectsWaitingAssets.ContainsKey(modelUrl)) { m_objectsWaitingAssets.Add(modelUrl, new HashSet <Guid>()); } if (!m_objectsWaitingAssets[modelUrl].Contains(cloudObject.ObjectId)) { m_objectsWaitingAssets[modelUrl].Add(cloudObject.ObjectId); } } } } }
public void Process() { if (m_objectUpdateQueue.Count > 0) { foreach (Guid objectId in m_objectUpdateQueue) { CloudObject cloudObject = DeckProgram.CloudView.CloudCache.GetObject(objectId); OmModelPrimitiveExt modelPrimitiveExt = cloudObject.GetExtension <OmModelPrimitiveExt>(); Vector3 location = new Vector3(cloudObject.Location.X, cloudObject.Location.Y, cloudObject.Location.Z); Quaternion orientation = new Quaternion(cloudObject.Orientation.W, cloudObject.Orientation.X, cloudObject.Orientation.Y, cloudObject.Orientation.Z); Vector3 scale = new Vector3(cloudObject.BoundingSphereRadius * modelPrimitiveExt.Scale, cloudObject.BoundingSphereRadius * modelPrimitiveExt.Scale, cloudObject.BoundingSphereRadius * modelPrimitiveExt.Scale); bool isNewAvatar = objectId == AvatarId && !DeckProgram.DeckScene.ContainsObject(objectId); if (!DeckProgram.DeckScene.ContainsObject(objectId)) { if (IsSynchronizing) { CurrentObjectSynchronizationCount++; if (ExpectedObjectSynchronizationCount <= CurrentObjectSynchronizationCount) { CurrentObjectSynchronizationCount = 0; ExpectedObjectSynchronizationCount = 0; Thread.Sleep(200); } } DeckProgram.DeckScene.AddObject(new DeckObject(objectId, cloudObject.ObjectName, cloudObject.TypeName, modelPrimitiveExt.ModelUrl, modelPrimitiveExt.Scale, location, orientation, cloudObject.BoundingSphereRadius, scale)); } DeckObject deckObject = DeckProgram.DeckScene.GetObject(cloudObject.ObjectId); if (isNewAvatar) { Matrix orientationMatrix; Common.Rotate(out orientationMatrix, ref orientation); DeckProgram.DeckRudder.AvatarTargetLocation = location; DeckProgram.DeckRudder.AvatarCurrentLocation = location; DeckProgram.DeckRudder.AvatarTargetOrientationMatrix = orientationMatrix; DeckProgram.DeckRudder.AvatarCurrentOrientationMatrix = orientationMatrix; DeckProgram.DeckRudder.UpdateCameraTransformation(); DeckProgram.DeckRudder.SynchronizeCameraCurrentLocationWithTargetLocation(); } deckObject.ObjectName = cloudObject.ObjectName; deckObject.NetworkLocation = location; deckObject.NetworkOrientation = orientation; deckObject.Radius = cloudObject.BoundingSphereRadius; deckObject.ModelScale = modelPrimitiveExt.Scale; deckObject.NetworkScale = scale; DeckProgram.DeckScene.UpdateObject(deckObject); DeckProgram.DeckScene.ActivateObject(objectId); } m_objectUpdateQueue.Clear(); } if (DeckProgram.DeckRudder.IsSteered && DateTime.Now.Subtract(m_lastSteeringUpdate).TotalMilliseconds > 100) { m_lastSteeringUpdate = DateTime.Now; if (DeckProgram.CloudView.CloudCache.GetObject(AvatarId) != null) { ModifyRequestMessage modifyRequestMessage = new ModifyRequestMessage(); modifyRequestMessage.ObjectFragment.ObjectId = AvatarId; modifyRequestMessage.ObjectFragment.OwnerId = ParticipantId; modifyRequestMessage.ObjectFragment.TypeId = Guid.Empty; modifyRequestMessage.ObjectFragment.ObjectName = ParticipantNickName; modifyRequestMessage.ObjectFragment.TypeName = "Avatar"; modifyRequestMessage.ObjectFragment.BoundingSphereRadius = 2f; modifyRequestMessage.ObjectFragment.Mass = 2f; modifyRequestMessage.ObjectFragment.Location.X = (float)DeckProgram.DeckRudder.AvatarTargetLocation.X; modifyRequestMessage.ObjectFragment.Location.Y = (float)DeckProgram.DeckRudder.AvatarTargetLocation.Y; modifyRequestMessage.ObjectFragment.Location.Z = (float)DeckProgram.DeckRudder.AvatarTargetLocation.Z; Matrix rotationMatrix = DeckProgram.DeckRudder.AvatarTargetOrientationMatrix; Quaternion quaternion; Common.Rotate(out quaternion, ref rotationMatrix); modifyRequestMessage.ObjectFragment.Orientation.X = (float)quaternion.I; modifyRequestMessage.ObjectFragment.Orientation.Y = (float)quaternion.J; modifyRequestMessage.ObjectFragment.Orientation.Z = (float)quaternion.K; modifyRequestMessage.ObjectFragment.Orientation.W = (float)quaternion.W; OmModelPrimitiveExt modelPrimitiveExt = new OmModelPrimitiveExt(); modelPrimitiveExt.ModelUrl = "http://assets.bubblecloud.org/Collada/Seymour/Seymour_triangulate.dae"; modelPrimitiveExt.Scale = (float)0.1f; modifyRequestMessage.SetExtension(modelPrimitiveExt); DeckProgram.CloudView.ModifyObject(modifyRequestMessage); DeckProgram.DeckRudder.IsSteered = false; } } }