public bool Compare(ISceneChildEntity part) { if (part != null) { if (part.UUID == part.ParentEntity.UUID) { if (Position == part.AbsolutePosition && Rotation == part.GetRotationOffset() && Scale == part.Shape.Scale) { return(true); } else { return(false); } } else { if (Position == part.OffsetPosition && Rotation == part.GetRotationOffset() && Scale == part.Shape.Scale) { return(true); } else { return(false); } } } return(false); }
public UndoState (ISceneChildEntity part) { if (part != null) { if (part.UUID == part.ParentEntity.UUID) { Position = part.ParentEntity.AbsolutePosition; Rotation = part.GetRotationOffset (); Scale = part.Shape.Scale; } else { Position = part.OffsetPosition; Rotation = part.GetRotationOffset (); Scale = part.Shape.Scale; } } }
public bool Compare (ISceneChildEntity part) { if (part != null) { if (part.UUID == part.ParentEntity.UUID) { if (Position == part.AbsolutePosition && Rotation == part.GetRotationOffset () && Scale == part.Shape.Scale) return true; return false; } if (Position == part.OffsetPosition && Rotation == part.GetRotationOffset () && Scale == part.Shape.Scale) return true; return false; } return false; }
public UndoState(ISceneChildEntity part) { if (part != null) { if (part.UUID == part.ParentEntity.UUID) { Position = part.ParentEntity.AbsolutePosition; Rotation = part.GetRotationOffset(); Scale = part.Shape.Scale; } else { Position = part.OffsetPosition; Rotation = part.GetRotationOffset(); Scale = part.Shape.Scale; } } }
private List <SensedEntity> doAgentSensor(SenseRepeatClass ts) { List <SensedEntity> sensedEntities = new List <SensedEntity>(); // If nobody about quit fast IEntityCountModule entityCountModule = ts.host.ParentEntity.Scene.RequestModuleInterface <IEntityCountModule>(); if (entityCountModule != null && entityCountModule.RootAgents == 0) { return(sensedEntities); } ISceneChildEntity SensePoint = ts.host; Vector3 fromRegionPos = SensePoint.AbsolutePosition; Quaternion q = SensePoint.GetRotationOffset(); LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); bool attached = (SensePoint.AttachmentPoint != 0); Vector3 toRegionPos; double dis; Action <IScenePresence> senseEntity = delegate(IScenePresence presence) { if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) { return; } // if the object the script is in is attached and the avatar is the owner // then this one is not wanted if (attached && presence.UUID == SensePoint.OwnerID) { return; } toRegionPos = presence.AbsolutePosition; dis = Math.Abs(Util.GetDistanceTo(toRegionPos, fromRegionPos)); // are they in range if (dis <= ts.range) { // Are they in the required angle of view if (ts.arc < Math.PI) { // not omni-directional. Can you see it ? // vec forward_dir = llRot2Fwd(llGetRot()) // vec obj_dir = toRegionPos-fromRegionPos // dot=dot(forward_dir,obj_dir) // mag_fwd = mag(forward_dir) // mag_obj = mag(obj_dir) // ang = acos(dot /(mag_fwd*mag_obj)) double ang_obj = 0; try { Vector3 diff = toRegionPos - fromRegionPos; LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); double mag_obj = LSL_Types.Vector3.Mag(obj_dir); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); } catch { } if (ang_obj <= ts.arc) { sensedEntities.Add(new SensedEntity(dis, presence.UUID)); } } else { sensedEntities.Add(new SensedEntity(dis, presence.UUID)); } } }; // If this is an avatar sense by key try to get them directly // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { IScenePresence sp; // Try direct lookup by UUID if (!ts.host.ParentEntity.Scene.TryGetScenePresence(ts.keyID, out sp)) { return(sensedEntities); } senseEntity(sp); } else if (!string.IsNullOrEmpty(ts.name)) { IScenePresence sp; // Try lookup by name will return if/when found if (!ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp)) { return(sensedEntities); } if (((ts.type & AGENT) != 0) && ts.host.ParentEntity.Scene.TryGetAvatarByName(ts.name, out sp)) { senseEntity(sp); } if ((ts.type & AGENT_BY_USERNAME) != 0) { ts.host.ParentEntity.Scene.ForEachScenePresence( delegate(IScenePresence ssp) { if (ssp.Name.Replace(" ", ".").ToLower() == ts.name) { senseEntity(ssp); } } ); } } else { ts.host.ParentEntity.Scene.ForEachScenePresence(senseEntity); } return(sensedEntities); }
private List <SensedEntity> doObjectSensor(SenseRepeatClass ts) { List <ISceneEntity> Entities; List <SensedEntity> sensedEntities = new List <SensedEntity>(); ISceneChildEntity SensePoint = ts.host; Vector3 fromRegionPos = SensePoint.AbsolutePosition; // If this is an object sense by key try to get it directly // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { IEntity e = null; ts.host.ParentEntity.Scene.Entities.TryGetValue(ts.keyID, out e); if (e == null || !(e is ISceneEntity)) { return(sensedEntities); } Entities = new List <ISceneEntity> { e as ISceneEntity }; } else { Entities = new List <ISceneEntity>(ts.host.ParentEntity.Scene.Entities.GetEntities(fromRegionPos, (float)ts.range)); } // pre define some things to avoid repeated definitions in the loop body Vector3 toRegionPos; double dis; int objtype; ISceneChildEntity part; float dx; float dy; float dz; Quaternion q = SensePoint.GetRotationOffset(); if (SensePoint.ParentEntity.RootChild.IsAttachment) { // In attachments, the sensor cone always orients with the // avatar rotation. This may include a nonzero elevation if // in mouselook. IScenePresence avatar = ts.host.ParentEntity.Scene.GetScenePresence(SensePoint.ParentEntity.RootChild.AttachedAvatar); q = avatar.Rotation; } LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); Vector3 ZeroVector = new Vector3(0, 0, 0); bool nameSearch = !string.IsNullOrEmpty(ts.name); foreach (ISceneEntity ent in Entities) { bool keep = true; if (nameSearch && ent.Name != ts.name) // Wrong name and it is a named search { continue; } if (ent.IsDeleted) // taken so long to do this it has gone from the scene { continue; } if (!(ent is ISceneEntity)) // dont bother if it is a pesky avatar { continue; } toRegionPos = ent.AbsolutePosition; // Calculation is in line for speed dx = toRegionPos.X - fromRegionPos.X; dy = toRegionPos.Y - fromRegionPos.Y; dz = toRegionPos.Z - fromRegionPos.Z; // Weed out those that will not fit in a cube the size of the range // no point calculating if they are within a sphere the size of the range // if they arent even in the cube if (Math.Abs(dx) > ts.range || Math.Abs(dy) > ts.range || Math.Abs(dz) > ts.range) { dis = ts.range + 1.0; } else { dis = Math.Sqrt(dx * dx + dy * dy + dz * dz); } if (keep && dis <= ts.range && ts.host.UUID != ent.UUID) { // In Range and not the object containing the script, is it the right Type ? objtype = 0; part = (ent).RootChild; if (part.AttachmentPoint != 0) // Attached so ignore { continue; } if (part.Inventory.ContainsScripts()) { objtype |= ACTIVE | SCRIPTED; // Scripted and active. It COULD have one hidden ... } else { if (ent.Velocity.Equals(ZeroVector)) { objtype |= PASSIVE; // Passive non-moving } else { objtype |= ACTIVE; // moving so active } } // If any of the objects attributes match any in the requested scan type if (((ts.type & objtype) != 0)) { // Right type too, what about the other params , key and name ? if (ts.arc < Math.PI) { // not omni-directional. Can you see it ? // vec forward_dir = llRot2Fwd(llGetRot()) // vec obj_dir = toRegionPos-fromRegionPos // dot=dot(forward_dir,obj_dir) // mag_fwd = mag(forward_dir) // mag_obj = mag(obj_dir) // ang = acos(dot /(mag_fwd*mag_obj)) double ang_obj = 0; try { Vector3 diff = toRegionPos - fromRegionPos; LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); double mag_obj = LSL_Types.Vector3.Mag(obj_dir); ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); } catch { } if (ang_obj > ts.arc) { keep = false; } } if (keep) { // add distance for sorting purposes later sensedEntities.Add(new SensedEntity(dis, ent.UUID)); } } } } return(sensedEntities); }
void CreatePrim (WarpRenderer renderer, ISceneChildEntity prim) { try { if ((PCode)prim.Shape.PCode != PCode.Prim) return; if (prim.Scale.LengthSquared () < MIN_PRIM_SIZE * MIN_PRIM_SIZE) return; Primitive omvPrim = prim.Shape.ToOmvPrimitive (prim.OffsetPosition, prim.GetRotationOffset ()); FacetedMesh renderMesh = null; // Are we dealing with a sculptie or mesh? if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) { // Try fetching the asset byte [] sculptAsset = m_scene.AssetService.GetData (omvPrim.Sculpt.SculptTexture.ToString ()); if (sculptAsset != null) { // Is it a mesh? if (omvPrim.Sculpt.Type == SculptType.Mesh) { AssetMesh meshAsset = new AssetMesh (omvPrim.Sculpt.SculptTexture, sculptAsset); FacetedMesh.TryDecodeFromAsset (omvPrim, meshAsset, DetailLevel.Highest, out renderMesh); meshAsset = null; } else // It's sculptie { Image sculpt = m_imgDecoder.DecodeToImage (sculptAsset); if (sculpt != null) { renderMesh = m_primMesher.GenerateFacetedSculptMesh (omvPrim, (Bitmap)sculpt, DetailLevel.Medium); sculpt.Dispose (); } } sculptAsset = null; } else { // missing sculpt data... replace with something renderMesh = m_primMesher.GenerateFacetedMesh (omvPrim, DetailLevel.Medium); } } else // Prim { renderMesh = m_primMesher.GenerateFacetedMesh (omvPrim, DetailLevel.Medium); } if (renderMesh == null) return; warp_Vector primPos = ConvertVector (prim.GetWorldPosition ()); warp_Quaternion primRot = ConvertQuaternion (prim.GetRotationOffset ()); warp_Matrix m = warp_Matrix.quaternionMatrix (primRot); if (prim.ParentID != 0) { ISceneEntity group = m_scene.GetGroupByPrim (prim.LocalId); if (group != null) m.transform (warp_Matrix.quaternionMatrix (ConvertQuaternion (group.RootChild.GetRotationOffset ()))); } warp_Vector primScale = ConvertVector (prim.Scale); string primID = prim.UUID.ToString (); // Create the prim faces for (int i = 0; i < renderMesh.Faces.Count; i++) { Face renderFace = renderMesh.Faces [i]; string meshName = primID + "-Face-" + i; warp_Object faceObj = new warp_Object (renderFace.Vertices.Count, renderFace.Indices.Count / 3); foreach (Vertex v in renderFace.Vertices) { warp_Vector pos = ConvertVector (v.Position); warp_Vector norm = ConvertVector (v.Normal); if (prim.Shape.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 < renderFace.Indices.Count;) { faceObj.addTriangle ( renderFace.Indices [j++], renderFace.Indices [j++], renderFace.Indices [j++]); } Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace ((uint)i); string materialName; Color4 faceColor = GetFaceColor (teFace); if (m_texturePrims && (prim.Scale.LengthSquared () > m_texturePrimSize)) { materialName = GetOrCreateMaterial (renderer, faceColor, teFace.TextureID); } else { 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); faceObj = null; } renderMesh.Faces.Clear (); renderMesh = null; } catch (Exception ex) { MainConsole.Instance.Warn ("[Warp3D]: Exception creating prim, " + ex); } }
public LSL_List GetLinkPrimitiveParams(ISceneChildEntity part, LSL_List rules) { LSL_List res = new LSL_List(); int idx = 0; while (idx < rules.Length) { int code = rules.GetLSLIntegerItem(idx++); int remain = rules.Length - idx; Primitive.TextureEntry tex = part.Shape.Textures; int face = 0; if (code == (int) ScriptBaseClass.PRIM_NAME) { res.Add(new LSL_String(part.Name)); } else if (code == (int) ScriptBaseClass.PRIM_DESC) { res.Add(new LSL_String(part.Description)); } else if (code == (int) ScriptBaseClass.PRIM_MATERIAL) { res.Add(new LSL_Integer(part.Material)); } else if (code == (int) ScriptBaseClass.PRIM_PHYSICS) { res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.Physics) != 0 ? new LSL_Integer(1) : new LSL_Integer(0)); } else if (code == (int) ScriptBaseClass.PRIM_TEMP_ON_REZ) { res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.TemporaryOnRez) != 0 ? new LSL_Integer(1) : new LSL_Integer(0)); } else if (code == (int) ScriptBaseClass.PRIM_PHANTOM) { res.Add((part.GetEffectiveObjectFlags() & (uint) PrimFlags.Phantom) != 0 ? new LSL_Integer(1) : new LSL_Integer(0)); } else if (code == (int) ScriptBaseClass.PRIM_POSITION) { Vector3 tmp = part.AbsolutePosition; LSL_Vector v = new LSL_Vector(tmp.X, tmp.Y, tmp.Z); // For some reason, the part.AbsolutePosition.* values do not change if the // linkset is rotated; they always reflect the child prim's world position // as though the linkset is unrotated. This is incompatible behavior with SL's // implementation, so will break scripts imported from there (not to mention it // makes it more difficult to determine a child prim's actual inworld position). if (part.ParentID != 0) { LSL_Rotation rtmp = llGetRootRotation(); LSL_Vector rpos = llGetRootPosition(); v = ((v - rpos)*rtmp) + rpos; } res.Add(v); } else if (code == (int) ScriptBaseClass.PRIM_POS_LOCAL) { res.Add(GetLocalPos(part)); } else if (code == (int) ScriptBaseClass.PRIM_SIZE) { Vector3 tmp = part.Scale; res.Add(new LSL_Vector(tmp.X, tmp.Y, tmp.Z)); } else if (code == (int) ScriptBaseClass.PRIM_ROTATION) { res.Add(GetPartRot(part)); } else if (code == (int) ScriptBaseClass.PRIM_TYPE) { // implementing box PrimitiveBaseShape Shape = part.Shape; int primType = (int) part.GetPrimType(); res.Add(new LSL_Integer(primType)); double topshearx = (sbyte) Shape.PathShearX/100.0; // Fix negative values for PathShearX double topsheary = (sbyte) Shape.PathShearY/100.0; // and PathShearY. if (primType == ScriptBaseClass.PRIM_TYPE_BOX || primType == ScriptBaseClass.PRIM_TYPE_CYLINDER || primType == ScriptBaseClass.PRIM_TYPE_PRISM) { res.Add(new LSL_Integer(Shape.ProfileCurve)); res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0)); res.Add(new LSL_Float(Shape.ProfileHollow/50000.0)); res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0)); res.Add(new LSL_Vector(1 - (Shape.PathScaleX/100.0 - 1), 1 - (Shape.PathScaleY/100.0 - 1), 0)); res.Add(new LSL_Vector(topshearx, topsheary, 0)); } if (primType == ScriptBaseClass.PRIM_TYPE_SPHERE) { res.Add(new LSL_Integer(Shape.ProfileCurve)); res.Add(new LSL_Vector(Shape.PathBegin/50000.0, 1 - Shape.PathEnd/50000.0, 0)); res.Add(new LSL_Float(Shape.ProfileHollow/50000.0)); res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0)); res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0)); } if (primType == ScriptBaseClass.PRIM_TYPE_SCULPT) { res.Add(Shape.SculptTexture.ToString()); res.Add(new LSL_Integer(Shape.SculptType)); } if (primType == ScriptBaseClass.PRIM_TYPE_RING || primType == ScriptBaseClass.PRIM_TYPE_TUBE || primType == ScriptBaseClass.PRIM_TYPE_TORUS) { // holeshape res.Add(new LSL_Integer(Shape.ProfileCurve)); // cut res.Add(new LSL_Vector(Shape.PathBegin/50000.0, 1 - Shape.PathEnd/50000.0, 0)); // hollow res.Add(new LSL_Float(Shape.ProfileHollow/50000.0)); // twist res.Add(new LSL_Vector(Shape.PathTwistBegin/100.0, Shape.PathTwist/100.0, 0)); // vector holesize res.Add(new LSL_Vector(1 - (Shape.PathScaleX/100.0 - 1), 1 - (Shape.PathScaleY/100.0 - 1), 0)); // vector topshear res.Add(new LSL_Vector(topshearx, topsheary, 0)); // vector profilecut res.Add(new LSL_Vector(Shape.ProfileBegin/50000.0, 1 - Shape.ProfileEnd/50000.0, 0)); // vector tapera res.Add(new LSL_Vector(Shape.PathTaperX/100.0, Shape.PathTaperY/100.0, 0)); // float revolutions res.Add( new LSL_Float(Math.Round(Shape.PathRevolutions*0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d); // Slightly inaccurate, because an unsigned byte is being used to represent // the entire range of floating-point values from 1.0 through 4.0 (which is how // SL does it). // // Using these formulas to store and retrieve PathRevolutions, it is not // possible to use all values between 1.00 and 4.00. For instance, you can't // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11. // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value // such as 1.10. So, SL must store and retreive the actual user input rather // than only storing the encoded value. // float radiusoffset res.Add(new LSL_Float(Shape.PathRadiusOffset/100.0)); // float skew res.Add(new LSL_Float(Shape.PathSkew/100.0)); } } else if (code == (int) ScriptBaseClass.PRIM_TEXTURE) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_String(texface.TextureID.ToString())); res.Add(new LSL_Vector(texface.RepeatU, texface.RepeatV, 0)); res.Add(new LSL_Vector(texface.OffsetU, texface.OffsetV, 0)); res.Add(new LSL_Float(texface.Rotation)); } } else { if (face >= 0 && face < GetNumberOfSides(part)) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_String(texface.TextureID.ToString())); res.Add(new LSL_Vector(texface.RepeatU, texface.RepeatV, 0)); res.Add(new LSL_Vector(texface.OffsetU, texface.OffsetV, 0)); res.Add(new LSL_Float(texface.Rotation)); } } } else if (code == (int) ScriptBaseClass.PRIM_COLOR) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); tex = part.Shape.Textures; Color4 texcolor; if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { texcolor = tex.GetFace((uint) face).RGBA; res.Add(new LSL_Vector(texcolor.R, texcolor.G, texcolor.B)); res.Add(new LSL_Float(texcolor.A)); } } else { texcolor = tex.GetFace((uint) face).RGBA; res.Add(new LSL_Vector(texcolor.R, texcolor.G, texcolor.B)); res.Add(new LSL_Float(texcolor.A)); } } else if (code == (int) ScriptBaseClass.PRIM_BUMP_SHINY) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); // Convert Shininess to PRIM_SHINY_* res.Add(new LSL_Integer((uint) texface.Shiny >> 6)); // PRIM_BUMP_* res.Add(new LSL_Integer((int) texface.Bump)); } } else { if (face >= 0 && face < GetNumberOfSides(part)) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); // Convert Shininess to PRIM_SHINY_* res.Add(new LSL_Integer((uint) texface.Shiny >> 6)); // PRIM_BUMP_* res.Add(new LSL_Integer((int) texface.Bump)); } } } else if (code == (int) ScriptBaseClass.PRIM_FULLBRIGHT) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); tex = part.Shape.Textures; if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); } } else { if (face >= 0 && face < GetNumberOfSides(part)) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0)); } } } else if (code == (int) ScriptBaseClass.PRIM_FLEXIBLE) { PrimitiveBaseShape shape = part.Shape; res.Add(shape.FlexiEntry ? new LSL_Integer(1) : new LSL_Integer(0)); res.Add(new LSL_Integer(shape.FlexiSoftness)); // softness res.Add(new LSL_Float(shape.FlexiGravity)); // gravity res.Add(new LSL_Float(shape.FlexiDrag)); // friction res.Add(new LSL_Float(shape.FlexiWind)); // wind res.Add(new LSL_Float(shape.FlexiTension)); // tension res.Add(new LSL_Vector(shape.FlexiForceX, // force shape.FlexiForceY, shape.FlexiForceZ)); } else if (code == (int) ScriptBaseClass.PRIM_TEXGEN) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { MappingType texgen = tex.GetFace((uint) face).TexMapType; // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc. res.Add(new LSL_Integer((uint) texgen >> 1)); } } else { if (face >= 0 && face < GetNumberOfSides(part)) { MappingType texgen = tex.GetFace((uint) face).TexMapType; res.Add(new LSL_Integer((uint) texgen >> 1)); } } } else if (code == (int) ScriptBaseClass.PRIM_POINT_LIGHT) { PrimitiveBaseShape shape = part.Shape; res.Add(shape.LightEntry ? new LSL_Integer(1) : new LSL_Integer(0)); res.Add(new LSL_Vector(shape.LightColorR, // color shape.LightColorG, shape.LightColorB)); res.Add(new LSL_Float(shape.LightIntensity)); // intensity res.Add(new LSL_Float(shape.LightRadius)); // radius res.Add(new LSL_Float(shape.LightFalloff)); // falloff } else if (code == (int) ScriptBaseClass.PRIM_GLOW) { if (remain < 1) return res; face = rules.GetLSLIntegerItem(idx++); if (face == ScriptBaseClass.ALL_SIDES) { for (face = 0; face < GetNumberOfSides(part); face++) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_Float(texface.Glow)); } } else { if (face >= 0 && face < GetNumberOfSides(part)) { Primitive.TextureEntryFace texface = tex.GetFace((uint) face); res.Add(new LSL_Float(texface.Glow)); } } } else if (code == (int) ScriptBaseClass.PRIM_TEXT) { Color4 textColor = part.GetTextColor(); res.Add(new LSL_String(part.Text)); res.Add(new LSL_Vector(textColor.R, textColor.G, textColor.B)); res.Add(new LSL_Float(textColor.A)); } else if (code == (int) ScriptBaseClass.PRIM_ROT_LOCAL) { Quaternion rtmp = part.GetRotationOffset(); res.Add(new LSL_Rotation(rtmp.X, rtmp.Y, rtmp.Z, rtmp.W)); } else if (code == (int) ScriptBaseClass.PRIM_OMEGA) { Vector3 axis = part.OmegaAxis; LSL_Float spinRate = part.OmegaSpinRate; LSL_Float gain = part.OmegaGain; res.Add(axis); res.Add(spinRate); res.Add(gain); } else if (code == (int) ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE) { res.Add(new LSL_Integer(part.PhysicsType)); } else if (code == (int) ScriptBaseClass.PRIM_LINK_TARGET) { if (remain < 1) continue; LSL_Integer nextLink = rules.GetLSLIntegerItem(idx++); List<ISceneChildEntity> entities = GetLinkParts(nextLink); if (entities.Count > 0) part = entities[0]; } } return res; }
void CreatePrim(WarpRenderer renderer, ISceneChildEntity prim, bool texturePrims) { try { if ((PCode)prim.Shape.PCode != PCode.Prim) { return; } if (prim.Scale.LengthSquared() < MIN_PRIM_SIZE * MIN_PRIM_SIZE) { return; } Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.GetRotationOffset()); FacetedMesh renderMesh = null; // Are we dealing with a sculptie or mesh? if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) { // Try fetching the asset byte [] sculptAsset = m_scene.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString()); if (sculptAsset != null) { // Is it a mesh? if (omvPrim.Sculpt.Type == SculptType.Mesh) { AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset); FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out renderMesh); meshAsset = null; } else // It's sculptie { Image sculpt = m_imgDecoder.DecodeToImage(sculptAsset); if (sculpt != null) { renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, DetailLevel.Medium); sculpt.Dispose(); } } sculptAsset = null; } else { // missing sculpt data... replace with something renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); } } else // Prim { renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); } if (renderMesh == null) { return; } warp_Vector primPos = ConvertVector(prim.GetWorldPosition()); warp_Quaternion primRot = ConvertQuaternion(prim.GetRotationOffset()); warp_Matrix m = warp_Matrix.quaternionMatrix(primRot); if (prim.ParentID != 0) { ISceneEntity group = m_scene.GetGroupByPrim(prim.LocalId); if (group != null) { m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootChild.GetRotationOffset()))); } } warp_Vector primScale = ConvertVector(prim.Scale); string primID = prim.UUID.ToString(); // Create the prim faces for (int i = 0; i < renderMesh.Faces.Count; i++) { Face renderFace = renderMesh.Faces [i]; string meshName = primID + "-Face-" + i; warp_Object faceObj = new warp_Object(renderFace.Vertices.Count, renderFace.Indices.Count / 3); foreach (Vertex v in renderFace.Vertices) { warp_Vector pos = ConvertVector(v.Position); warp_Vector norm = ConvertVector(v.Normal); if (prim.Shape.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 < renderFace.Indices.Count;) { faceObj.addTriangle( renderFace.Indices [j++], renderFace.Indices [j++], renderFace.Indices [j++]); } Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); string materialName; Color4 faceColor = GetFaceColor(teFace); if (texturePrims && (prim.Scale.LengthSquared() > m_texturePrimSize)) { materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); } else { 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); faceObj = null; } renderMesh.Faces.Clear(); renderMesh = null; } catch (Exception ex) { MainConsole.Instance.Warn("[WarpTile generator]: Exception creating prim, " + ex); } }