private static Primitive.FlexibleData FromPrimObjectFlexible(PrimObject.FlexibleBlock objFlex) { if (objFlex == null) { return(null); } Primitive.FlexibleData flex = new Primitive.FlexibleData(); flex.Drag = objFlex.Drag; flex.Force = objFlex.Force; flex.Gravity = objFlex.Gravity; flex.Softness = objFlex.Softness; flex.Tension = objFlex.Tension; flex.Wind = objFlex.Wind; return(flex); }
private static string DecodeObjectExtraParams(string fieldName, object fieldData) { byte[] data = (byte[])fieldData; int i = 0; //int totalLength = 1; Primitive.FlexibleData Flexible = null; Primitive.LightData Light = null; Primitive.SculptData Sculpt = null; byte extraParamCount = data[i++]; for (int k = 0; k < extraParamCount; k++) { ExtraParamType type = (ExtraParamType)Utils.BytesToUInt16(data, i); i += 2; uint paramLength = Utils.BytesToUInt(data, i); i += 4; if (type == ExtraParamType.Flexible) Flexible = new Primitive.FlexibleData(data, i); else if (type == ExtraParamType.Light) Light = new Primitive.LightData(data, i); else if (type == ExtraParamType.Sculpt) Sculpt = new Primitive.SculptData(data, i); i += (int)paramLength; //totalLength += (int)paramLength + 6; } StringBuilder result = new StringBuilder(); result.AppendFormat("{0,30}", "<ExtraParams>" + Environment.NewLine); if (Flexible != null) { result.AppendFormat("{0,30}", "<Flexible>" + Environment.NewLine); GenericTypeDecoder(Flexible, ref result); result.AppendFormat("{0,30}", "</Flexible>" + Environment.NewLine); } if (Sculpt != null) { result.AppendFormat("{0,30}", "<Sculpt>" + Environment.NewLine); GenericTypeDecoder(Sculpt, ref result); result.AppendFormat("{0,30}", "</Sculpt>" + Environment.NewLine); } if (Light != null) { result.AppendFormat("{0,30}", "<Light>" + Environment.NewLine); GenericTypeDecoder(Light, ref result); result.AppendFormat("{0,30}", "</Light>" + Environment.NewLine); } result.AppendFormat("{0,30}", "</ExtraParams>"); return result.ToString(); }
/// <summary> /// Parses ad request /// </summary> /// <param name = "request"></param> /// <param name = "AgentId"></param> /// <param name = "cap"></param> /// <returns></returns> public byte[] ProcessAdd(Stream request, OSHttpResponse response, UUID AgentId) { IScenePresence avatar; if (!m_scene.TryGetScenePresence(AgentId, out avatar)) { return(MainServer.NoResponse); } OSDMap r = (OSDMap)OSDParser.Deserialize(request); UploadObjectAssetMessage message = new UploadObjectAssetMessage(); try { message.Deserialize(r); } catch (Exception ex) { MainConsole.Instance.Error("[UploadObjectAssetModule]: Error deserializing message " + ex); message = null; } if (message == null) { response.StatusCode = 400; //501; //410; //404; return(Encoding.UTF8.GetBytes("<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>")); } Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation); Quaternion rot = Quaternion.Identity; Vector3 rootpos = Vector3.Zero; SceneObjectGroup rootGroup = null; SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length]; for (int i = 0; i < message.Objects.Length; i++) { UploadObjectAssetMessage.Object obj = message.Objects[i]; PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); if (i == 0) { rootpos = obj.Position; } // Combine the extraparams data into it's ugly blob again.... //int bytelength = 0; //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) //{ // bytelength += obj.ExtraParams[extparams].ExtraParamData.Length; //} //byte[] extraparams = new byte[bytelength]; //int position = 0; //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) //{ // Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position, // obj.ExtraParams[extparams].ExtraParamData.Length); // // position += obj.ExtraParams[extparams].ExtraParamData.Length; // } //pbs.ExtraParams = extraparams; foreach (UploadObjectAssetMessage.Object.ExtraParam extraParam in obj.ExtraParams) { switch ((ushort)extraParam.Type) { case (ushort)ExtraParamType.Sculpt: Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); pbs.SculptEntry = true; pbs.SculptTexture = obj.SculptID; pbs.SculptType = (byte)sculpt.Type; break; case (ushort)ExtraParamType.Flexible: Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); pbs.FlexiEntry = true; pbs.FlexiDrag = flex.Drag; pbs.FlexiForceX = flex.Force.X; pbs.FlexiForceY = flex.Force.Y; pbs.FlexiForceZ = flex.Force.Z; pbs.FlexiGravity = flex.Gravity; pbs.FlexiSoftness = flex.Softness; pbs.FlexiTension = flex.Tension; pbs.FlexiWind = flex.Wind; break; case (ushort)ExtraParamType.Light: Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0); pbs.LightColorA = light.Color.A; pbs.LightColorB = light.Color.B; pbs.LightColorG = light.Color.G; pbs.LightColorR = light.Color.R; pbs.LightCutoff = light.Cutoff; pbs.LightEntry = true; pbs.LightFalloff = light.Falloff; pbs.LightIntensity = light.Intensity; pbs.LightRadius = light.Radius; break; case 0x40: pbs.ReadProjectionData(extraParam.ExtraParamData, 0); break; } } pbs.PathBegin = (ushort)obj.PathBegin; pbs.PathCurve = (byte)obj.PathCurve; pbs.PathEnd = (ushort)obj.PathEnd; pbs.PathRadiusOffset = (sbyte)obj.RadiusOffset; pbs.PathRevolutions = (byte)obj.Revolutions; pbs.PathScaleX = (byte)obj.ScaleX; pbs.PathScaleY = (byte)obj.ScaleY; pbs.PathShearX = (byte)obj.ShearX; pbs.PathShearY = (byte)obj.ShearY; pbs.PathSkew = (sbyte)obj.Skew; pbs.PathTaperX = (sbyte)obj.TaperX; pbs.PathTaperY = (sbyte)obj.TaperY; pbs.PathTwist = (sbyte)obj.Twist; pbs.PathTwistBegin = (sbyte)obj.TwistBegin; pbs.HollowShape = (HollowShape)obj.ProfileHollow; pbs.PCode = (byte)PCode.Prim; pbs.ProfileBegin = (ushort)obj.ProfileBegin; pbs.ProfileCurve = (byte)obj.ProfileCurve; pbs.ProfileEnd = (ushort)obj.ProfileEnd; pbs.Scale = obj.Scale; pbs.State = 0; SceneObjectPart prim = new SceneObjectPart(AgentId, pbs, obj.Position, obj.Rotation, Vector3.Zero, obj.Name, m_scene) { UUID = UUID.Random(), CreatorID = AgentId, OwnerID = AgentId, GroupID = obj.GroupID }; prim.LastOwnerID = prim.OwnerID; prim.CreationDate = Util.UnixTimeSinceEpoch(); prim.Name = obj.Name; prim.Description = ""; prim.PayPrice[0] = -2; prim.PayPrice[1] = -2; prim.PayPrice[2] = -2; prim.PayPrice[3] = -2; prim.PayPrice[4] = -2; Primitive.TextureEntry tmp = new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f")); for (int j = 0; j < obj.Faces.Length; j++) { UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; Primitive.TextureEntryFace primFace = tmp.CreateFace((uint)j); 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 & 1) != 0); primFace.OffsetU = face.OffsetS; primFace.OffsetV = face.OffsetT; primFace.RepeatU = face.ScaleS; primFace.RepeatV = face.ScaleT; primFace.TexMapType = (MappingType)(face.MediaFlags & 6); } pbs.TextureEntry = tmp.GetBytes(); prim.Shape = pbs; prim.Scale = obj.Scale; SceneObjectGroup grp = new SceneObjectGroup(prim, m_scene); prim.ParentID = 0; if (i == 0) { rootGroup = grp; } grp.AbsolutePosition = obj.Position; prim.RotationOffset = obj.Rotation; grp.RootPart.IsAttachment = false; string reason; if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos, out reason)) { m_scene.SceneGraph.AddPrimToScene(grp); grp.AbsolutePosition = obj.Position; } else { //Stop now then avatar.ControllingClient.SendAlertMessage("You do not have permission to rez objects here: " + reason); return(MainServer.NoResponse); } allparts[i] = grp; } for (int j = 1; j < allparts.Length; j++) { rootGroup.LinkToGroup(allparts[j]); } rootGroup.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate); pos = m_scene.SceneGraph.GetNewRezLocation(Vector3.Zero, rootpos, UUID.Zero, rot, 1, 1, true, allparts[0].GroupScale(), false); OSDMap map = new OSDMap(); map["local_id"] = allparts[0].LocalId; return(OSDParser.SerializeLLSDXmlBytes(map)); }
/// <summary> /// Parses ad request /// </summary> /// <param name="request"></param> /// <param name="AgentId"></param> /// <param name="cap"></param> /// <returns></returns> public Hashtable ProcessAdd(Hashtable request, UUID AgentId, Caps cap) { Hashtable responsedata = new Hashtable(); responsedata["int_response_code"] = 400; //501; //410; //404; responsedata["content_type"] = "text/plain"; responsedata["keepalive"] = false; responsedata["str_response_string"] = "Request wasn't what was expected"; ScenePresence avatar; if (!m_scene.TryGetScenePresence(AgentId, out avatar)) { return(responsedata); } OSDMap r = (OSDMap)OSDParser.Deserialize((string)request["requestbody"]); UploadObjectAssetMessage message = new UploadObjectAssetMessage(); try { message.Deserialize(r); } catch (Exception ex) { m_log.Error("[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString()); message = null; } if (message == null) { responsedata["int_response_code"] = 400; //501; //410; //404; responsedata["content_type"] = "text/plain"; responsedata["keepalive"] = false; responsedata["str_response_string"] = "<llsd><map><key>error</key><string>Error parsing Object</string></map></llsd>"; return(responsedata); } Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation); Quaternion rot = Quaternion.Identity; Vector3 rootpos = Vector3.Zero; // Quaternion rootrot = Quaternion.Identity; SceneObjectGroup rootGroup = null; SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length]; for (int i = 0; i < message.Objects.Length; i++) { UploadObjectAssetMessage.Object obj = message.Objects[i]; PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); if (i == 0) { rootpos = obj.Position; // rootrot = obj.Rotation; } // Combine the extraparams data into it's ugly blob again.... //int bytelength = 0; //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) //{ // bytelength += obj.ExtraParams[extparams].ExtraParamData.Length; //} //byte[] extraparams = new byte[bytelength]; //int position = 0; //for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) //{ // Buffer.BlockCopy(obj.ExtraParams[extparams].ExtraParamData, 0, extraparams, position, // obj.ExtraParams[extparams].ExtraParamData.Length); // // position += obj.ExtraParams[extparams].ExtraParamData.Length; // } //pbs.ExtraParams = extraparams; for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) { UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams]; switch ((ushort)extraParam.Type) { case (ushort)ExtraParamType.Sculpt: Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); pbs.SculptEntry = true; pbs.SculptTexture = obj.SculptID; pbs.SculptType = (byte)sculpt.Type; break; case (ushort)ExtraParamType.Flexible: Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); pbs.FlexiEntry = true; pbs.FlexiDrag = flex.Drag; pbs.FlexiForceX = flex.Force.X; pbs.FlexiForceY = flex.Force.Y; pbs.FlexiForceZ = flex.Force.Z; pbs.FlexiGravity = flex.Gravity; pbs.FlexiSoftness = flex.Softness; pbs.FlexiTension = flex.Tension; pbs.FlexiWind = flex.Wind; break; case (ushort)ExtraParamType.Light: Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0); pbs.LightColorA = light.Color.A; pbs.LightColorB = light.Color.B; pbs.LightColorG = light.Color.G; pbs.LightColorR = light.Color.R; pbs.LightCutoff = light.Cutoff; pbs.LightEntry = true; pbs.LightFalloff = light.Falloff; pbs.LightIntensity = light.Intensity; pbs.LightRadius = light.Radius; break; case 0x40: pbs.ReadProjectionData(extraParam.ExtraParamData, 0); break; } } pbs.PathBegin = (ushort)obj.PathBegin; pbs.PathCurve = (byte)obj.PathCurve; pbs.PathEnd = (ushort)obj.PathEnd; pbs.PathRadiusOffset = (sbyte)obj.RadiusOffset; pbs.PathRevolutions = (byte)obj.Revolutions; pbs.PathScaleX = (byte)obj.ScaleX; pbs.PathScaleY = (byte)obj.ScaleY; pbs.PathShearX = (byte)obj.ShearX; pbs.PathShearY = (byte)obj.ShearY; pbs.PathSkew = (sbyte)obj.Skew; pbs.PathTaperX = (sbyte)obj.TaperX; pbs.PathTaperY = (sbyte)obj.TaperY; pbs.PathTwist = (sbyte)obj.Twist; pbs.PathTwistBegin = (sbyte)obj.TwistBegin; pbs.HollowShape = (HollowShape)obj.ProfileHollow; pbs.PCode = (byte)PCode.Prim; pbs.ProfileBegin = (ushort)obj.ProfileBegin; pbs.ProfileCurve = (byte)obj.ProfileCurve; pbs.ProfileEnd = (ushort)obj.ProfileEnd; pbs.Scale = obj.Scale; pbs.State = (byte)0; SceneObjectPart prim = new SceneObjectPart(); prim.UUID = UUID.Random(); prim.CreatorID = AgentId; prim.OwnerID = AgentId; prim.GroupID = obj.GroupID; prim.LastOwnerID = prim.OwnerID; prim.CreationDate = Util.UnixTimeSinceEpoch(); prim.Name = obj.Name; prim.Description = ""; prim.PayPrice[0] = -2; prim.PayPrice[1] = -2; prim.PayPrice[2] = -2; prim.PayPrice[3] = -2; prim.PayPrice[4] = -2; Primitive.TextureEntry tmp = new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f")); for (int j = 0; j < obj.Faces.Length; j++) { UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; Primitive.TextureEntryFace primFace = tmp.CreateFace((uint)j); 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 & 1) != 0); primFace.OffsetU = face.OffsetS; primFace.OffsetV = face.OffsetT; primFace.RepeatU = face.ScaleS; primFace.RepeatV = face.ScaleT; primFace.TexMapType = (MappingType)(face.MediaFlags & 6); } pbs.TextureEntry = tmp.GetBytes(); prim.Shape = pbs; prim.Scale = obj.Scale; SceneObjectGroup grp = new SceneObjectGroup(); grp.SetRootPart(prim); prim.ParentID = 0; if (i == 0) { rootGroup = grp; } grp.AttachToScene(m_scene); grp.AbsolutePosition = obj.Position; prim.RotationOffset = obj.Rotation; grp.RootPart.IsAttachment = false; // Required for linking grp.RootPart.UpdateFlag = 0; if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos)) { m_scene.AddSceneObject(grp); grp.AbsolutePosition = obj.Position; } allparts[i] = grp; } for (int j = 1; j < allparts.Length; j++) { rootGroup.RootPart.UpdateFlag = 0; allparts[j].RootPart.UpdateFlag = 0; rootGroup.LinkToGroup(allparts[j]); } rootGroup.ScheduleGroupForFullUpdate(); pos = m_scene.GetNewRezLocation(Vector3.Zero, rootpos, UUID.Zero, rot, (byte)1, 1, true, allparts[0].GroupScale(), false); responsedata["int_response_code"] = 200; //501; //410; //404; responsedata["content_type"] = "text/plain"; responsedata["keepalive"] = false; responsedata["str_response_string"] = String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId)); return(responsedata); }
public static void WriteShape(XmlTextWriter writer, Primitive prim, Primitive.ObjectProperties props, Primitive.ConstructionData shp, ImportSettings options) { if (true /*shp != null*/) { writer.WriteStartElement("Shape"); WriteEnum(writer, "ProfileCurve", shp.ProfileCurve); writer.WriteStartElement("TextureEntry"); byte[] te; if (prim.Textures != null) { te = prim.Textures.GetBytes(); } else { te = Utils.EmptyBytes; } writer.WriteBase64(te, 0, te.Length); writer.WriteEndElement(); // TextureEntry writer.WriteStartElement("ExtraParams"); byte[] ep; if (prim.GetExtraParamsBytes() != null) { ep = prim.GetExtraParamsBytes(); } else { ep = Utils.EmptyBytes; } writer.WriteBase64(ep, 0, ep.Length); writer.WriteEndElement(); // ExtraParams writer.WriteElementString("PathBegin", Primitive.PackBeginCut(shp.PathBegin).ToString()); WriteEnum(writer, "PathCurve", shp.PathCurve); writer.WriteElementString("PathEnd", Primitive.PackEndCut(shp.PathEnd).ToString()); writer.WriteElementString("PathRadiusOffset", Primitive.PackPathTwist(shp.PathRadiusOffset).ToString()); writer.WriteElementString("PathRevolutions", Primitive.PackPathRevolutions(shp.PathRevolutions).ToString()); writer.WriteElementString("PathScaleX", Primitive.PackPathScale(shp.PathScaleX).ToString()); writer.WriteElementString("PathScaleY", Primitive.PackPathScale(shp.PathScaleY).ToString()); writer.WriteElementString("PathShearX", ((byte)Primitive.PackPathShear(shp.PathShearX)).ToString()); writer.WriteElementString("PathShearY", ((byte)Primitive.PackPathShear(shp.PathShearY)).ToString()); writer.WriteElementString("PathSkew", Primitive.PackPathTwist(shp.PathSkew).ToString()); writer.WriteElementString("PathTaperX", Primitive.PackPathTaper(shp.PathTaperX).ToString()); writer.WriteElementString("PathTaperY", Primitive.PackPathTaper(shp.PathTaperY).ToString()); writer.WriteElementString("PathTwist", Primitive.PackPathTwist(shp.PathTwist).ToString()); writer.WriteElementString("PathTwistBegin", Primitive.PackPathTwist(shp.PathTwistBegin).ToString()); writer.WriteElementString("ProfileBegin", Primitive.PackBeginCut(shp.ProfileBegin).ToString()); writer.WriteElementString("ProfileEnd", Primitive.PackEndCut(shp.ProfileEnd).ToString()); writer.WriteElementString("ProfileHollow", Primitive.PackProfileHollow(shp.ProfileHollow).ToString()); WriteEnum(writer, "PCode", shp.PCode); // this is Attachment in a way? WriteInt(writer, "State", shp.State); //WriteEnum(writer, "State", shp.AttachmentPoint); WriteFlags(writer, "ProfileShape", shp.ProfileCurve, options); WriteFlags(writer, "HollowShape", shp.ProfileHole, options); var Sculpt = prim.Sculpt; if (Sculpt != null) { WriteUUID(writer, "SculptTexture", Sculpt.SculptTexture, options); WriteEnum(writer, "SculptType", Sculpt.Type); writer.WriteStartElement("SculptData"); byte[] sd; if (prim.Sculpt != null) { sd = Sculpt.GetBytes(); } else { sd = Utils.EmptyBytes; } writer.WriteBase64(sd, 0, sd.Length); writer.WriteEndElement(); // SculptData } Primitive.FlexibleData Flexi = prim.Flexible; if (Flexi != null) { WriteInt(writer, "FlexiSoftness", Flexi.Softness); WriteFloat(writer, "FlexiTension", Flexi.Tension); WriteFloat(writer, "FlexiDrag", Flexi.Drag); WriteFloat(writer, "FlexiGravity", Flexi.Gravity); WriteFloat(writer, "FlexiWind", Flexi.Wind); WriteFloat(writer, "FlexiForceX", Flexi.Force.X); WriteFloat(writer, "FlexiForceY", Flexi.Force.Y); WriteFloat(writer, "FlexiForceZ", Flexi.Force.Z); } Primitive.LightData Light = prim.Light; if (Light != null) { WriteFloat(writer, "LightColorR", Light.Color.R); WriteFloat(writer, "LightColorG", Light.Color.G); WriteFloat(writer, "LightColorB", Light.Color.B); WriteFloat(writer, "LightColorA", Light.Color.A); WriteFloat(writer, "LightRadius", Light.Radius); WriteFloat(writer, "LightCutoff", Light.Cutoff); WriteFloat(writer, "LightFalloff", Light.Falloff); WriteFloat(writer, "LightIntensity", Light.Intensity); } WriteValue(writer, "FlexiEntry", (Flexi != null).ToString().ToLower()); WriteValue(writer, "LightEntry", (Light != null).ToString().ToLower()); WriteValue(writer, "SculptEntry", (Sculpt != null).ToString().ToLower()); //todo if (shp.Media != null) WES(writer,"Media", shp.Media.ToXml()); writer.WriteEndElement(); // Shape } }
private void SetPrimParams(IScriptInstance script, ISceneEntity entity, object[] rules) { LLPrimitive prim = entity as LLPrimitive; if (prim == null) { return; } bool changedShape = false, changedColor = false, changedTexture = false; int i = 0; while (i < rules.Length) { int code = llList2Integer(script, rules, i++); switch (code) { case LSLConstants.PRIM_NAME: { SetObjectName(prim, llList2String(script, rules, i++)); break; } case LSLConstants.PRIM_DESC: { SetObjectDesc(prim, llList2String(script, rules, i++)); break; } case LSLConstants.PRIM_TYPE: { SetPrimType(script, rules, ref i); prim.Scene.EntityAddOrUpdate(this, prim, UpdateFlags.Shape, 0); changedShape = true; break; } case LSLConstants.PRIM_MATERIAL: { prim.Prim.PrimData.Material = (Material)llList2Integer(script, rules, i++); prim.Scene.EntityAddOrUpdate(this, prim, 0, (uint)LLUpdateFlags.Material); break; } case LSLConstants.PRIM_PHYSICS: { SetStatus(prim, LSLConstants.STATUS_PHYSICS, llList2Integer(script, rules, i++)); break; } case LSLConstants.PRIM_TEMP_ON_REZ: { bool tempOnRez = (llList2Integer(script, rules, i++) != 0); LLPrimitive parent = GetRootEntity(prim) as LLPrimitive; if (parent != null) { if (tempOnRez) { parent.Prim.Flags |= PrimFlags.TemporaryOnRez; } else { parent.Prim.Flags &= ~PrimFlags.TemporaryOnRez; } parent.Scene.EntityAddOrUpdate(this, parent, 0, (uint)LLUpdateFlags.PrimFlags); } break; } case LSLConstants.PRIM_PHANTOM: { SetStatus(prim, LSLConstants.STATUS_PHANTOM, llList2Integer(script, rules, i++)); break; } case LSLConstants.PRIM_POSITION: { SetPos(prim, llList2Vector(script, rules, i++)); break; } case LSLConstants.PRIM_ROTATION: { SetRot(prim, llList2Rot(script, rules, i++)); break; } case LSLConstants.PRIM_SIZE: { SetScale(prim, llList2Vector(script, rules, i++)); break; } case LSLConstants.PRIM_TEXTURE: { int face = llList2Integer(script, rules, i++); string texture = llList2String(script, rules, i++); Vector3 repeats = llList2Vector(script, rules, i++); Vector3 offsets = llList2Vector(script, rules, i++); float rotRadians = llList2Float(script, rules, i++); SetTexture(script, prim, texture, face); ScaleTexture(script, prim, repeats.X, repeats.Y, face); OffsetTexture(script, prim, offsets.X, offsets.Y, face); RotateTexture(script, prim, rotRadians, face); changedTexture = true; break; } case LSLConstants.PRIM_TEXT: { string text = llList2String(script, rules, i++); Vector3 color = llList2Vector(script, rules, i++); float alpha = llList2Float(script, rules, i++); SetText(prim, text, color, alpha); break; } case LSLConstants.PRIM_COLOR: { int face = llList2Integer(script, rules, i++); Vector3 color = llList2Vector(script, rules, i++); float alpha = llList2Float(script, rules, i++); SetColor(prim, color, face); SetAlpha(prim, alpha, face); changedColor = true; break; } case LSLConstants.PRIM_BUMP_SHINY: { int face = llList2Integer(script, rules, i++); Shininess shiny = (Shininess)llList2Integer(script, rules, i++); Bumpiness bump = (Bumpiness)llList2Integer(script, rules, i++); SetShinyBump(prim, shiny, bump, face); changedTexture = true; break; } case LSLConstants.PRIM_POINT_LIGHT: { bool enabled = (llList2Integer(script, rules, i++) != 0); Vector3 color = llList2Vector(script, rules, i++); float intensity = llList2Float(script, rules, i++); float radius = llList2Float(script, rules, i++); float falloff = llList2Float(script, rules, i++); if (enabled) { Primitive.LightData light = new Primitive.LightData(); light.Color = new Color4( Utils.Clamp(color.X, 0f, 1f), Utils.Clamp(color.Y, 0f, 1f), Utils.Clamp(color.Z, 0f, 1f), 1f); light.Intensity = intensity; light.Radius = radius; light.Falloff = falloff; prim.Prim.Light = light; } else { prim.Prim.Light = null; } prim.Scene.EntityAddOrUpdate(this, prim, 0, (uint)LLUpdateFlags.ExtraData); break; } case LSLConstants.PRIM_FULLBRIGHT: { int face = llList2Integer(script, rules, i++); bool fullbright = (llList2Integer(script, rules, i++) != 0); SetFullbright(prim, fullbright, face); changedTexture = true; break; } case LSLConstants.PRIM_FLEXIBLE: { bool enabled = (llList2Integer(script, rules, i++) != 0); int softness = llList2Integer(script, rules, i++); float gravity = llList2Float(script, rules, i++); float friction = llList2Float(script, rules, i++); float wind = llList2Float(script, rules, i++); float tension = llList2Float(script, rules, i++); Vector3 force = llList2Vector(script, rules, i++); if (enabled) { Primitive.FlexibleData flex = new Primitive.FlexibleData(); flex.Softness = softness; flex.Gravity = gravity; flex.Drag = friction; flex.Wind = wind; flex.Tension = tension; flex.Force = force; prim.Prim.Flexible = flex; } else { prim.Prim.Flexible = null; } prim.Scene.EntityAddOrUpdate(this, prim, 0, (uint)LLUpdateFlags.ExtraData); break; } case LSLConstants.PRIM_TEXGEN: { int face = llList2Integer(script, rules, i++); MappingType texgen = (MappingType)llList2Integer(script, rules, i++); SetTexgen(prim, texgen, face); changedTexture = true; break; } case LSLConstants.PRIM_GLOW: { int face = llList2Integer(script, rules, i++); float intensity = llList2Float(script, rules, i++); SetGlow(prim, intensity, face); changedTexture = true; break; } } } if (m_lslScriptEngine != null) { if (changedShape) { m_lslScriptEngine.PostObjectEvent(prim.ID, "changed", new object[] { LSLConstants.CHANGED_SHAPE }, null); } if (changedTexture) { m_lslScriptEngine.PostObjectEvent(prim.ID, "changed", new object[] { LSLConstants.CHANGED_TEXTURE }, null); } if (changedColor) { m_lslScriptEngine.PostObjectEvent(prim.ID, "changed", new object[] { LSLConstants.CHANGED_COLOR }, null); } } }
/// <summary> /// Parses add request /// </summary> /// <param name="request"></param> /// <param name="agentID"></param> /// <param name="cap"></param> /// <returns></returns> public void ProcessAdd(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, OSDMap map, UUID agentID, Caps cap) { httpResponse.KeepAlive = false; if (!m_scene.TryGetScenePresence(agentID, out ScenePresence avatar)) { httpResponse.StatusCode = (int)HttpStatusCode.Gone; return; } UploadObjectAssetMessage message = new UploadObjectAssetMessage(); try { message.Deserialize(map); } catch (Exception ex) { m_log.Error("[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString()); message = null; } if (message == null) { httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; return; } try { Vector3 pos = avatar.AbsolutePosition + (Vector3.UnitX * avatar.Rotation); Quaternion rot = Quaternion.Identity; Vector3 rootpos = Vector3.Zero; SceneObjectGroup rootGroup = null; SceneObjectGroup[] allparts = new SceneObjectGroup[message.Objects.Length]; for (int i = 0; i < message.Objects.Length; i++) { UploadObjectAssetMessage.Object obj = message.Objects[i]; PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox(); if (i == 0) { rootpos = obj.Position; } for (int extparams = 0; extparams < obj.ExtraParams.Length; extparams++) { UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[extparams]; switch ((ushort)extraParam.Type) { case (ushort)ExtraParamType.Sculpt: Primitive.SculptData sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0); pbs.SculptEntry = true; pbs.SculptTexture = obj.SculptID; pbs.SculptType = (byte)sculpt.Type; break; case (ushort)ExtraParamType.Flexible: Primitive.FlexibleData flex = new Primitive.FlexibleData(extraParam.ExtraParamData, 0); pbs.FlexiEntry = true; pbs.FlexiDrag = flex.Drag; pbs.FlexiForceX = flex.Force.X; pbs.FlexiForceY = flex.Force.Y; pbs.FlexiForceZ = flex.Force.Z; pbs.FlexiGravity = flex.Gravity; pbs.FlexiSoftness = flex.Softness; pbs.FlexiTension = flex.Tension; pbs.FlexiWind = flex.Wind; break; case (ushort)ExtraParamType.Light: Primitive.LightData light = new Primitive.LightData(extraParam.ExtraParamData, 0); pbs.LightColorA = light.Color.A; pbs.LightColorB = light.Color.B; pbs.LightColorG = light.Color.G; pbs.LightColorR = light.Color.R; pbs.LightCutoff = light.Cutoff; pbs.LightEntry = true; pbs.LightFalloff = light.Falloff; pbs.LightIntensity = light.Intensity; pbs.LightRadius = light.Radius; break; case 0x40: pbs.ReadProjectionData(extraParam.ExtraParamData, 0); break; } } pbs.PathBegin = (ushort)obj.PathBegin; pbs.PathCurve = (byte)obj.PathCurve; pbs.PathEnd = (ushort)obj.PathEnd; pbs.PathRadiusOffset = (sbyte)obj.RadiusOffset; pbs.PathRevolutions = (byte)obj.Revolutions; pbs.PathScaleX = (byte)obj.ScaleX; pbs.PathScaleY = (byte)obj.ScaleY; pbs.PathShearX = (byte)obj.ShearX; pbs.PathShearY = (byte)obj.ShearY; pbs.PathSkew = (sbyte)obj.Skew; pbs.PathTaperX = (sbyte)obj.TaperX; pbs.PathTaperY = (sbyte)obj.TaperY; pbs.PathTwist = (sbyte)obj.Twist; pbs.PathTwistBegin = (sbyte)obj.TwistBegin; pbs.HollowShape = (HollowShape)obj.ProfileHollow; pbs.PCode = (byte)PCode.Prim; pbs.ProfileBegin = (ushort)obj.ProfileBegin; pbs.ProfileCurve = (byte)obj.ProfileCurve; pbs.ProfileEnd = (ushort)obj.ProfileEnd; pbs.Scale = obj.Scale; pbs.State = (byte)0; pbs.LastAttachPoint = (byte)0; SceneObjectPart prim = new SceneObjectPart(); prim.UUID = UUID.Random(); prim.CreatorID = agentID; prim.OwnerID = agentID; prim.GroupID = obj.GroupID; prim.LastOwnerID = prim.OwnerID; prim.RezzerID = agentID; prim.CreationDate = Util.UnixTimeSinceEpoch(); prim.Name = obj.Name; prim.Description = ""; prim.PayPrice[0] = -2; prim.PayPrice[1] = -2; prim.PayPrice[2] = -2; prim.PayPrice[3] = -2; prim.PayPrice[4] = -2; Primitive.TextureEntry tmp = new Primitive.TextureEntry(UUID.Parse("89556747-24cb-43ed-920b-47caed15465f")); for (int j = 0; j < obj.Faces.Length; j++) { UploadObjectAssetMessage.Object.Face face = obj.Faces[j]; Primitive.TextureEntryFace primFace = tmp.CreateFace((uint)j); 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 & 1) != 0); primFace.OffsetU = face.OffsetS; primFace.OffsetV = face.OffsetT; primFace.RepeatU = face.ScaleS; primFace.RepeatV = face.ScaleT; primFace.TexMapType = (MappingType)(face.MediaFlags & 6); } pbs.TextureEntry = tmp.GetBytes(); prim.Shape = pbs; prim.Scale = obj.Scale; SceneObjectGroup grp = new SceneObjectGroup(); grp.SetRootPart(prim); prim.ParentID = 0; if (i == 0) { rootGroup = grp; } grp.AttachToScene(m_scene); grp.AbsolutePosition = obj.Position; prim.RotationOffset = obj.Rotation; // Required for linking grp.RootPart.ClearUpdateSchedule(); if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos)) { m_scene.AddSceneObject(grp); grp.AbsolutePosition = obj.Position; } allparts[i] = grp; } for (int j = 1; j < allparts.Length; j++) { // Required for linking rootGroup.RootPart.ClearUpdateSchedule(); allparts[j].RootPart.ClearUpdateSchedule(); rootGroup.LinkToGroup(allparts[j]); } rootGroup.ScheduleGroupForFullAnimUpdate(); httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.RawBuffer = Util.UTF8NBGetbytes(String.Format("<llsd><map><key>local_id</key>{0}</map></llsd>", ConvertUintToBytes(allparts[0].LocalId))); } catch { } httpResponse.StatusCode = (int)HttpStatusCode.BadRequest; }