public override void Setup() { base.Setup(); Widget = Helper.CreateModel(MScene.Overlay, "NavigationWidget", @"Models\arrow02.3ds", Vector3d.Zero); MMaterial mat = new MMaterial("WidgetMaterial"); MScene.MaterialRoot.Add(mat); mat.AddShader((MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER)); mat.SetDiffuseTexture(Globals.TexturePool.GetTexture("Textures\\arrow02.png")); Widget.AddMaterial(mat); Widget.transform.Scale = new Vector3d(1, 1, 1); Widget.Enabled = true; }
public void Setup(MObject o) { MSceneObject mo = (MSceneObject)o; if (mo == null) { return; } InstanceID = mo.InstanceID; Destination = MTeleporter.GetDestination(mo); DestinationBox.Text = MassiveTools.VectorToString(Destination); Description = MTeleporter.GetDescription(mo); DescriptionBox.Text = Description; }
/// <summary> /// Prepares an object for inclusion in the scene graph /// If the template does not exist, it is created first /// </summary> /// <param name="m"></param> public void Spawn(MServerObject m) { MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(m.InstanceID); if (mo != null) { return; //if the object already exists, never mind } //check if the object template exists. All user objects must exist as a template first MSceneObject mt = (MSceneObject)MScene.TemplateRoot.FindModuleByName(m.TemplateID); if (mt == null) { LoadTemplate(m.TemplateID); } //if ((m.Name == Globals.UserAccount.UserID) && ( m.OwnerID == Globals.UserAccount.UserID)){ mo = Helper.Spawn(m, MassiveTools.VectorFromArray(m.Position), MassiveTools.QuaternionFromArray(m.Rotation)); if (mo == null) { Console.WriteLine("MSpawnHandler: Template not found:" + m.TemplateID); } else { mo.InstanceID = m.InstanceID; mo.SetRotation(MassiveTools.QuaternionFromArray(m.Rotation)); //If the object spawning is our avatar if (mo.InstanceID == Globals.UserAccount.UserID) { Globals.Avatar.SetSceneObject(mo); MBuildingBlock bb = MBuildParts.GetBlock(mo.TemplateID); MScene.Camera.CameraOffset = MassiveTools.VectorFromArray(bb.BoneOffset); MMessageBus.AvatarChanged(this, Globals.UserAccount.UserID, mo.TemplateID); } SetMaterial(mo, m.TextureID); MMessageBus.Created(this, mo); } if (mo.OwnerID == Globals.UserAccount.UserID) { MMessageBus.Select(this, new SelectEvent(mo)); } }
void AddModules(MObject mods) { foreach (MObject mo in mods.Modules.ToList()) { //if (mo.Renderable == false) continue; if (mo is MSceneObject) { MSceneObject mso = (MSceneObject)mo; //if (mso.OwnerID == Globals.UserAccount.UserID) { AssetsList.Add(mso); } } AddModules(mo); } }
//sends local move requests to the server for handling private void MMessageBus_MoveRequestEventHandler(object sender, MoveEvent e) { if (Globals.Network.Connected == true) { Globals.Network.PositionRequest(e.InstanceID, e.Position, e.Rotation); } else { MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID); if (mo != null) { mo.SetPosition(e.Position); mo.SetRotation(e.Rotation); } } }
/// <summary> /// Submodules offer extra functionality for e.g. user interaction, linking click handlers to widgets /// We don't want to copy their instance, because each has unique values, e.g. door state. /// </summary> /// <param name="bb"></param> /// <param name="o"></param> static void AddSubmodules(MBuildingBlock bb, MSceneObject o) { if (bb.SubModule == "MDoor") { MDoor door = new MDoor(o); o.Add(door); } if (bb.SubModule == "MLinker") { MLinker link = new MLinker(); o.Add(link); MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MLinkerWidget.Mc_DoubleClick; mc.RightClicked = MLinkerWidget.Mc_RightClick; o.Add(mc); o.Tag = "LINKER01|URL:"; } if (bb.SubModule == "MTeleporter") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MTeleporterWidget.Mc_DoubleClick; mc.RightClicked = MTeleporterWidget.Mc_RightClick; o.Add(mc); o.Tag = "TELEPORTER01|XYZ:"; } if (bb.SubModule == "MPicture") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MPictureWidget.Mc_DoubleClick; mc.RightClicked = MPictureWidget.Mc_RightClick; o.Add(mc); o.Tag = "PICTURE01|This Picture|Description"; } if (bb.SubModule == "MStatus") { MClickHandler mc = new MClickHandler(); mc.DoubleClicked = MStatusWidget.Mc_DoubleClick; mc.RightClicked = MStatusWidget.Mc_RightClick; o.Add(mc); o.Tag = "STATUS01|This Status|Description"; } }
public static MSceneObject CreateSceneObject(string name, MVector3 position, MQuaternion rotation, string parent = null) { string id = Guid.NewGuid().ToString(); MSceneObject sceneObject = new MSceneObject() { ID = id, Name = name, Transform = new MTransform(id, position, rotation) { Parent = parent }, Properties = new Dictionary <string, string>(), }; return(sceneObject); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { base.AssignInstruction(instruction, simulationState); if (instruction.Properties.ContainsKey("leftTarget")) { this.LeftHandTarget = this.SceneAccess.GetSceneObjectByID(instruction.Properties["leftTarget"]); } if (instruction.Properties.ContainsKey("rightTarget")) { this.RightHandTarget = this.SceneAccess.GetSceneObjectByID(instruction.Properties["rightTarget"]); } return(new MBoolResponse(true)); }
void CalcFrustrum(MObject moParent) { Array ar = moParent.Modules.ToArray(); for (int i = 0; i < ar.Length; i++) { MObject m = (MObject)ar.GetValue(i); if (m == null) { continue; } if (m.Renderable) { MSceneObject mo = (MSceneObject)m; //meshes use their parent's transforms if (mo.Type == EType.Other) { continue; } if ((mo.Type != EType.Mesh) && (mo.Type != EType.BoneMesh)) { _frustrum.CalculateFrustum(MScene.Camera.getProjectionMatrix(), MScene.Camera.getViewMatrix()); //if ( _frustrum.VolumeVsFrustum(mo.transform.Position - Globals.GlobalOffset, mo.BoundingBox)) if (!_frustrum.SphereVsFrustum(mo.transform.Position - Globals.GlobalOffset, mo.BoundingBox.Size().Length)) //if (!_frustrum.PointVsFrustum(mo.transform.Position - Globals.GlobalOffset)) { mo.Culled = true; mo.Enabled = false; } else { mo.Culled = false; mo.Enabled = true; } //mo.DistanceFromAvatar = Vector3d.Distance(mo.transform.Position, AvatarPos); } } CalcFrustrum(m); } }
private void MMessageBus_DeleteObjectRequestHandler(object sender, DeleteRequestEvent e) { MSceneObject o = e.TargetObject; if (o == null) { return; } MPhysicsObject po = (MPhysicsObject)o.FindModuleByType(MObject.EType.PhysicsObject); MScene.Physics.Remove(po); MScene.ModelRoot.Remove(o); MScene.Priority1.Remove(o); MScene.Priority2.Remove(o); MScene.SelectedObject = null; }
public static void SetTimeOfDay(double _time) { time = _time; MAstroBody Sol = MPlanetHandler.Get("Sol"); Quaterniond q = Quaterniond.FromEulerAngles(0, (15 * time) * Math.PI / 180.0, 0); MSceneObject mo = (MSceneObject)MScene.AstroRoot.FindModuleByName("Sol"); mo.SetPosition(q * new Vector3d(Sol.DistanceToAvatar, 0, 0)); MMessageBus.Navigate(null, mo.transform.Position); double ottime = (time + timeOffset) % 24; float f24 = (float)Math.Sin((ottime * 15.0) * Math.PI / 180.0); //f24 = Math.Min((float)Math.Pow(f24, 0.2), 1); f24 = Math.Max(f24, 0.02f); MScene.light.Ambient = new Vector3(f24, f24, f24); }
public void Setup(MObject o, bool ReadOnly = false) { MSceneObject mo = (MSceneObject)o; if (mo == null) { return; } Target = mo; InstanceID = Target.InstanceID; UpdateImage(); UpdateData(); if (ReadOnly == true) { UpdateButton.Visible = false; InfoBox.ReadOnly = true; } }
/// <summary> /// Changes this transform from local to global space by iteratively progressing to parent objects transforms. /// </summary> /// <param name="t"></param> /// <param name="sceneAccess"></param> /// <returns></returns> public static MTransform LocalToGlobal(this MTransform t, MSceneAccess.Iface sceneAccess) { MTransform newT = t; if (t.Parent != null) { MSceneObject o = sceneAccess.GetSceneObjectByID(t.Parent); if (o != null) { newT = t.Multiply(o.Transform); if (o.Transform.Parent != null) { newT.Parent = o.Transform.Parent; newT = newT.LocalToGlobal(sceneAccess); } } } return(newT); }
private void MMessageBus_ObjectDeletedEvent(object sender, DeleteEvent e) { MSceneObject o = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID); if (o == null) { return; } MPhysicsObject po = (MPhysicsObject)o.FindModuleByType(MObject.EType.PhysicsObject); MScene.Physics.Remove(po); MScene.ModelRoot.Remove(o); MScene.Priority1.Remove(o); MScene.Priority2.Remove(o); MScene.SelectedObject = null; //o.Dispose(); //don't dispose, it disposes templates, let GC pick up unallocated objects }
public void Setup(MObject o, bool ReadOnly = false) { progressBar1.Visible = false; MSceneObject mo = (MSceneObject)o; if (mo == null) { return; } Target = mo; InstanceID = Target.InstanceID; UpdateImage(); UpdateData(); if (ReadOnly == true) { UpdateButton.Visible = false; UserStatusText.ReadOnly = true; } }
public static bool ZoneLocked(Vector3d pos, MObject mParent) { if (mParent.OwnerID == null) { return(true); } if (!mParent.OwnerID.Equals(Globals.UserAccount.UserID) && !mParent.OwnerID.Equals(MObject.OWNER_NONE) && !mParent.OwnerID.Equals(MObject.OWNER_ADMIN) && !mParent.OwnerID.Equals(MObject.OWNER_MAYOR) && !mParent.OwnerID.Equals(MObject.OWNER_SYSTEM)) { if (mParent.Renderable) { MSceneObject mso = (MSceneObject)mParent; if (mso.IsAvatar == true) { return(false); } double dist = Vector3d.Distance(pos, (mso.transform.Position)); if (dist < Globals.BuildThreshold) { return(true); } } } foreach (MObject m in mParent.Modules.ToList()) { bool b = (ZoneLocked(pos, m)); if (b == true) { return(true); } } return(false); }
/// <summary> /// Returns all attachments of the parents (recursively) including the one of the scene object specified by the id). /// </summary> /// <param name="id"></param> /// <returns></returns> public List <MAttachment> GetAttachmentsParentsRecursive(string id) { if (!this.sceneObjectsByID.ContainsKey(id)) { return(new List <MAttachment>()); } List <MAttachment> attachments = new List <MAttachment>(); MSceneObject current = this.GetSceneObjectByID(id); while (current.Transform.Parent != null && current.Transform.Parent != " ") { if (current.Attachments != null && current.Attachments.Count > 0) { attachments.AddRange(current.Attachments); } current = this.GetSceneObjectByID(current.Transform.Parent); } return(attachments); }
/// <summary> /// Basic initialization method /// </summary> /// <param name="avatarDescription"></param> /// <param name="properties"></param> /// <returns></returns> public override MBoolResponse Initialize(MAvatarDescription avatarDescription, Dictionary <string, string> properties) { //Call the base class (important for automatic conversion from MSimulationState to SimulationState) base.Initialize(avatarDescription, properties); this.SkeletonAccess = new IntermediateSkeleton(); this.SkeletonAccess.InitializeAnthropometry(avatarDescription); //Create a new session uuid this.sessionId = Guid.NewGuid().ToString(); //Create a new virtual scene this.virtualScene = new MMIScene(); //Create a unique id for the new virtual object representing the move target string moveTargetID = Guid.NewGuid().ToString(); //Create a new virtual object representing the move target moveTarget = new MSceneObject(moveTargetID, "MoveTarget", new MTransform() { ID = moveTargetID, Position = new MVector3(0, 0, 0), Rotation = new MQuaternion(0, 0, 0, 1) }); //Add the virtual move target to the scene this.virtualScene.Apply(new MSceneUpdate() { AddedSceneObjects = new List <MSceneObject>() { moveTarget } }); //Full scene transmission initial required this.transmitFullScene = true; //Setup the mmu access this.mmuAccess = new MMUAccess(this.sessionId) { //IntermediateAvatarDescription = avatarDescription, SceneAccess = this.virtualScene }; Console.WriteLine("Try to connect to mmu access..."); //Connect to mmu access and load mmus bool connected = this.mmuAccess.Connect(this.AdapterEndpoint, this.AvatarDescription.AvatarID); if (connected) { //Get all loadable MMUs within the current session List <MMUDescription> loadableMMUs = this.mmuAccess.GetLoadableMMUs(); MMUDescription moveMMU = loadableMMUs.Find(s => s.MotionType == "move"); Console.WriteLine("Got loadable MMUs:"); //Load the relevant MMUs bool loaded = this.mmuAccess.LoadMMUs(new List <MMUDescription>() { moveMMU }, TimeSpan.FromSeconds(10)); if (!loaded) { Console.WriteLine("Error at loading MMU"); return(new MBoolResponse(false) { LogData = new List <string>() { { "Error at loading mmu" } } }); } //Initialize all MMUs this.mmuAccess.InitializeMMUs(TimeSpan.FromSeconds(10), this.AvatarDescription.AvatarID); //Instantiate the cosimulator this.coSimulator = new MMICoSimulator(mmuAccess.MotionModelUnits); return(new MBoolResponse(true)); } else { Console.WriteLine("Connection to MMUAccess/MMIRegister failed"); return(new MBoolResponse(false) { LogData = new List <string>() { "Connection to MMUAccess/MMIRegister failed" } }); } }
public DeleteRequestEvent(MSceneObject inTargetObject) { TargetObject = inTargetObject; }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { //Assign the instruction this.instruction = instruction; MBoolResponse response = new MBoolResponse(true); if (instruction.Constraints.Count > 0 && instruction.Constraints[0].GeometryConstraint != null) { MSceneObject parent = this.SceneAccess.GetSceneObjectByID(instruction.Constraints[0].GeometryConstraint.ParentObjectID); if (instruction.Constraints[0].GeometryConstraint.ParentToConstraint != null) { MTransform ptc = instruction.Constraints[0].GeometryConstraint.ParentToConstraint; String gtp = ptc.Parent; if (gtp != null && this.SceneAccess.GetSceneObjectByID(gtp) != null) { // transform parent takes precedent. this.targetTransform = ptc.LocalToGlobal(this.SceneAccess); } else if (parent != null) { // parent to constraint has not valid parent, thus the geometry constraint parent is this.targetTransform = ptc.Multiply(parent.Transform.LocalToGlobal(this.SceneAccess)); } else { this.targetTransform = ptc; } } else { MVector3 pos = new MVector3(0, 0, 0); if (instruction.Constraints[0].GeometryConstraint.TranslationConstraint != null) { MTranslationConstraint trlCstr = instruction.Constraints[0].GeometryConstraint.TranslationConstraint; if (parent != null) { pos = parent.Transform.Position.Add(trlCstr.GetVector3()); } else { pos = trlCstr.GetVector3(); } } MQuaternion rot = new MQuaternion(0, 0, 0, 1); if (instruction.Constraints[0].GeometryConstraint.RotationConstraint != null) { MRotationConstraint rtCstr = instruction.Constraints[0].GeometryConstraint.RotationConstraint; if (parent != null) { rot = rtCstr.GetQuaternion().Multiply(parent.Transform.Rotation); } else { rot = rtCstr.GetQuaternion(); } } this.targetTransform = new MTransform("", pos, rot); } } else { response = new MBoolResponse(false) { LogData = new List <string>() { "Required target constraint (MGeometryConstraint) not defined" } }; } //Extract the velocity if defined if (instruction.Properties.ContainsKey("Velocity")) { Console.WriteLine("vel: " + instruction.Properties["Velocity"]); float.TryParse(instruction.Properties["Velocity"], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out velocity); } else { velocity = -1.0f; } /* * //Get the target id * if (instruction.Properties.ContainsKey("TargetID")) * this.targetTransform = this.SceneAccess.GetTransformByID(instruction.Properties["TargetID"]); * //Error id not available * else * { * return new MBoolResponse(false) * { * }; * }*/ //Return true/success return(response); }
public static MSceneObject LoadTemplate(string TemplateID) { MBuildingBlock bb = MBuildParts.GetBlock(TemplateID); if (bb == null) { Console.WriteLine("WARNING: MSpawnHandler.LoadTemplate " + TemplateID + " not found in blocks"); return(null); } MSceneObject o = null; if (bb.Type == MBuildParts.MAnimatedModel) { o = Helper.CreateAnimatedModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero); MAnimatedModel man = (MAnimatedModel)o; man.BoneOffset = MassiveTools.VectorFromArray(bb.BoneOffset); } if (bb.Type == MBuildParts.MModel) { o = Helper.CreateModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero); } MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(bb.MaterialID); if (mat == null) { Console.WriteLine("MSpawnHandler.LoadTemplate " + bb.MaterialID + " was null"); } o.SetMaterial(mat); Vector3d size = MassiveTools.VectorFromArray(bb.Size); MPhysicsObject.EShape shape = GetShape(bb.PhysicsShape); if (shape != MPhysicsObject.EShape.NULL) { MPhysicsObject mpo = new MPhysicsObject(o, TemplateID + "_physics", bb.Weight, shape, true, size); mpo.SetSleep(5); mpo.SetFriction(0.5); if (shape != MPhysicsObject.EShape.Sphere) { mpo.SetAngularFactor(0.0, 0.0, 0.0); mpo.SetDamping(0.5, 0.5); mpo.SetRestitution(0.5); } else { mpo.SetDamping(0.1, 0.1); mpo.SetRestitution(0.8); } } o.TemplateID = TemplateID; o.InstanceID = TemplateID; o.IsTransparent = bb.IsTransparent; o.transform.RotationOffset = Quaterniond.FromEulerAngles(MassiveTools.VectorFromArray(bb.RotationOffset)); o.Setup(); AddSubmodules(bb, o); return(o); }
public FocusEvent(MSceneObject inFocusObject) { FocusObject = inFocusObject; }
void CheckPick(Point p, bool DoubleClick = false, bool RightClick = false) { GL.Enable(EnableCap.DepthTest); GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit); MScene.ScreenPick.RenderPick(MScene.ModelRoot); //_glcontrol.SwapBuffers(); Vector3d p3d = new Vector3d(p.X, _glcontrol.Height - p.Y, 0); int index = _Scene.GetPick(p3d); //Log("Pick id:" + index + " @" + p.ToString()); if (index != -1) { //Console.WriteLine("Clicked:" + index); MObject mobj = MScene.ModelRoot.FindModuleByIndex(index, null); if (mobj == null) { return; } if (!mobj.Renderable) { return; } MSceneObject mo = (MSceneObject)mobj; if (mo != null) { if ((mo.Type == MObject.EType.Mesh) && (mo.Parent.Renderable)) { mo = (MSceneObject)mo.Parent; } else { return; } //Console.WriteLine("Pick id:" + index + " @" + p.ToString() + " Owner:" + mo.OwnerID); if (mo.OwnerID == null) { MMessageBus.Status(this, "ID: + " + mo.Index + " Object " + mo.Name + " with ID:" + mo.InstanceID + " has no owner"); } else if (!mo.OwnerID.Equals(Globals.UserAccount.UserID)) { MMessageBus.Status(this, "ID:" + mo.Index + " Object " + mo.Name + "," + mo.InstanceID); } // else { mo.OnClick(DoubleClick, RightClick); MMessageBus.Select(this, new SelectEvent(mo)); MMaterial m = (MMaterial)mo.FindModuleByType(EType.Material); MMessageBus.Status(this, "Selected:" + mo.TemplateID + "," + mo.InstanceID); } } MScene.SelectedObject = mo; } else { MScene.SelectedObject = null; } }
public static void Focus(object sender, MSceneObject mo) { FocusEventHandler?.Invoke(sender, new FocusEvent(mo)); }
public static void Created(object sender, MSceneObject mo) { GUIEvent(ObjectCreatedHandler, sender, new CreateEvent(mo)); }
public static void DeleteRequest(object sender, MSceneObject mo) { DeleteObjectRequestHandler?.Invoke(sender, new DeleteRequestEvent(mo)); }
public SelectEvent(MSceneObject _inSelected) { Selected = _inSelected; }
/// <summary> /// Basic constructor which takes the MSceneObject as input /// </summary> /// <param name="msceneObject"></param> public PhysicsTracker(MSceneObject msceneObject) { this.sceneObject = msceneObject; }
public static string GetDescription(MSceneObject mo) { string[] tags = DecodeTag((string)mo.Tag); return(tags[2]); }
/// <summary> /// Basic constructor which takes the MSceneObject as input /// </summary> /// <param name="msceneObject"></param> public TransformTracker(MSceneObject msceneObject) { this.sceneObject = msceneObject; }