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); } }
private void LookAt(LSL_Vector target, double strength, double damping, ISceneChildEntity obj) { // Determine where we are looking from LSL_Vector from = new LSL_Vector(obj.GetWorldPosition()); // Work out the normalised vector from the source to the target LSL_Vector delta = llVecNorm(target - from); LSL_Vector angle = new LSL_Vector(0, 0, 0) { x = llAtan2(delta.z, delta.y) - ScriptBaseClass.PI_BY_TWO, y = llAtan2(delta.x, llSqrt((delta.y*delta.y) + (delta.z*delta.z))) }; // Calculate the yaw // subtracting PI_BY_TWO is required to compensate for the odd SL co-ordinate system // Calculate pitch // we need to convert from a vector describing // the angles of rotation in radians into rotation value LSL_Types.Quaternion rot = llEuler2Rot(angle); //If the strength is 0, or we are non-physical, set the rotation if (strength == 0 || obj.PhysActor == null || !obj.PhysActor.IsPhysical) SetLinkRot(obj, rot); else obj.startLookAt(Rot2Quaternion(rot), (float) strength, (float) damping); }
private void LookAt(LSL_Vector target, double strength, double damping, ISceneChildEntity obj) { // Determine where we are looking from LSL_Vector from = new LSL_Vector(obj.GetWorldPosition()); // The following code bit was written by Dahlia // from the Opensimulator Core Team. Thank you for fixing this issue // normalized direction to target LSL_Vector dir = llVecNorm(target - from); // use vertical to help compute left axis LSL_Vector up = new LSL_Vector(0.0, 0.0, 1.0); // find normalized left axis parallel to horizon LSL_Vector left = llVecNorm(LSL_Vector.Cross(up, dir)); // make up orthogonal to left and direction up = LSL_Vector.Cross(dir, left); // compute rotation based on orthogonal axes LSL_Rotation rot = new LSL_Rotation(0.0, 0.707107, 0.0, 0.707107) * llAxes2Rot(dir, left, up); // End codebit //If the strength is 0, or we are non-physical, set the rotation if (strength == 0 || obj.PhysActor == null || !obj.PhysActor.IsPhysical) SetLinkRot(obj, rot); else obj.startLookAt(Rot2Quaternion(rot), (float)strength, (float)damping); }
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); } }
private void CreatePrim (WarpRenderer renderer, ISceneChildEntity prim) { try { const float MIN_SIZE = 2f; if ((PCode)prim.Shape.PCode != PCode.Prim) return; if (prim.Scale.LengthSquared () < MIN_SIZE * MIN_SIZE) return; Primitive omvPrim = prim.Shape.ToOmvPrimitive (prim.OffsetPosition, prim.RotationOffset); FacetedMesh renderMesh = null; // Are we dealing with a sculptie or mesh? if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) { // Try fetchinng the asset AssetBase sculptAsset = m_scene.AssetService.Get (omvPrim.Sculpt.SculptTexture.ToString ()); if (sculptAsset != null) { // Is it a mesh? if (omvPrim.Sculpt.Type == SculptType.Mesh) { OpenMetaverse.Assets.AssetMesh meshAsset = new OpenMetaverse.Assets.AssetMesh (omvPrim.Sculpt.SculptTexture, sculptAsset.Data); FacetedMesh.TryDecodeFromAsset (omvPrim, meshAsset, DetailLevel.Highest, out renderMesh); } else // It's sculptie { IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder> (); Image sculpt = imgDecoder.DecodeToImage (sculptAsset.Data); if (sculpt != null) { renderMesh = m_primMesher.GenerateFacetedSculptMesh (omvPrim, (Bitmap)sculpt, DetailLevel.Medium); sculpt.Dispose (); } } } } else // Prim { renderMesh = m_primMesher.GenerateFacetedMesh (omvPrim, DetailLevel.Medium); } if (renderMesh == null) return; warp_Vector primPos = ConvertVector (prim.GetWorldPosition ()); warp_Quaternion primRot = ConvertQuaternion (prim.RotationOffset); 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.RotationOffset))); } 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 face = renderMesh.Faces[i]; string meshName = primID + "-Face-" + i.ToString (); warp_Object faceObj = new warp_Object (face.Vertices.Count, face.Indices.Count / 3); for (int j = 0; j < face.Vertices.Count; j++) { Vertex v = face.Vertices[j]; 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 < face.Indices.Count; j += 3) { faceObj.addTriangle ( face.Indices[j + 0], face.Indices[j + 1], face.Indices[j + 2]); } Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace ((uint)i); string materialName; Color4 faceColor = GetFaceColor (teFace); if (m_texturePrims && prim.Scale.LengthSquared () > 48 * 48) { 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); } renderMesh.Faces.Clear (); renderMesh = null; } catch(Exception ex) { m_log.Warn ("[Warp3D]: Exception creating prim, " + ex.ToString ()); } }