private void OffsetTexture(IScriptInstance script, LLPrimitive obj, float u, float v, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Change one face Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.OffsetU = u; face.OffsetV = v; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) { face.OffsetU = u; face.OffsetV = v; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
private void ObjectLoadedHandler(AssetPrim linkset, long bytesRead, long totalBytes) { if (m_primMesher == null) { return; } // Get the root prim LLPrimitive parent = LLUtil.PrimObjectToLLPrim(linkset.Parent, m_scene, m_primMesher); // Get the child prims and sort them by link order SortedList <int, LLPrimitive> children = new SortedList <int, LLPrimitive>(linkset.Children.Count); for (int i = 0; i < linkset.Children.Count; i++) { children.Add(linkset.Children[i].LinkNumber, LLUtil.PrimObjectToLLPrim(linkset.Children[i], m_scene, m_primMesher)); } // Set the child prims as children of the root, in order foreach (LLPrimitive child in children.Values) { child.SetParent(parent, false, false); } // Send updates for everything m_scene.EntityAddOrUpdate(this, parent, UpdateFlags.FullUpdate, 0); foreach (LLPrimitive child in children.Values) { m_scene.EntityAddOrUpdate(this, child, UpdateFlags.FullUpdate, 0); } PrintProgress(bytesRead, totalBytes); }
public PermissionMask GetPrimPermissions(IScenePresence presence, LLPrimitive entity) { // Check if presence is a grid admin if (IsGridAdmin(presence)) { return(PermissionMask.All); } // Check if presence is an estate manager if (IsEstateManager(presence)) { return(PermissionMask.All); } Permissions perms = entity.Prim.Properties.Permissions; if (entity.OwnerID == presence.ID) { return(perms.OwnerMask); } if (entity.GroupID != UUID.Zero && IsInGroup(presence, entity.GroupID)) { return(perms.GroupMask); } return(perms.EveryoneMask); }
private void SerializationHandler(PrimSerialization serialization) { if (serialization.Prim != null && serialization.Prim.Parent != null) { m_log.Debug("Skipping serialization for child prim " + serialization.Prim.ID); return; } SerializedData item = new SerializedData { ContentType = PRIM_CONTENT_TYPE, Name = serialization.ID.ToString(), Section = "llprimitives", StoreID = m_scene.ID, Version = 1 }; // Removes set item.Data = null, signaling a delete. Adds set item.Data to the serialized prim data if (serialization.Prim != null) { item.Data = Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(LLPrimitive.SerializeLinkset(serialization.Prim))); } m_dataStore.BeginSerialize(item); }
private static PrimInventory FromPrimObjectInventory(LLPrimitive host, PrimObject.InventoryBlock objInv) { PrimInventory inv = new PrimInventory(host); if (objInv == null) { return(inv); } for (int i = 0; i < objInv.Items.Length; i++) { PrimObject.InventoryBlock.ItemBlock objItem = objInv.Items[i]; LLInventoryTaskItem item = new LLInventoryTaskItem(); item.AssetID = objItem.AssetID; item.ContentType = LLUtil.LLAssetTypeToContentType((int)objItem.Type); item.CreationDate = objItem.CreationDate; item.CreatorID = objItem.CreatorID; item.Description = objItem.Description; item.Flags = (uint)objItem.Flags; item.GroupID = objItem.GroupID; item.ID = objItem.ID; item.Name = objItem.Name; item.OwnerID = objItem.OwnerID; item.Permissions = new Permissions(objItem.PermsBase, objItem.PermsEveryone, objItem.PermsGroup, objItem.PermsNextOwner, objItem.PermsOwner); item.PermissionGranter = objItem.PermsGranterID; inv.AddOrUpdateItem(item, true); } inv.InventorySerial = (short)objInv.Serial; return(inv); }
private void Deserialize() { IList <SerializedData> items = m_dataStore.Deserialize(m_scene.ID, "llprimitives"); int linksetCount = 0; int primCount = 0; for (int i = 0; i < items.Count; i++) { SerializedData item = items[i]; using (MemoryStream stream = new MemoryStream(item.Data)) { OSDMap linksetMap = OSDParser.DeserializeJson(stream) as OSDMap; if (linksetMap != null) { IList <LLPrimitive> linkset = LLPrimitive.DeserializeLinkset(linksetMap, m_scene, m_primMesher, false); // Rez the parent(s) first for (int j = 0; j < linkset.Count; j++) { LLPrimitive prim = linkset[j]; if (prim.Parent == null) { m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.FullUpdate, 0); } } // Rez the children for (int j = 0; j < linkset.Count; j++) { LLPrimitive prim = linkset[j]; if (prim.Parent != null) { m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.FullUpdate, 0); } } // Start any scripts for (int j = 0; j < linkset.Count; j++) { StartScripts(linkset[j]); } ++linksetCount; primCount += linkset.Count; } else { m_log.WarnFormat("Failed to deserialize store object {0} ({1} bytes), Content-Type={2}, Version={3}", item.Name, item.Data.Length, item.ContentType, item.Version); } } } m_log.DebugFormat("Deserialized and loaded {0} LLPrimitives in {1} linksets", primCount, linksetCount); }
public ConvexHullSet GetConvexHulls(LLPrimitive prim) { ConvexHullSet hullSet; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetConvexHullSet(physicsKey, BASIC_MESH_LOD, out hullSet)) { return(hullSet); } // FIXME: Implement this return(null); }
public BasicMesh GetBasicMesh(LLPrimitive prim) { BasicMesh mesh; OpenMetaverseMesh omvMesh = null; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetBasicMesh(physicsKey, BASIC_MESH_LOD, out mesh)) return mesh; // Can't go any further without a prim renderer if (m_renderer == null) return null; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) omvMesh = m_renderer.GenerateSimpleSculptMesh(prim.Prim, sculptTexture, OpenMetaverse.Rendering.DetailLevel.Low); } else { // Basic prim meshing omvMesh = m_renderer.GenerateSimpleMesh(prim.Prim, OpenMetaverse.Rendering.DetailLevel.Medium); } if (omvMesh == null) return null; #if DEBUG for (int i = 0; i < omvMesh.Indices.Count; i++) System.Diagnostics.Debug.Assert(omvMesh.Indices[i] < omvMesh.Vertices.Count, "Mesh index is out of range"); #endif // Convert the OpenMetaverse.Rendering mesh to a BasicMesh mesh = new BasicMesh(); mesh.Vertices = new Vector3[omvMesh.Vertices.Count]; for (int i = 0; i < omvMesh.Vertices.Count; i++) mesh.Vertices[i] = omvMesh.Vertices[i].Position; mesh.Indices = omvMesh.Indices.ToArray(); mesh.Volume = Util.GetMeshVolume(mesh, Vector3.One); // Store the result in the mesh cache, if we have one if (m_meshCache != null) m_meshCache.StoreBasicMesh(physicsKey, BASIC_MESH_LOD, mesh); return mesh; }
private void StartScripts(LLPrimitive prim) { if (m_scriptEngine == null) { return; } IList <LLInventoryTaskItem> scriptItems = prim.Inventory.FindAllItems(item => item.AssetType == AssetType.LSLText); for (int i = 0; i < scriptItems.Count; i++) { LLInventoryItem item = scriptItems[i]; m_scriptEngine.RezScript(item.ID, item.AssetID, prim, 0); } }
public static OSDMap SerializeLinkset(LLPrimitive prim) { OSDMap linksetMap = new OSDMap(); linksetMap[prim.LocalID.ToString()] = prim.GetOSD(); ILinkable[] children = prim.GetChildren(); if (children != null) { for (int i = 0; i < children.Length; i++) { LLPrimitive child = children[i] as LLPrimitive; if (child != null) linksetMap[child.LocalID.ToString()] = child.GetOSD(); } } return linksetMap; }
private void EntityAddOrUpdateHandler(object sender, EntityAddOrUpdateArgs e) { if (sender != this && e.Entity is LLPrimitive && (e.UpdateFlags != 0 || e.ExtraFlags != 0)) { LLPrimitive prim = (LLPrimitive)e.Entity; ILinkable parent = prim.Parent; if (parent == null) { m_writeQueue.Add(prim.ID, new PrimSerialization { ID = prim.ID, Prim = prim }); } else if (parent is LLPrimitive) { m_writeQueue.Add(parent.ID, new PrimSerialization { ID = parent.ID, Prim = (LLPrimitive)parent }); } } }
private void StartScripts(LLPrimitive prim) { if (m_scriptEngine == null) return; IList<LLInventoryTaskItem> scriptItems = prim.Inventory.FindAllItems(item => item.AssetType == AssetType.LSLText); for (int i = 0; i < scriptItems.Count; i++) { LLInventoryItem item = scriptItems[i]; m_scriptEngine.RezScript(item.ID, item.AssetID, prim, 0); } }
private static int GetNumberOfSides(LLPrimitive obj) { int sides = obj.GetNumberOfSides(); if (obj.Prim.Type == PrimType.Sphere && obj.Prim.PrimData.ProfileHollow > 0f) { // Account for an LSL bug where this reports four sides instead of two sides += 2; } return sides; }
public PrimFlags GetFlagsFor(IScenePresence presence, LLPrimitive entity) { PrimFlags flags = entity.Prim.Flags; Permissions perms = entity.Prim.Properties.Permissions; // Remove flags that shouldn't be sent to clients flags &= ~(PrimFlags.DieAtEdge | PrimFlags.Flying | PrimFlags.ReturnAtEdge | PrimFlags.Sandbox); if (entity.OwnerID != UUID.Zero) { flags |= PrimFlags.ObjectAnyOwner; // Someone owns the object } if (entity.GroupID != UUID.Zero) { flags |= (PrimFlags.ObjectAnyOwner | PrimFlags.ObjectGroupOwned); // A group owns this object } if (entity.OwnerID == presence.ID || IsGridAdmin(presence) || IsEstateManager(presence)) { // User owner permissions // Mark that we own this object flags |= PrimFlags.ObjectYouOwner; flags |= PrimFlags.ObjectOwnerModify; if (perms.OwnerMask.HasPermission(PermissionMask.Copy)) { flags |= PrimFlags.ObjectCopy; } if (perms.OwnerMask.HasPermission(PermissionMask.Modify)) { flags |= PrimFlags.ObjectModify; } if (perms.OwnerMask.HasPermission(PermissionMask.Move)) { flags |= PrimFlags.ObjectMove; } if (perms.OwnerMask.HasPermission(PermissionMask.Transfer)) { flags |= PrimFlags.ObjectTransfer; } } else if (IsInGroup(presence, entity.GroupID)) { // Use group permissions // Mark that we own this object flags |= PrimFlags.ObjectYouOwner; flags |= PrimFlags.ObjectOwnerModify; flags |= PrimFlags.ObjectYouOfficer; if (perms.GroupMask.HasPermission(PermissionMask.Copy)) { flags |= PrimFlags.ObjectCopy; } if (perms.GroupMask.HasPermission(PermissionMask.Modify)) { flags |= PrimFlags.ObjectModify; } if (perms.GroupMask.HasPermission(PermissionMask.Move)) { flags |= PrimFlags.ObjectMove; } if (perms.GroupMask.HasPermission(PermissionMask.Transfer)) { flags |= PrimFlags.ObjectTransfer; } } else { // Use everyone permissions if (perms.EveryoneMask.HasPermission(PermissionMask.Copy)) { flags |= PrimFlags.ObjectCopy; } if (perms.EveryoneMask.HasPermission(PermissionMask.Modify)) { flags |= PrimFlags.ObjectModify; } if (perms.EveryoneMask.HasPermission(PermissionMask.Move)) { flags |= PrimFlags.ObjectMove; } if (perms.EveryoneMask.HasPermission(PermissionMask.Transfer)) { flags |= PrimFlags.ObjectTransfer; } } return(flags); }
public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod) { return m_cubeRenderingMesh; }
private void CreatePrim(WarpRenderer renderer, LLPrimitive prim, IPrimMesher primMesher) { const float MIN_SIZE = 2f; if (prim.Prim.PrimData.PCode != PCode.Prim) return; if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) return; RenderingMesh renderMesh; DetailLevel lod = DetailLevel.Medium; renderMesh = primMesher.GetRenderingMesh(prim, lod); if (renderMesh == null) return; warp_Vector primPos = ConvertVector(prim.ScenePosition); warp_Quaternion primRot = ConvertQuaternion(prim.RelativeRotation); warp_Matrix m = warp_Matrix.quaternionMatrix(primRot); if (prim.Parent != null) m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(prim.Parent.RelativeRotation))); warp_Vector primScale = ConvertVector(prim.Scale); string primID = prim.ID.ToString(); // Create the prim faces for (int i = 0; i < renderMesh.Faces.Length; i++) { RenderingMesh.Face face = renderMesh.Faces[i]; string meshName = primID + "-Face-" + i.ToString(); warp_Object faceObj = new warp_Object(face.Vertices.Length, face.Indices.Length / 3); for (int j = 0; j < face.Vertices.Length; j++) { Vertex v = face.Vertices[j]; warp_Vector pos = ConvertVector(v.Position); warp_Vector norm = ConvertVector(v.Normal); if (prim.Prim.Sculpt == null || prim.Prim.Sculpt.SculptTexture == UUID.Zero) norm = norm.reverse(); warp_Vertex vert = new warp_Vertex(pos, norm, v.TexCoord.X, v.TexCoord.Y); faceObj.addVertex(vert); } for (int j = 0; j < face.Indices.Length; j += 3) { faceObj.addTriangle( face.Indices[j + 0], face.Indices[j + 1], face.Indices[j + 2]); } Primitive.TextureEntryFace teFace = prim.Prim.Textures.GetFace((uint)i); Color4 faceColor = GetFaceColor(teFace); string materialName = GetOrCreateMaterial(renderer, faceColor); faceObj.transform(m); faceObj.setPos(primPos); faceObj.scaleSelf(primScale.x, primScale.y, primScale.z); renderer.Scene.addObject(meshName, faceObj); renderer.SetObjectMaterial(meshName, materialName); } }
public PrimInventory(LLPrimitive hostObject) { m_hostObject = hostObject; }
private void SetPrimShapeParams(LLPrimitive prim, int holeShape, Vector3 cut, float hollow, Vector3 twist, Vector3 dimple) { HoleType hole = (HoleType)holeShape; if (hole != HoleType.Same && hole != HoleType.Circle && hole != HoleType.Square && hole != HoleType.Triangle) hole = HoleType.Same; // Clamp the cut values cut.X = Utils.Clamp(cut.X, 0f, 1f); cut.Y = Utils.Clamp(cut.Y, 0f, 1f); if (cut.Y - cut.X < 0.05f) { cut.X = cut.Y - 0.05f; if (cut.X < 0f) { cut.X = 0f; cut.Y = 0.05f; } } // Clamp hollow hollow = Utils.Clamp(hollow, 0f, 0.95f); // Clamp the twist values twist.X = Utils.Clamp(twist.X, -1f, 1f); twist.Y = Utils.Clamp(twist.Y, -1f, 1f); // Clamp the dimple values dimple.X = Utils.Clamp(dimple.X, 0f, 1f); dimple.Y = Utils.Clamp(dimple.Y, 0f, 1f); if (dimple.Y - cut.X < 0.05f) dimple.X = cut.Y - 0.05f; prim.Prim.PrimData.ProfileHole = hole; prim.Prim.PrimData.ProfileBegin = cut.X; prim.Prim.PrimData.ProfileEnd = cut.Y; prim.Prim.PrimData.ProfileHollow = hollow; prim.Prim.PrimData.PathTwistBegin = twist.X; prim.Prim.PrimData.PathTwist = twist.Y; // TODO: Is this right? If so, what is cut for? prim.Prim.PrimData.ProfileBegin = dimple.X; prim.Prim.PrimData.ProfileEnd = dimple.Y; }
private void SetPrimShapeParams(LLPrimitive prim, int holeShape, Vector3 cut, float hollow, Vector3 twist, Vector3 topSize, Vector3 topShear, Vector3 advCut, Vector3 taper, float revolutions, float radiusOffset, float skew) { // FIXME: Implement this throw new NotImplementedException(); }
private void UploadObjectAssetHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response) { UploadObjectAssetMessage message; if (LLUtil.TryGetMessage <UploadObjectAssetMessage>(request.Body, out message)) { LLPrimitive parent = null; // Build the linkset for (int i = 0; i < message.Objects.Length; i++) { UploadObjectAssetMessage.Object obj = message.Objects[i]; #region Primitive Creation Primitive prim = new Primitive(); prim.Properties = new Primitive.ObjectProperties(); prim.Sculpt = new Primitive.SculptData(); prim.Textures = new Primitive.TextureEntry(UUID.Zero); prim.Flags = PrimFlags.CastShadows | PrimFlags.InventoryEmpty | PrimFlags.CreateSelected; prim.ID = UUID.Random(); prim.MediaURL = String.Empty; prim.OwnerID = cap.OwnerID; prim.GroupID = obj.GroupID; prim.TextColor = Color4.Black; prim.Properties.CreationDate = DateTime.UtcNow; prim.Properties.CreatorID = cap.OwnerID; prim.Properties.Description = String.Empty; prim.Properties.GroupID = obj.GroupID; prim.Properties.LastOwnerID = cap.OwnerID; prim.Properties.Name = obj.Name; prim.Properties.ObjectID = prim.ID; prim.Properties.OwnerID = prim.OwnerID; prim.Properties.Permissions = (m_permissions != null) ? m_permissions.GetDefaultPermissions() : Permissions.FullPermissions; prim.Properties.SalePrice = 10; prim.PrimData.PCode = PCode.Prim; prim.PrimData.Material = obj.Material; prim.PrimData.PathBegin = obj.PathBegin; prim.PrimData.PathCurve = (PathCurve)obj.PathCurve; prim.PrimData.PathEnd = obj.PathEnd; prim.PrimData.ProfileBegin = obj.ProfileBegin; prim.PrimData.ProfileCurve = (ProfileCurve)obj.ProfileCurve; prim.PrimData.ProfileEnd = obj.ProfileEnd; prim.PrimData.ProfileHollow = obj.ProfileHollow; prim.PrimData.PathRadiusOffset = obj.RadiusOffset; prim.PrimData.PathRevolutions = obj.Revolutions; prim.PrimData.PathScaleX = obj.ScaleX; prim.PrimData.PathScaleY = obj.ScaleY; prim.PrimData.PathShearX = obj.ShearX; prim.PrimData.PathShearY = obj.ShearY; prim.PrimData.PathSkew = obj.Skew; prim.PrimData.PathTaperX = obj.TaperX; prim.PrimData.PathTaperY = obj.TaperY; prim.PrimData.PathTwist = obj.Twist; prim.PrimData.PathTwistBegin = obj.TwistBegin; // Extra parameters for (int j = 0; j < obj.ExtraParams.Length; j++) { UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[j]; switch (extraParam.Type) { case ExtraParamType.Flexible: prim.Flexible = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); break; case ExtraParamType.Light: prim.Light = new Primitive.LightData(extraParam.ExtraParamData, 0); break; case ExtraParamType.Sculpt: prim.Sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); break; } } // Faces for (int j = 0; j < obj.Faces.Length; j++) { UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; Primitive.TextureEntryFace primFace = prim.Textures.GetFace(0); primFace.Bump = face.Bump; primFace.RGBA = face.Color; primFace.Fullbright = face.Fullbright; primFace.Glow = face.Glow; primFace.TextureID = face.ImageID; primFace.Rotation = face.ImageRot; primFace.MediaFlags = ((face.MediaFlags & MEDIA_MASK) != 0); primFace.OffsetU = face.OffsetS; primFace.OffsetV = face.OffsetT; primFace.RepeatU = face.ScaleS; primFace.RepeatV = face.ScaleT; primFace.TexMapType = (MappingType)(face.MediaFlags & TEX_MAP_MASK); } prim.Sculpt.SculptTexture = obj.SculptID; prim.Sculpt.Type = obj.SculptType; #endregion Primitive Creation LLPrimitive llprim = new LLPrimitive(prim, m_scene, m_primMesher); llprim.Scale = obj.Scale; // Link children prims to the parent if (i == 0) { llprim.RelativePosition = obj.Position; llprim.RelativeRotation = obj.Rotation; m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0); parent = llprim; } else { llprim.RelativePosition = obj.Position; llprim.RelativeRotation = obj.Rotation; llprim.SetParent(parent, true, false); m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0); } } } else { m_log.Warn("Received invalid data for UploadObjectAsset"); response.Status = System.Net.HttpStatusCode.BadRequest; } }
private void SetPrimShapeParams(LLPrimitive prim, int holeShape, Vector3 cut, float hollow, Vector3 twist, Vector3 topSize, Vector3 topShear) { HoleType hole = (HoleType)holeShape; if (hole != HoleType.Same && hole != HoleType.Circle && hole != HoleType.Square && hole != HoleType.Triangle) hole = HoleType.Same; // Clamp the cut values cut.X = Utils.Clamp(cut.X, 0f, 1f); cut.Y = Utils.Clamp(cut.Y, 0f, 1f); if (cut.Y - cut.X < 0.05f) { cut.X = cut.Y - 0.05f; if (cut.X < 0f) { cut.X = 0f; cut.Y = 0.05f; } } // Clamp hollow hollow = Utils.Clamp(hollow, 0f, 0.95f); // Clamp the twist values twist.X = Utils.Clamp(twist.X, -1f, 1f); twist.Y = Utils.Clamp(twist.Y, -1f, 1f); // Clamp the taper values topSize.X = Utils.Clamp(topSize.X, 0f, 2f); topSize.Y = Utils.Clamp(topSize.Y, 0f, 2f); // Clamp the top shear values topShear.X = Utils.Clamp(topShear.X, -0.5f, 0.5f); topShear.Y = Utils.Clamp(topShear.Y, -0.5f, 0.5f); prim.Prim.PrimData.ProfileHole = hole; prim.Prim.PrimData.ProfileBegin = cut.X; prim.Prim.PrimData.ProfileEnd = cut.Y; prim.Prim.PrimData.ProfileHollow = hollow; prim.Prim.PrimData.PathTwistBegin = twist.X; prim.Prim.PrimData.PathTwist = twist.Y; prim.Prim.PrimData.PathScaleX = topSize.Y; prim.Prim.PrimData.PathScaleY = topSize.Y; prim.Prim.PrimData.PathShearX = topShear.X; prim.Prim.PrimData.PathShearY = topShear.Y; }
private void SetTexgen(LLPrimitive obj, MappingType texgen, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.TexMapType = texgen; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) face.TexMapType = texgen; } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
public PrimFlags GetFlagsFor(IScenePresence presence, LLPrimitive entity) { PrimFlags flags = entity.Prim.Flags; Permissions perms = entity.Prim.Properties.Permissions; // Remove flags that shouldn't be sent to clients flags &= ~(PrimFlags.DieAtEdge | PrimFlags.Flying | PrimFlags.ReturnAtEdge | PrimFlags.Sandbox); if (entity.OwnerID != UUID.Zero) flags |= PrimFlags.ObjectAnyOwner; // Someone owns the object if (entity.GroupID != UUID.Zero) flags |= (PrimFlags.ObjectAnyOwner | PrimFlags.ObjectGroupOwned); // A group owns this object if (entity.OwnerID == presence.ID || IsGridAdmin(presence) || IsEstateManager(presence)) { // User owner permissions // Mark that we own this object flags |= PrimFlags.ObjectYouOwner; flags |= PrimFlags.ObjectOwnerModify; if (perms.OwnerMask.HasPermission(PermissionMask.Copy)) flags |= PrimFlags.ObjectCopy; if (perms.OwnerMask.HasPermission(PermissionMask.Modify)) flags |= PrimFlags.ObjectModify; if (perms.OwnerMask.HasPermission(PermissionMask.Move)) flags |= PrimFlags.ObjectMove; if (perms.OwnerMask.HasPermission(PermissionMask.Transfer)) flags |= PrimFlags.ObjectTransfer; } else if (IsInGroup(presence, entity.GroupID)) { // Use group permissions // Mark that we own this object flags |= PrimFlags.ObjectYouOwner; flags |= PrimFlags.ObjectOwnerModify; flags |= PrimFlags.ObjectYouOfficer; if (perms.GroupMask.HasPermission(PermissionMask.Copy)) flags |= PrimFlags.ObjectCopy; if (perms.GroupMask.HasPermission(PermissionMask.Modify)) flags |= PrimFlags.ObjectModify; if (perms.GroupMask.HasPermission(PermissionMask.Move)) flags |= PrimFlags.ObjectMove; if (perms.GroupMask.HasPermission(PermissionMask.Transfer)) flags |= PrimFlags.ObjectTransfer; } else { // Use everyone permissions if (perms.EveryoneMask.HasPermission(PermissionMask.Copy)) flags |= PrimFlags.ObjectCopy; if (perms.EveryoneMask.HasPermission(PermissionMask.Modify)) flags |= PrimFlags.ObjectModify; if (perms.EveryoneMask.HasPermission(PermissionMask.Move)) flags |= PrimFlags.ObjectMove; if (perms.EveryoneMask.HasPermission(PermissionMask.Transfer)) flags |= PrimFlags.ObjectTransfer; } return flags; }
public PhysicsMesh GetPhysicsMesh(LLPrimitive prim) { return m_cubeMesh; }
public PermissionMask GetPrimPermissions(IScenePresence presence, LLPrimitive entity) { // Check if presence is a grid admin if (IsGridAdmin(presence)) return PermissionMask.All; // Check if presence is an estate manager if (IsEstateManager(presence)) return PermissionMask.All; Permissions perms = entity.Prim.Properties.Permissions; if (entity.OwnerID == presence.ID) return perms.OwnerMask; if (entity.GroupID != UUID.Zero && IsInGroup(presence, entity.GroupID)) return perms.GroupMask; return perms.EveryoneMask; }
private void SetColor(LLPrimitive obj, Vector3 color, int side) { if (obj is LLPrimitive) { LLPrimitive prim = (LLPrimitive)obj; int sides = GetNumberOfSides(prim); // Sanitize the color input color.X = Utils.Clamp(color.X, 0.0f, 1.0f); color.Y = Utils.Clamp(color.Y, 0.0f, 1.0f); color.Z = Utils.Clamp(color.Z, 0.0f, 1.0f); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = prim.Prim.Textures.CreateFace((uint)side); face.RGBA = new Color4(color.X, color.Y, color.Z, face.RGBA.A); obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = prim.Prim.Textures.GetFace(i); if (face != null) face.RGBA = new Color4(color.X, color.Y, color.Z, face.RGBA.A); } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } } }
public PhysicsMesh GetPhysicsMesh(LLPrimitive prim) { List<Coord> coords; List<Face> faces; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { SculptMesh mesh = GetSculptMesh(prim, DetailLevel.Low, true); if (mesh == null) return null; coords = mesh.coords; faces = mesh.faces; } else { PrimMesh mesh = GetPrimMesh(prim, DetailLevel.Low, true); if (mesh == null) return null; coords = mesh.coords; faces = mesh.faces; } Vector3[] vertices = new Vector3[coords.Count]; for (int i = 0; i < coords.Count; i++) { Coord c = coords[i]; vertices[i] = new Vector3(c.X, c.Y, c.Z); } ushort[] indices = new ushort[faces.Count * 3]; for (int i = 0; i < faces.Count; i++) { Face f = faces[i]; indices[i * 3 + 0] = (ushort)f.v1; indices[i * 3 + 1] = (ushort)f.v2; indices[i * 3 + 2] = (ushort)f.v3; } return new PhysicsMesh { Vertices = vertices, Indices = indices }; }
private void SetTexture(IScriptInstance script, LLPrimitive obj, string texture, int side) { // "texture" may be an AssetID or the name of a texture in this object's task inventory UUID textureID = KeyOrName(script, texture, AssetType.Texture); // Can't set texture to UUID.Zero if (textureID == UUID.Zero) return; int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Change one face Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.TextureID = textureID; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLScriptBase.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) face.TextureID = textureID; } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod) { RenderingMesh mesh; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetRenderingMesh(physicsKey, lod, out mesh)) { return(mesh); } // Can't go any further without a prim renderer if (m_renderer == null) { return(null); } // Convert our DetailLevel to the OpenMetaverse.Rendering DetailLevel OpenMetaverse.Rendering.DetailLevel detailLevel; switch (lod) { case DetailLevel.Low: detailLevel = OpenMetaverse.Rendering.DetailLevel.Low; break; case DetailLevel.Medium: detailLevel = OpenMetaverse.Rendering.DetailLevel.Medium; break; case DetailLevel.High: detailLevel = OpenMetaverse.Rendering.DetailLevel.High; break; case DetailLevel.Highest: default: detailLevel = OpenMetaverse.Rendering.DetailLevel.Highest; break; } FacetedMesh facetedMesh = null; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) { facetedMesh = m_renderer.GenerateFacetedSculptMesh(prim.Prim, sculptTexture, detailLevel); } } else { // Basic prim meshing facetedMesh = m_renderer.GenerateFacetedMesh(prim.Prim, detailLevel); } if (facetedMesh != null) { #region FacetedMesh to RenderingMesh Conversion mesh = new RenderingMesh(); mesh.Faces = new RenderingMesh.Face[facetedMesh.Faces.Count]; for (int i = 0; i < facetedMesh.Faces.Count; i++) { Face face = facetedMesh.Faces[i]; Vertex[] vertices = new Vertex[face.Vertices.Count]; for (int j = 0; j < face.Vertices.Count; j++) { OpenMetaverse.Rendering.Vertex omvrVertex = face.Vertices[j]; vertices[j] = new Vertex { Position = omvrVertex.Position, Normal = omvrVertex.Normal, TexCoord = omvrVertex.TexCoord }; } ushort[] indices = face.Indices.ToArray(); mesh.Faces[i] = new RenderingMesh.Face { Vertices = vertices, Indices = indices }; } #endregion FacetedMesh to RenderingMesh Conversion // Store the result in the mesh cache, if we have one if (m_meshCache != null) { m_meshCache.StoreRenderingMesh(physicsKey, lod, mesh); } return(mesh); } else { return(null); } }
public static LLPrimitive FromOSD(OSDMap map, IScene scene, IPrimMesher mesher) { if (map == null) return null; OSDMap primMap = map["prim"] as OSDMap; Primitive prim = new Primitive(); prim.Acceleration = primMap["acceleration"].AsVector3(); prim.AngularVelocity = primMap["ang_velocity"].AsVector3(); prim.ClickAction = (ClickAction)primMap["click_action"].AsInteger(); prim.Flags = (PrimFlags)primMap["flags"].AsUInteger(); prim.GroupID = primMap["group_id"].AsUUID(); prim.ID = primMap["id"].AsUUID(); prim.LocalID = primMap["local_id"].AsUInteger(); prim.MediaURL = primMap["media_url"].AsString(); prim.OwnerID = primMap["owner_id"].AsUUID(); prim.ParentID = primMap["parent_id"].AsUInteger(); prim.ParticleSys = Primitive.ParticleSystem.FromOSD(primMap["particles"]); prim.Position = primMap["position"].AsVector3(); prim.Rotation = primMap["rotation"].AsQuaternion(); prim.Scale = primMap["scale"].AsVector3(); prim.ScratchPad = primMap["scratch_pad"].AsBinary(); prim.Sound = primMap["sound"].AsUUID(); prim.SoundFlags = (SoundFlags)primMap["sound_flags"].AsInteger(); prim.SoundGain = (float)primMap["sound_gain"].AsReal(); prim.SoundRadius = (float)primMap["sound_radius"].AsReal(); prim.Text = primMap["text"].AsString(); prim.TextColor = primMap["text_color"].AsColor4(); prim.TextureAnim = Primitive.TextureAnimation.FromOSD(primMap["texture_anim"]); prim.TreeSpecies = (Tree)primMap["tree_species"].AsInteger(); prim.Velocity = primMap["velocity"].AsVector3(); prim.PrimData.Material = (Material)primMap["material"].AsInteger(); prim.PrimData.State = (byte)primMap["state"].AsInteger(); prim.PrimData.PCode = (PCode)primMap["pcode"].AsInteger(); if (prim.PrimData.PCode == PCode.None) prim.PrimData.PCode = PCode.Prim; if (primMap.ContainsKey("name_values")) { string nameValue = primMap["name_values"].AsString(); if (!String.IsNullOrEmpty(nameValue)) { string[] lines = nameValue.Split('\n'); prim.NameValues = new NameValue[lines.Length]; for (int i = 0; i < lines.Length; i++) { string line = lines[i]; if (!String.IsNullOrEmpty(line)) prim.NameValues[i] = new NameValue(line); } } } if (primMap.ContainsKey("textures")) prim.Textures = Primitive.TextureEntry.FromOSD(primMap["textures"]); if (primMap.ContainsKey("light")) prim.Light = Primitive.LightData.FromOSD(primMap["light"]); if (primMap.ContainsKey("flex")) prim.Flexible = Primitive.FlexibleData.FromOSD(primMap["flex"]); if (primMap.ContainsKey("sculpt")) prim.Sculpt = Primitive.SculptData.FromOSD(primMap["sculpt"]); OSDMap pathMap = (OSDMap)primMap["path"]; prim.PrimData.PathBegin = (float)pathMap["begin"].AsReal(); prim.PrimData.PathCurve = (PathCurve)pathMap["curve"].AsInteger(); prim.PrimData.PathEnd = (float)pathMap["end"].AsReal(); prim.PrimData.PathRadiusOffset = (float)pathMap["radius_offset"].AsReal(); prim.PrimData.PathRevolutions = (float)pathMap["revolutions"].AsReal(); prim.PrimData.PathScaleX = (float)pathMap["scale_x"].AsReal(); prim.PrimData.PathScaleY = (float)pathMap["scale_y"].AsReal(); prim.PrimData.PathShearX = (float)pathMap["shear_x"].AsReal(); prim.PrimData.PathShearY = (float)pathMap["shear_y"].AsReal(); prim.PrimData.PathSkew = (float)pathMap["skew"].AsReal(); prim.PrimData.PathTaperX = (float)pathMap["taper_x"].AsReal(); prim.PrimData.PathTaperY = (float)pathMap["taper_y"].AsReal(); prim.PrimData.PathTwist = (float)pathMap["twist"].AsReal(); prim.PrimData.PathTwistBegin = (float)pathMap["twist_begin"].AsReal(); OSDMap profileMap = (OSDMap)primMap["profile"]; prim.PrimData.ProfileBegin = (float)profileMap["begin"].AsReal(); prim.PrimData.ProfileCurve = (ProfileCurve)profileMap["curve"].AsInteger(); prim.PrimData.ProfileHole = (HoleType)profileMap["hole"].AsInteger(); prim.PrimData.ProfileEnd = (float)profileMap["end"].AsReal(); prim.PrimData.ProfileHollow = (float)profileMap["hollow"].AsReal(); OSDMap propertiesMap = (OSDMap)primMap["properties"]; prim.Properties = new Primitive.ObjectProperties(); prim.Properties.AggregatePerms = (byte)propertiesMap["aggregate_perms"].AsInteger(); prim.Properties.AggregatePermTextures = (byte)propertiesMap["aggregate_perms_textures"].AsInteger(); prim.Properties.AggregatePermTexturesOwner = (byte)propertiesMap["aggregate_perms_textures_owner"].AsInteger(); prim.Properties.Category = (ObjectCategory)propertiesMap["category"].AsInteger(); prim.Properties.CreationDate = propertiesMap["creation_date"].AsDate(); prim.Properties.CreatorID = propertiesMap["creator_id"].AsUUID(); prim.Properties.Description = propertiesMap["description"].AsString(); prim.Properties.FolderID = propertiesMap["folder_id"].AsUUID(); prim.Properties.FromTaskID = propertiesMap["from_task_id"].AsUUID(); prim.Properties.GroupID = prim.GroupID; prim.Properties.InventorySerial = (short)propertiesMap["inventory_serial"].AsInteger(); prim.Properties.ItemID = propertiesMap["item_id"].AsUUID(); prim.Properties.LastOwnerID = propertiesMap["last_owner_id"].AsUUID(); prim.Properties.Name = propertiesMap["name"].AsString(); prim.Properties.ObjectID = prim.ID; prim.Properties.OwnerID = prim.OwnerID; prim.Properties.OwnershipCost = propertiesMap["ownership_cost"].AsInteger(); prim.Properties.Permissions = Permissions.FromOSD(propertiesMap["permissions"]); prim.Properties.SalePrice = propertiesMap["sale_price"].AsInteger(); prim.Properties.SaleType = (SaleType)propertiesMap["sale_type"].AsInteger(); prim.Properties.SitName = propertiesMap["sit_name"].AsString(); prim.Properties.TouchName = propertiesMap["touch_name"].AsString(); LLPrimitive obj = new LLPrimitive(prim, scene, mesher); obj.SitPosition = map["sit_position"].AsVector3(); obj.SitRotation = map["sit_rotations"].AsQuaternion(); obj.AttachmentPosition = map["attachment_position"].AsVector3(); obj.AttachmentRotation = map["attachment_rotations"].AsQuaternion(); obj.LastAttachmentPoint = (AttachmentPoint)map["last_attachment_point"].AsInteger(); obj.BeforeAttachmentRotation = map["before_attachment_rotation"].AsQuaternion(); obj.RotationAxis = map["rotation_axis"].AsVector3(); obj.LinkNumber = map["link_number"].AsInteger(); obj.RemoteScriptAccessPIN = map["remote_script_access_pin"].AsInteger(); obj.Inventory.FromTaskInventoryAsset(map["inventory"].AsString()); OSDArray buttons = map["pay_price_buttons"] as OSDArray; if (buttons != null) { obj.PayPriceButtons[0] = buttons[0].AsInteger(); obj.PayPriceButtons[1] = buttons[1].AsInteger(); obj.PayPriceButtons[2] = buttons[2].AsInteger(); obj.PayPriceButtons[3] = buttons[3].AsInteger(); } obj.PayPrice = map["pay_price"].AsInteger(); OSDArray faceMedia = map["face_media"] as OSDArray; if (faceMedia != null) { obj.Prim.FaceMedia = new MediaEntry[faceMedia.Count]; for (int i = 0; i < faceMedia.Count; i++) { OSDMap entryMap = faceMedia[i] as OSDMap; if (entryMap != null) obj.Prim.FaceMedia[i] = MediaEntry.FromOSD(entryMap); } } obj.Prim.MediaVersion = map["media_version"].AsString(); obj.m_lastUpdated = map["last_updated"].AsDate(); if (obj.m_lastUpdated <= Utils.Epoch) obj.m_lastUpdated = DateTime.UtcNow; return obj; }
public static LLPrimitive PrimObjectToLLPrim(PrimObject obj, IScene scene, IPrimMesher mesher) { Primitive prim = new Primitive(); prim.Properties = new Primitive.ObjectProperties(); LLPrimitive llprim = new LLPrimitive(prim, scene, mesher); prim.Acceleration = obj.Acceleration; if (obj.AllowedDrop) { prim.Flags |= PrimFlags.AllowInventoryDrop; } prim.AngularVelocity = obj.AngularVelocity; llprim.AttachmentPosition = obj.AttachmentPosition; llprim.AttachmentRotation = obj.AttachmentRotation; llprim.BeforeAttachmentRotation = obj.BeforeAttachmentRotation; //obj.CameraAtOffset; //obj.CameraEyeOffset; prim.ClickAction = (ClickAction)obj.ClickAction; //obj.CollisionSound; //obj.CollisionSoundVolume; prim.Properties.CreationDate = obj.CreationDate; prim.Properties.CreatorID = obj.CreatorID; prim.Properties.Description = obj.Description; if (obj.DieAtEdge) { prim.Flags |= PrimFlags.DieAtEdge; } prim.Flexible = FromPrimObjectFlexible(obj.Flexible); prim.Properties.FolderID = obj.FolderID; prim.Properties.GroupID = obj.GroupID; prim.ID = obj.ID; llprim.Inventory = FromPrimObjectInventory(llprim, obj.Inventory); llprim.LastAttachmentPoint = (AttachmentPoint)obj.LastAttachmentPoint; prim.Properties.LastOwnerID = obj.LastOwnerID; prim.Light = FromPrimObjectLight(obj.Light); //obj.LinkNumber; prim.LocalID = obj.LocalID; prim.Properties.Name = obj.Name; prim.OwnerID = obj.OwnerID; //obj.ParentID; prim.ParticleSys = FromPrimObjectParticles(obj.Particles); prim.Properties.Permissions = new Permissions(obj.PermsBase, obj.PermsEveryone, obj.PermsGroup, obj.PermsNextOwner, obj.PermsOwner); if (obj.Phantom) { prim.Flags |= PrimFlags.Phantom; } prim.Position = obj.Position; prim.RegionHandle = Util.PositionToRegionHandle(scene.MinPosition); llprim.RemoteScriptAccessPIN = obj.RemoteScriptAccessPIN; if (obj.ReturnAtEdge) { prim.Flags |= PrimFlags.ReturnAtEdge; } //obj.RezDate; prim.Rotation = obj.Rotation; prim.Properties.SalePrice = obj.SalePrice; prim.Properties.SalePrice = obj.SaleType; if (obj.Sandbox) { prim.Flags |= PrimFlags.Sandbox; } prim.Scale = obj.Scale; //obj.ScriptState; prim.Sculpt = FromPrimObjectSculpt(obj.Sculpt); //obj.Selected; //obj.SelectorID; prim.PrimData = FromPrimObjectShape(obj.Shape, obj.PCode, obj.Material); prim.Properties.SitName = obj.SitName; llprim.SitPosition = obj.SitOffset; llprim.SitRotation = obj.SitRotation; prim.SoundFlags = (SoundFlags)obj.SoundFlags; prim.SoundGain = obj.SoundGain; prim.Sound = obj.SoundID; prim.SoundRadius = obj.SoundRadius; //obj.State; if (obj.Temporary) { prim.Flags |= PrimFlags.Temporary; } prim.Text = obj.Text; prim.TextColor = obj.TextColor; prim.Textures = obj.Textures; prim.Properties.TouchName = obj.TouchName; if (obj.UsePhysics) { prim.Flags |= PrimFlags.Physics; } prim.Velocity = obj.Velocity; //obj.VolumeDetect return(llprim); }
public static IList<LLPrimitive> DeserializeLinkset(OSDMap linksetMap, IScene destinationScene, IPrimMesher mesher, bool forceNewIDs) { Dictionary<uint, LLPrimitive> prims = new Dictionary<uint, LLPrimitive>(); Dictionary<uint, uint> oldToNewIDs = new Dictionary<uint, uint>(); // Deserialize all of the prims and assign new IDs foreach (KeyValuePair<string, OSD> kvp in linksetMap) { uint localID; if (UInt32.TryParse(kvp.Key, out localID) && kvp.Value is OSDMap) { OSDMap primMap = (OSDMap)kvp.Value; LLPrimitive prim; try { prim = LLPrimitive.FromOSD(primMap, destinationScene, mesher); if (forceNewIDs || prim.Prim.ID == UUID.Zero || prim.Prim.LocalID == 0) { prim.Prim.ID = UUID.Random(); prim.Prim.LocalID = destinationScene.CreateLocalID(); } // Clear any attachment point state data prim.Prim.PrimData.AttachmentPoint = AttachmentPoint.Default; prims[prim.LocalID] = prim; oldToNewIDs[localID] = prim.Prim.LocalID; } catch (Exception ex) { m_log.WarnFormat("Invalid prim data in serialized linkset: {0}: {1}", ex.Message, primMap); } } else { m_log.WarnFormat("Invalid key/value pair in serialized linkset: \"{0}\":\"{1}\"", kvp.Key, kvp.Value); } } // Link all of the prims together and update the ParentIDs foreach (LLPrimitive prim in prims.Values) { if (prim.Prim.ParentID != 0) { uint newLocalID; if (oldToNewIDs.TryGetValue(prim.Prim.ParentID, out newLocalID)) { prim.Prim.ParentID = newLocalID; LLPrimitive parent = prims[newLocalID]; prim.SetParent(parent, false, false); } else { m_log.WarnFormat("Failed to locate parent prim {0} for child prim {1}, delinking child", prim.Prim.ParentID, prim.LocalID); prim.Prim.ParentID = 0; } } } return new List<LLPrimitive>(prims.Values); }
private void SetAlpha(LLPrimitive obj, float alpha, int side) { if (obj is LLPrimitive) { LLPrimitive prim = (LLPrimitive)obj; int sides = GetNumberOfSides(prim); float newAlpha = (float)Utils.Clamp(alpha, 0.0, 1.0); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = prim.Prim.Textures.CreateFace((uint)side); Color4 faceColor = face.RGBA; faceColor.A = newAlpha; face.RGBA = faceColor; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = prim.Prim.Textures.GetFace(i); if (face != null) { Color4 faceColor = face.RGBA; faceColor.A = newAlpha; face.RGBA = faceColor; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } } }
public ConvexHullSet GetConvexHulls(LLPrimitive prim) { ConvexHullSet hullSet; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetConvexHullSet(physicsKey, BASIC_MESH_LOD, out hullSet)) return hullSet; // FIXME: Implement this return null; }
private void UploadObjectAssetHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response) { UploadObjectAssetMessage message; if (LLUtil.TryGetMessage<UploadObjectAssetMessage>(request.Body, out message)) { LLPrimitive parent = null; // Build the linkset for (int i = 0; i < message.Objects.Length; i++) { UploadObjectAssetMessage.Object obj = message.Objects[i]; #region Primitive Creation Primitive prim = new Primitive(); prim.Properties = new Primitive.ObjectProperties(); prim.Sculpt = new Primitive.SculptData(); prim.Textures = new Primitive.TextureEntry(UUID.Zero); prim.Flags = PrimFlags.CastShadows | PrimFlags.InventoryEmpty | PrimFlags.CreateSelected; prim.ID = UUID.Random(); prim.MediaURL = String.Empty; prim.OwnerID = cap.OwnerID; prim.GroupID = obj.GroupID; prim.TextColor = Color4.Black; prim.Properties.CreationDate = DateTime.UtcNow; prim.Properties.CreatorID = cap.OwnerID; prim.Properties.Description = String.Empty; prim.Properties.GroupID = obj.GroupID; prim.Properties.LastOwnerID = cap.OwnerID; prim.Properties.Name = obj.Name; prim.Properties.ObjectID = prim.ID; prim.Properties.OwnerID = prim.OwnerID; prim.Properties.Permissions = (m_permissions != null) ? m_permissions.GetDefaultPermissions() : Permissions.FullPermissions; prim.Properties.SalePrice = 10; prim.PrimData.PCode = PCode.Prim; prim.PrimData.Material = obj.Material; prim.PrimData.PathBegin = obj.PathBegin; prim.PrimData.PathCurve = (PathCurve)obj.PathCurve; prim.PrimData.PathEnd = obj.PathEnd; prim.PrimData.ProfileBegin = obj.ProfileBegin; prim.PrimData.ProfileCurve = (ProfileCurve)obj.ProfileCurve; prim.PrimData.ProfileEnd = obj.ProfileEnd; prim.PrimData.ProfileHollow = obj.ProfileHollow; prim.PrimData.PathRadiusOffset = obj.RadiusOffset; prim.PrimData.PathRevolutions = obj.Revolutions; prim.PrimData.PathScaleX = obj.ScaleX; prim.PrimData.PathScaleY = obj.ScaleY; prim.PrimData.PathShearX = obj.ShearX; prim.PrimData.PathShearY = obj.ShearY; prim.PrimData.PathSkew = obj.Skew; prim.PrimData.PathTaperX = obj.TaperX; prim.PrimData.PathTaperY = obj.TaperY; prim.PrimData.PathTwist = obj.Twist; prim.PrimData.PathTwistBegin = obj.TwistBegin; // Extra parameters for (int j = 0; j < obj.ExtraParams.Length; j++) { UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[j]; switch (extraParam.Type) { case ExtraParamType.Flexible: prim.Flexible = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); break; case ExtraParamType.Light: prim.Light = new Primitive.LightData(extraParam.ExtraParamData, 0); break; case ExtraParamType.Sculpt: prim.Sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); break; } } // Faces for (int j = 0; j < obj.Faces.Length; j++) { UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; Primitive.TextureEntryFace primFace = prim.Textures.GetFace(0); primFace.Bump = face.Bump; primFace.RGBA = face.Color; primFace.Fullbright = face.Fullbright; primFace.Glow = face.Glow; primFace.TextureID = face.ImageID; primFace.Rotation = face.ImageRot; primFace.MediaFlags = ((face.MediaFlags & MEDIA_MASK) != 0); primFace.OffsetU = face.OffsetS; primFace.OffsetV = face.OffsetT; primFace.RepeatU = face.ScaleS; primFace.RepeatV = face.ScaleT; primFace.TexMapType = (MappingType)(face.MediaFlags & TEX_MAP_MASK); } prim.Sculpt.SculptTexture = obj.SculptID; prim.Sculpt.Type = obj.SculptType; #endregion Primitive Creation LLPrimitive llprim = new LLPrimitive(prim, m_scene, m_primMesher); llprim.Scale = obj.Scale; // Link children prims to the parent if (i == 0) { llprim.RelativePosition = obj.Position; llprim.RelativeRotation = obj.Rotation; m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0); parent = llprim; } else { llprim.RelativePosition = obj.Position; llprim.RelativeRotation = obj.Rotation; llprim.SetParent(parent, true, false); m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0); } } } else { m_log.Warn("Received invalid data for UploadObjectAsset"); response.Status = System.Net.HttpStatusCode.BadRequest; } }
public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod) { RenderingMesh mesh; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetRenderingMesh(physicsKey, lod, out mesh)) return mesh; // Can't go any further without a prim renderer if (m_renderer == null) return null; // Convert our DetailLevel to the OpenMetaverse.Rendering DetailLevel OpenMetaverse.Rendering.DetailLevel detailLevel; switch (lod) { case DetailLevel.Low: detailLevel = OpenMetaverse.Rendering.DetailLevel.Low; break; case DetailLevel.Medium: detailLevel = OpenMetaverse.Rendering.DetailLevel.Medium; break; case DetailLevel.High: detailLevel = OpenMetaverse.Rendering.DetailLevel.High; break; case DetailLevel.Highest: default: detailLevel = OpenMetaverse.Rendering.DetailLevel.Highest; break; } FacetedMesh facetedMesh = null; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) facetedMesh = m_renderer.GenerateFacetedSculptMesh(prim.Prim, sculptTexture, detailLevel); } else { // Basic prim meshing facetedMesh = m_renderer.GenerateFacetedMesh(prim.Prim, detailLevel); } if (facetedMesh != null) { #region FacetedMesh to RenderingMesh Conversion mesh = new RenderingMesh(); mesh.Faces = new RenderingMesh.Face[facetedMesh.Faces.Count]; for (int i = 0; i < facetedMesh.Faces.Count; i++) { Face face = facetedMesh.Faces[i]; Vertex[] vertices = new Vertex[face.Vertices.Count]; for (int j = 0; j < face.Vertices.Count; j++) { OpenMetaverse.Rendering.Vertex omvrVertex = face.Vertices[j]; vertices[j] = new Vertex { Position = omvrVertex.Position, Normal = omvrVertex.Normal, TexCoord = omvrVertex.TexCoord }; } ushort[] indices = face.Indices.ToArray(); mesh.Faces[i] = new RenderingMesh.Face { Vertices = vertices, Indices = indices }; } #endregion FacetedMesh to RenderingMesh Conversion // Store the result in the mesh cache, if we have one if (m_meshCache != null) m_meshCache.StoreRenderingMesh(physicsKey, lod, mesh); return mesh; } else { return null; } }
public RenderingMesh GetRenderingMesh(LLPrimitive prim, DetailLevel lod) { OMVR.FacetedMesh omvrMesh = null; if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { SculptMesh mesh = GetSculptMesh(prim, lod, false); if (mesh != null) omvrMesh = GenerateFacetedMesh(1, prim.Prim, mesh.viewerFaces); } else { PrimMesh mesh = GetPrimMesh(prim, lod, false); if (mesh != null) omvrMesh = GenerateFacetedMesh(mesh.numPrimFaces, prim.Prim, mesh.viewerFaces); } if (omvrMesh != null) { // Copy the faces RenderingMesh.Face[] renderingFaces = new RenderingMesh.Face[omvrMesh.Faces.Count]; for (int i = 0; i < omvrMesh.Faces.Count; i++) { OMVR.Face face = omvrMesh.Faces[i]; RenderingMesh.Face renderingFace = new RenderingMesh.Face(); // Copy the vertices for this face renderingFace.Vertices = new Vertex[face.Vertices.Count]; for (int j = 0; j < face.Vertices.Count; j++) { OMVR.Vertex vertex = face.Vertices[j]; renderingFace.Vertices[j] = new Vertex { Position = vertex.Position, Normal = vertex.Normal, TexCoord = vertex.TexCoord }; } // Copy the indices for this face renderingFace.Indices = face.Indices.ToArray(); renderingFaces[i] = renderingFace; } return new RenderingMesh { Faces = renderingFaces }; } else { return null; } }
private void SetShinyBump(LLPrimitive obj, Shininess shiny, Bumpiness bump, int side) { int sides = GetNumberOfSides(obj); if (side >= 0 && side < sides) { // Get or create the requested face and update Primitive.TextureEntryFace face = obj.Prim.Textures.CreateFace((uint)side); face.Shiny = shiny; face.Bump = bump; obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } else if (side == LSLConstants.ALL_SIDES) { // Change all of the faces for (uint i = 0; i < sides; i++) { Primitive.TextureEntryFace face = obj.Prim.Textures.GetFace(i); if (face != null) { face.Shiny = shiny; face.Bump = bump; } } obj.Scene.EntityAddOrUpdate(this, obj, 0, (uint)LLUpdateFlags.Textures); } }
public BasicMesh GetBasicMesh(LLPrimitive prim) { BasicMesh mesh; OpenMetaverseMesh omvMesh = null; ulong physicsKey = prim.GetPhysicsKey(); // Try a cache lookup first if (m_meshCache != null && m_meshCache.TryGetBasicMesh(physicsKey, BASIC_MESH_LOD, out mesh)) { return(mesh); } // Can't go any further without a prim renderer if (m_renderer == null) { return(null); } if (prim.Prim.Sculpt != null && prim.Prim.Sculpt.SculptTexture != UUID.Zero) { // Sculpty meshing Bitmap sculptTexture = GetSculptMap(prim.Prim.Sculpt.SculptTexture); if (sculptTexture != null) { omvMesh = m_renderer.GenerateSimpleSculptMesh(prim.Prim, sculptTexture, OpenMetaverse.Rendering.DetailLevel.Low); } } else { // Basic prim meshing omvMesh = m_renderer.GenerateSimpleMesh(prim.Prim, OpenMetaverse.Rendering.DetailLevel.Medium); } if (omvMesh == null) { return(null); } #if DEBUG for (int i = 0; i < omvMesh.Indices.Count; i++) { System.Diagnostics.Debug.Assert(omvMesh.Indices[i] < omvMesh.Vertices.Count, "Mesh index is out of range"); } #endif // Convert the OpenMetaverse.Rendering mesh to a BasicMesh mesh = new BasicMesh(); mesh.Vertices = new Vector3[omvMesh.Vertices.Count]; for (int i = 0; i < omvMesh.Vertices.Count; i++) { mesh.Vertices[i] = omvMesh.Vertices[i].Position; } mesh.Indices = omvMesh.Indices.ToArray(); mesh.Volume = Util.GetMeshVolume(mesh, Vector3.One); // Store the result in the mesh cache, if we have one if (m_meshCache != null) { m_meshCache.StoreBasicMesh(physicsKey, BASIC_MESH_LOD, mesh); } return(mesh); }
public SculptMesh GetSculptMesh(LLPrimitive llprim, DetailLevel lod, bool isBasicMesh) { Primitive prim = llprim.Prim; SculptMesh.SculptType sculptType; switch (prim.Sculpt.Type) { case SculptType.Cylinder: sculptType = SculptMesh.SculptType.cylinder; break; case SculptType.Plane: sculptType = SculptMesh.SculptType.plane; break; case SculptType.Torus: sculptType = SculptMesh.SculptType.torus; break; case SculptType.Sphere: default: sculptType = SculptMesh.SculptType.sphere; break; } Bitmap sculptTexture = null; if (m_assetClient != null) { Asset textureAsset; if (m_assetClient.TryGetAsset(prim.Sculpt.SculptTexture, "image/x-j2c", out textureAsset)) { try { sculptTexture = (Bitmap)CSJ2K.J2kImage.FromBytes(textureAsset.Data); } catch (Exception ex) { m_log.Warn("Failed to decode sculpt texture " + textureAsset.ID + ": " + ex.Message); } } else { m_log.Warn("Failed to fetch sculpt texture asset " + prim.Sculpt.SculptTexture); } } int mesherLod = 32; // number used in Idealist viewer switch (lod) { case DetailLevel.Highest: break; case DetailLevel.High: break; case DetailLevel.Medium: mesherLod /= 2; break; case DetailLevel.Low: mesherLod /= 4; break; } if (sculptTexture != null) return new SculptMesh(sculptTexture, sculptType, mesherLod, !isBasicMesh, prim.Sculpt.Mirror, prim.Sculpt.Invert); else return null; }
public static PrimMesh GetPrimMesh(LLPrimitive llprim, DetailLevel lod, bool isBasicMesh) { OMV.Primitive.ConstructionData primData = llprim.Prim.PrimData; int sides = 4; int hollowsides = 4; float profileBegin = primData.ProfileBegin; float profileEnd = primData.ProfileEnd; bool isSphere = false; if ((OMV.ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.Circle) { switch (lod) { case DetailLevel.Low: sides = 6; break; case DetailLevel.Medium: sides = 12; break; default: sides = 24; break; } } else if ((OMV.ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.EqualTriangle) sides = 3; else if ((OMV.ProfileCurve)(primData.profileCurve & 0x07) == OMV.ProfileCurve.HalfCircle) { // half circle, prim is a sphere isSphere = true; switch (lod) { case DetailLevel.Low: sides = 6; break; case DetailLevel.Medium: sides = 12; break; default: sides = 24; break; } profileBegin = 0.5f * profileBegin + 0.5f; profileEnd = 0.5f * profileEnd + 0.5f; } if ((OMV.HoleType)primData.ProfileHole == OMV.HoleType.Same) hollowsides = sides; else if ((OMV.HoleType)primData.ProfileHole == OMV.HoleType.Circle) { switch (lod) { case DetailLevel.Low: hollowsides = 6; break; case DetailLevel.Medium: hollowsides = 12; break; default: hollowsides = 24; break; } } else if ((OMV.HoleType)primData.ProfileHole == OMV.HoleType.Triangle) hollowsides = 3; PrimMesh newPrim = new PrimMesh(sides, profileBegin, profileEnd, (float)primData.ProfileHollow, hollowsides); newPrim.viewerMode = !isBasicMesh; newPrim.holeSizeX = primData.PathScaleX; newPrim.holeSizeY = primData.PathScaleY; newPrim.pathCutBegin = primData.PathBegin; newPrim.pathCutEnd = primData.PathEnd; newPrim.topShearX = primData.PathShearX; newPrim.topShearY = primData.PathShearY; newPrim.radius = primData.PathRadiusOffset; newPrim.revolutions = primData.PathRevolutions; newPrim.skew = primData.PathSkew; switch (lod) { case DetailLevel.Low: newPrim.stepsPerRevolution = 6; break; case DetailLevel.Medium: newPrim.stepsPerRevolution = 12; break; default: newPrim.stepsPerRevolution = 24; break; } if ((primData.PathCurve == OMV.PathCurve.Line) || (primData.PathCurve == OMV.PathCurve.Flexible)) { newPrim.taperX = 1.0f - primData.PathScaleX; newPrim.taperY = 1.0f - primData.PathScaleY; newPrim.twistBegin = (int)(180 * primData.PathTwistBegin); newPrim.twistEnd = (int)(180 * primData.PathTwist); newPrim.ExtrudeLinear(); } else { newPrim.taperX = primData.PathTaperX; newPrim.taperY = primData.PathTaperY; newPrim.twistBegin = (int)(360 * primData.PathTwistBegin); newPrim.twistEnd = (int)(360 * primData.PathTwist); newPrim.ExtrudeCircular(); } int numViewerFaces = newPrim.viewerFaces.Count; int numPrimFaces = newPrim.numPrimFaces; for (uint i = 0; i < numViewerFaces; i++) { ViewerFace vf = newPrim.viewerFaces[(int)i]; if (isSphere) { vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f; vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f; vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f; } } return newPrim; }
private void ObjectMediaHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response) { ObjectMediaMessage message; if (LLUtil.TryGetMessage <ObjectMediaMessage>(request.Body, out message)) { if (message.Request is ObjectMediaRequest) { ObjectMediaRequest mediaRequest = (ObjectMediaRequest)message.Request; ISceneEntity entity; if (m_scene.TryGetEntity(mediaRequest.PrimID, out entity) && entity is LLPrimitive) { LLPrimitive prim = (LLPrimitive)entity; ObjectMediaResponse reply = new ObjectMediaResponse(); reply.PrimID = prim.ID; reply.FaceMedia = prim.Prim.FaceMedia ?? new MediaEntry[0]; reply.Version = prim.Prim.MediaVersion ?? String.Empty; LLUtil.SendLLSDXMLResponse(response, reply.Serialize()); } else { m_log.Warn("Received an ObjectMedia request for unknown prim " + mediaRequest.PrimID); } } else if (message.Request is ObjectMediaUpdate) { ObjectMediaUpdate update = (ObjectMediaUpdate)message.Request; ISceneEntity entity; if (m_scene.TryGetEntity(update.PrimID, out entity) && entity is LLPrimitive) { LLPrimitive prim = (LLPrimitive)entity; int lastVersion = ParseMediaVersion(prim.Prim.MediaVersion); prim.Prim.FaceMedia = update.FaceMedia; prim.Prim.MediaVersion = CreateMediaVersion(lastVersion + 1, cap.OwnerID); // Set the CurrentURL fields for (int i = 0; i < prim.Prim.FaceMedia.Length; i++) { MediaEntry entry = prim.Prim.FaceMedia[i]; if (entry != null && String.IsNullOrEmpty(entry.CurrentURL)) { entry.CurrentURL = entry.HomeURL; } } // Set the texture face media flags for (int i = 0; i < prim.Prim.Textures.FaceTextures.Length; i++) { Primitive.TextureEntryFace face = prim.Prim.Textures.FaceTextures[i]; MediaEntry entry = (update.FaceMedia.Length > i) ? update.FaceMedia[i] : null; if (entry != null) { if (face == null) { face = prim.Prim.Textures.CreateFace((uint)i); } face.MediaFlags = true; } else if (face != null) { face.MediaFlags = false; } } m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.FullUpdate, 0); } else { m_log.Warn("Could not update ObjectMedia for " + update.PrimID + ", prim not found"); } } else { m_log.Warn("Unrecognized ObjectMedia message: " + message.Request); } } else { m_log.Warn("Received invalid data for ObjectMedia"); response.Status = System.Net.HttpStatusCode.BadRequest; } }