public TextureEntry() { for (int i = 0; i < FaceTextures.Length; i++) { FaceTextures[i] = new TextureEntryFace(); } }
public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber) { LLSDMap map = (LLSDMap)llsd; TextureEntryFace face = new TextureEntryFace(defaultFace); faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1; Color4 rgba = face.RGBA; rgba = ((LLSDArray)map["colors"]).AsColor4(); face.RGBA = rgba; face.RepeatU = (float)map["scales"].AsReal(); face.RepeatV = (float)map["scalet"].AsReal(); face.OffsetU = (float)map["offsets"].AsReal(); face.OffsetV = (float)map["offsett"].AsReal(); face.Rotation = (float)map["imagerot"].AsReal(); face.Bump = (Bumpiness)map["bump"].AsInteger(); face.Shiny = (Shininess)map["shiny"].AsInteger(); face.Fullbright = map["fullbright"].AsBoolean(); face.MediaFlags = map["media_flags"].AsBoolean(); face.TexMapType = (MappingType)map["mapping"].AsInteger(); face.Glow = (float)map["glow"].AsReal(); face.TextureID = map["imageid"].AsUUID(); return(face); }
private UpdateChangedFlags ChangedTexParams(TextureEntryFace oldTexFace, TextureEntryFace newTexFace) { UpdateChangedFlags flags = 0; if (oldTexFace.Glow != newTexFace.Glow || oldTexFace.Bump != newTexFace.Bump || oldTexFace.FullBright != newTexFace.FullBright || oldTexFace.MaterialID != newTexFace.MaterialID || oldTexFace.OffsetU != newTexFace.OffsetU || oldTexFace.OffsetV != newTexFace.OffsetV || oldTexFace.RepeatU != newTexFace.RepeatU || oldTexFace.RepeatV != newTexFace.RepeatV || oldTexFace.Rotation != newTexFace.Rotation || oldTexFace.Shiny != newTexFace.Shiny || oldTexFace.TexMapType != newTexFace.TexMapType || oldTexFace.TextureID != newTexFace.TextureID) { flags |= UpdateChangedFlags.Texture; } if (oldTexFace.TextureColor.R != newTexFace.TextureColor.R || oldTexFace.TextureColor.G != newTexFace.TextureColor.G || oldTexFace.TextureColor.B != newTexFace.TextureColor.B || oldTexFace.TextureColor.A != newTexFace.TextureColor.A) { flags |= UpdateChangedFlags.Color; } if (oldTexFace.MediaFlags != newTexFace.MediaFlags) { flags |= UpdateChangedFlags.Media; } return(flags); }
public static TextureEntry FromLLSD(LLSD llsd) { LLSDArray array = (LLSDArray)llsd; LLSDMap faceLLSD; if (array.Count > 0) { int faceNumber; faceLLSD = (LLSDMap)array[0]; TextureEntryFace defaultFace = TextureEntryFace.FromLLSD(faceLLSD, null, out faceNumber); TextureEntry te = new TextureEntry(defaultFace); for (int i = 1; i < array.Count; i++) { TextureEntryFace tex = TextureEntryFace.FromLLSD(array[i], defaultFace, out faceNumber); if (faceNumber >= 0 && faceNumber < te.FaceTextures.Length) { te.FaceTextures[faceNumber] = tex; } } return(te); } else { throw new ArgumentException("LLSD contains no elements"); } }
/// <summary> /// This will either create a new face if a custom face for the given /// index is not defined, or return the custom face for that index if /// it already exists /// </summary> /// <param name="index">The index number of the face to create or /// retrieve</param> /// <returns>A TextureEntryFace containing all the properties for that /// face</returns> public TextureEntryFace CreateFace(uint index) { if (index >= MAX_FACES) { throw new Exception(index + " is outside the range of MAX_FACES"); } if (FaceTextures[index] == null) { FaceTextures[index] = new TextureEntryFace(this.DefaultTexture); } return(FaceTextures[index]); }
/// <summary> /// Contains the definition for individual faces /// </summary> /// <param name="defaultTexture"></param> public TextureEntryFace(TextureEntryFace defaultTexture) { rgba = Color4.White; repeatU = 1.0f; repeatV = 1.0f; DefaultTexture = defaultTexture; if (DefaultTexture == null) { hasAttribute = TextureAttributes.All; } else { hasAttribute = TextureAttributes.None; } }
/// <summary> /// Constructor that takes a <code>TextureEntryFace</code> for the /// default face /// </summary> /// <param name="defaultFace">Face to use as the default face</param> public TextureEntry(TextureEntryFace defaultFace) { DefaultTexture = new TextureEntryFace(null); DefaultTexture.Bump = defaultFace.Bump; DefaultTexture.Fullbright = defaultFace.Fullbright; DefaultTexture.MediaFlags = defaultFace.MediaFlags; DefaultTexture.OffsetU = defaultFace.OffsetU; DefaultTexture.OffsetV = defaultFace.OffsetV; DefaultTexture.RepeatU = defaultFace.RepeatU; DefaultTexture.RepeatV = defaultFace.RepeatV; DefaultTexture.RGBA = defaultFace.RGBA; DefaultTexture.Rotation = defaultFace.Rotation; DefaultTexture.Glow = defaultFace.Glow; DefaultTexture.Shiny = defaultFace.Shiny; DefaultTexture.TexMapType = defaultFace.TexMapType; DefaultTexture.TextureID = defaultFace.TextureID; }
public object Clone() { TextureEntryFace ret = new TextureEntryFace(this.DefaultTexture == null ? null : (TextureEntryFace)this.DefaultTexture.Clone()); ret.rgba = rgba; ret.repeatU = repeatU; ret.repeatV = repeatV; ret.offsetU = offsetU; ret.offsetV = offsetV; ret.rotation = rotation; ret.glow = glow; ret.materialb = materialb; ret.mediab = mediab; ret.hasAttribute = hasAttribute; ret.textureID = textureID; ret.materialID = materialID; return ret; }
public static TextureEntryFace FromOSD(OSD osd, TextureEntryFace defaultFace, out int faceNumber) { OSDMap map = (OSDMap)osd; TextureEntryFace face = new TextureEntryFace(defaultFace); faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1; Color4 rgba = face.RGBA; rgba = ((OSDArray)map["colors"]).AsColor4(); face.RGBA = rgba; face.RepeatU = (float)map["scales"].AsReal(); face.RepeatV = (float)map["scalet"].AsReal(); face.OffsetU = (float)map["offsets"].AsReal(); face.OffsetV = (float)map["offsett"].AsReal(); face.Rotation = (float)map["imagerot"].AsReal(); face.Bump = (Bumpiness)map["bump"].AsInteger(); face.Shiny = (Shininess)map["shiny"].AsInteger(); face.Fullbright = map["fullbright"].AsBoolean(); face.MediaFlags = map["media_flags"].AsBoolean(); face.TexMapType = (MappingType)map["mapping"].AsInteger(); face.Glow = (float)map["glow"].AsReal(); face.TextureID = map["imageid"].AsUUID(); face.MaterialID = map["materialid"]; return face; }
/// <summary> /// Contains the definition for individual faces /// </summary> /// <param name="defaultTexture"></param> public TextureEntryFace(TextureEntryFace defaultTexture) { rgba = Color4.White; repeatU = 1.0f; repeatV = 1.0f; DefaultTexture = defaultTexture; if (DefaultTexture == null) hasAttribute = TextureAttributes.All; else hasAttribute = TextureAttributes.None; }
private void GetTexPrimitiveParams(TextureEntryFace face, PrimitiveParamsType type, AnArray paramList) { switch (type) { case PrimitiveParamsType.Texture: paramList.Add(m_Part.GetTextureInventoryItem(face.TextureID)); paramList.Add(new Vector3(face.RepeatU, face.RepeatV, 0)); paramList.Add(new Vector3(face.OffsetU, face.OffsetV, 0)); paramList.Add(face.Rotation); break; case PrimitiveParamsType.Color: paramList.Add(face.TextureColor.AsVector3); paramList.Add(face.TextureColor.A); break; case PrimitiveParamsType.Alpha: paramList.Add(face.TextureColor.A); break; case PrimitiveParamsType.BumpShiny: paramList.Add((int)face.Shiny); paramList.Add((int)face.Bump); break; case PrimitiveParamsType.FullBright: paramList.Add(face.FullBright); break; case PrimitiveParamsType.TexGen: paramList.Add((int)face.TexMapType); break; case PrimitiveParamsType.Glow: paramList.Add(face.Glow); break; case PrimitiveParamsType.AlphaMode: /* [ PRIM_ALPHA_MODE, integer face, integer alpha_mode, integer mask_cutoff ] */ if (face.MaterialID == UUID.Zero) { paramList.Add(PRIM_ALPHA_MODE_BLEND); paramList.Add(0); } else { try { var mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); paramList.Add(mat.DiffuseAlphaMode); paramList.Add(mat.AlphaMaskCutoff); } catch { paramList.Add(PRIM_ALPHA_MODE_BLEND); paramList.Add(0); } } break; case PrimitiveParamsType.Normal: /* [ PRIM_NORMAL, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians ] */ if (face.MaterialID == UUID.Zero) { paramList.Add(UUID.Zero); paramList.Add(new Vector3(1, 1, 0)); paramList.Add(Vector3.Zero); paramList.Add(0f); } else { try { var mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); paramList.Add(m_Part.GetTextureInventoryItem(mat.NormMap)); paramList.Add(new Vector3(mat.NormRepeatX, mat.NormRepeatY, 0) / Material.MATERIALS_MULTIPLIER); paramList.Add(new Vector3(mat.NormOffsetX, mat.NormOffsetY, 0) / Material.MATERIALS_MULTIPLIER); paramList.Add(mat.NormRotation); } catch { paramList.Add(UUID.Zero); paramList.Add(new Vector3(1, 1, 0)); paramList.Add(Vector3.Zero); paramList.Add(0f); } } break; case PrimitiveParamsType.Specular: /* [ PRIM_SPECULAR, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossiness, integer environment ] */ if (face.MaterialID == UUID.Zero) { paramList.Add(UUID.Zero); paramList.Add(new Vector3(1, 1, 0)); paramList.Add(Vector3.Zero); paramList.Add(0f); paramList.Add(Vector3.One); paramList.Add(0); paramList.Add(0); } else { try { var mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); paramList.Add(m_Part.GetTextureInventoryItem(mat.SpecMap)); paramList.Add(new Vector3(mat.SpecRepeatX, mat.SpecRepeatY, 0) / Material.MATERIALS_MULTIPLIER); paramList.Add(new Vector3(mat.SpecOffsetX, mat.SpecOffsetY, 0) / Material.MATERIALS_MULTIPLIER); paramList.Add(mat.SpecRotation / Material.MATERIALS_MULTIPLIER); paramList.Add(mat.SpecColor.AsVector3); paramList.Add(mat.SpecExp); paramList.Add(mat.EnvIntensity); } catch { paramList.Add(UUID.Zero); paramList.Add(new Vector3(1, 1, 0)); paramList.Add(Vector3.Zero); paramList.Add(0f); paramList.Add(Vector3.One); paramList.Add(0); paramList.Add(0); } } break; default: throw new ArgumentException(String.Format("Internal error! Primitive parameter type {0} should not be passed to PrimitiveFace", type)); } }
private void SetTexPrimitiveParams(TextureEntryFace face, PrimitiveParamsType type, AnArray.MarkEnumerator enumerator, ref UpdateChangedFlags flags, ref bool isUpdated, bool updateParams) { switch (type) { case PrimitiveParamsType.Texture: { UUID textureID = m_Part.GetTextureParam(enumerator, "PRIM_TEXTURE"); Vector3 repeats = ParamsHelper.GetVector(enumerator, "PRIM_TEXTURE"); Vector3 offsets = ParamsHelper.GetVector(enumerator, "PRIM_TEXTURE"); float rot = (float)ParamsHelper.GetDouble(enumerator, "PRIM_TEXTURE"); if (updateParams) { if (m_Part.TryFetchTexture(textureID)) { face.TextureID = textureID; } face.RepeatU = (float)repeats.X; face.RepeatV = (float)repeats.Y; face.OffsetU = (float)offsets.X; face.OffsetV = (float)offsets.Y; face.Rotation = rot; flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; case PrimitiveParamsType.Color: { Vector3 color = ParamsHelper.GetVector(enumerator, "PRIM_COLOR"); double alpha = ParamsHelper.GetDouble(enumerator, "PRIM_COLOR").Clamp(0, 1); if (updateParams) { face.TextureColor = new ColorAlpha(color, alpha); flags |= UpdateChangedFlags.Color; isUpdated = true; } } break; case PrimitiveParamsType.Alpha: { double alpha = ParamsHelper.GetDouble(enumerator, "PRIM_ALPHA").Clamp(0, 1); if (updateParams) { ColorAlpha color = face.TextureColor; color.A = alpha; face.TextureColor = color; flags |= UpdateChangedFlags.Color; isUpdated = true; } } break; case PrimitiveParamsType.BumpShiny: { Shininess shiny = (Shininess)ParamsHelper.GetInteger(enumerator, "PRIM_BUMP_SHINY"); Bumpiness bump = (Bumpiness)ParamsHelper.GetInteger(enumerator, "PRIM_BUMP_SHINY"); if (updateParams) { face.Shiny = shiny; face.Bump = bump; flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; case PrimitiveParamsType.FullBright: { bool fbright = ParamsHelper.GetBoolean(enumerator, "PRIM_FULLBRIGHT"); if (updateParams) { face.FullBright = fbright; flags |= UpdateChangedFlags.Color; isUpdated = true; } } break; case PrimitiveParamsType.TexGen: { MappingType mapType = (MappingType)ParamsHelper.GetInteger(enumerator, "PRIM_TEXGEN"); if (updateParams) { face.TexMapType = mapType; flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; case PrimitiveParamsType.Glow: { float glow = (float)ParamsHelper.GetDouble(enumerator, "PRIM_GLOW").Clamp(0, 1); if (updateParams) { face.Glow = glow; flags |= UpdateChangedFlags.Color; isUpdated = true; } } break; case PrimitiveParamsType.AlphaMode: /* [ PRIM_ALPHA_MODE, integer face, integer alpha_mode, integer mask_cutoff ] */ { Material mat; try { mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); } catch { mat = new Material(); } mat.DiffuseAlphaMode = ParamsHelper.GetInteger(enumerator, "PRIM_ALPHA_MODE"); mat.AlphaMaskCutoff = ParamsHelper.GetInteger(enumerator, "PRIM_ALPHA_MODE"); if (updateParams) { mat.DiffuseAlphaMode = mat.DiffuseAlphaMode.Clamp(0, 3); mat.AlphaMaskCutoff = mat.AlphaMaskCutoff.Clamp(0, 3); mat.MaterialID = UUID.Random; m_Part.ObjectGroup.Scene.StoreMaterial(mat); face.MaterialID = mat.MaterialID; flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; case PrimitiveParamsType.Normal: /* [ PRIM_NORMAL, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians ] */ { UUID texture = m_Part.GetTextureParam(enumerator, "PRIM_NORMAL"); Vector3 repeats = ParamsHelper.GetVector(enumerator, "PRIM_NORMAL"); Vector3 offsets = ParamsHelper.GetVector(enumerator, "PRIM_NORMAL"); double rotation = ParamsHelper.GetDouble(enumerator, "PRIM_NORMAL"); if (updateParams) { repeats.X *= Material.MATERIALS_MULTIPLIER; repeats.Y *= Material.MATERIALS_MULTIPLIER; offsets.X *= Material.MATERIALS_MULTIPLIER; offsets.Y *= Material.MATERIALS_MULTIPLIER; rotation %= Math.PI * 2; rotation *= Material.MATERIALS_MULTIPLIER; Material mat; try { mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); } catch { mat = new Material(); } mat.NormMap = texture; mat.NormOffsetX = (int)Math.Round(offsets.X); mat.NormOffsetY = (int)Math.Round(offsets.Y); mat.NormRepeatX = (int)Math.Round(repeats.X); mat.NormRepeatY = (int)Math.Round(repeats.Y); mat.NormRotation = (int)Math.Round(rotation); mat.MaterialID = UUID.Random; if (m_Part.TryFetchTexture(texture)) { m_Part.ObjectGroup.Scene.StoreMaterial(mat); face.MaterialID = mat.MaterialID; } flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; case PrimitiveParamsType.Specular: /* [ PRIM_SPECULAR, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossiness, integer environment ] */ { UUID texture = m_Part.GetTextureParam(enumerator, "PRIM_NORMAL"); Vector3 repeats = ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR"); Vector3 offsets = ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR"); repeats *= Material.MATERIALS_MULTIPLIER; offsets *= Material.MATERIALS_MULTIPLIER; double rotation = ParamsHelper.GetDouble(enumerator, "PRIM_SPECULAR"); rotation %= Math.PI * 2; rotation *= Material.MATERIALS_MULTIPLIER; var color = new ColorAlpha(ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR"), 1); int glossiness = ParamsHelper.GetInteger(enumerator, "PRIM_SPECULAR"); int environment = ParamsHelper.GetInteger(enumerator, "PRIM_SPECULAR"); if (updateParams) { environment = environment.Clamp(0, 255); glossiness = glossiness.Clamp(0, 255); Material mat; try { mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID); } catch { mat = new Material(); } mat.SpecColor = color; mat.SpecMap = texture; mat.SpecOffsetX = (int)Math.Round(offsets.X); mat.SpecOffsetY = (int)Math.Round(offsets.Y); mat.SpecRepeatX = (int)Math.Round(repeats.X); mat.SpecRepeatY = (int)Math.Round(repeats.Y); mat.SpecRotation = (int)Math.Round(rotation); mat.EnvIntensity = environment; mat.SpecExp = glossiness; mat.MaterialID = UUID.Random; if (m_Part.TryFetchTexture(texture)) { m_Part.ObjectGroup.Scene.StoreMaterial(mat); face.MaterialID = mat.MaterialID; } flags |= UpdateChangedFlags.Texture; isUpdated = true; } } break; default: throw new ArgumentException($"Internal error! Primitive parameter type {type} should not be passed to PrimitiveFace"); } }
public TextureEntryFaceContainer(TextureEntryFace face) { m_Face = face; }
private void copyTexturesToInventory(SceneObjectPart part) { if (m_enable == false) { return; } if (m_scene.LoginsEnabled == false) { return; } if (part.ParentGroup.RootPart.ClickAction == 2) { return; } if ((part.ParentGroup.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.ObjectCopy) != 0) { return; } //if ((setPermissionMask & (uint)PermissionMask.Copy) != 0) //return; if (inventoryContainsScripts(part.ParentGroup.RootPart)) { return; } try { List <UUID> allTextures = new List <UUID>(); List <TaskInventoryItem> inventoryItems = new List <TaskInventoryItem>(); //Get all Textures from the scene object Primitive.TextureEntry textures = part.Shape.Textures; int allSides = part.GetNumberOfSides(); for (uint i = 0; i < allSides; i++) { TextureEntryFace face = textures.GetFace(i); if (!m_textureBlackList.Contains(face.TextureID) && !m_defaultTexturs.Contains(face.TextureID.ToString())) { allTextures.Add(face.TextureID); } if (m_textureBlackList.Contains(face.TextureID)) { face.TextureID = UUID.Parse("89556747-24cb-43ed-920b-47caed15465f"); } } //Remove not existing textures if (m_checkTexture == true) { String[] _assetIDs = new string[allTextures.Count]; for (int i = 0; i < allTextures.Count; i++) { _assetIDs[i] = allTextures[i].ToString(); } bool[] existing = m_scene.AssetService.AssetsExist(_assetIDs); for (int i = 0; i < existing.Length; i++) { if (existing[i] == false) { m_textureBlackList.Add(allTextures[i]); allTextures[i] = UUID.Zero; } } } //Convert texture uuid list to inventar items. foreach (UUID texture in allTextures) { if (texture != UUID.Zero) { String partname = part.Name.Trim(); if (partname == "") { partname = "tf"; } TaskInventoryItem item = new TaskInventoryItem(); item.AssetID = texture; item.ItemID = UUID.Random(); item.OwnerID = part.OwnerID; item.CurrentPermissions = 581639; item.Name = partname + " - Texture"; item.Description = "This item was automatically generated by the texture fetcher module."; item.OwnerID = part.OwnerID; item.CreatorID = part.OwnerID; item.LastOwnerID = part.OwnerID; inventoryItems.Add(item); } } //Check if the item is allready in the inventory and then add it. bool updateNeeded = false; foreach (TaskInventoryItem item in inventoryItems) { if (!isAssetInInventory(part, item.AssetID)) { updateNeeded = true; part.ParentGroup.RootPart.Inventory.AddInventoryItem(item, false); } } if (updateNeeded == true) { //part.SendFullUpdateToAllClients(); } } catch (Exception _error) { m_log.Error("[" + Name + "] ERROR: " + _error.Message); } }
/// <summary> /// This will either create a new face if a custom face for the given /// index is not defined, or return the custom face for that index if /// it already exists /// </summary> /// <param name="index">The index number of the face to create or /// retrieve</param> /// <returns>A TextureEntryFace containing all the properties for that /// face</returns> public TextureEntryFace CreateFace(uint index) { if (index >= MAX_FACES) throw new Exception(index + " is outside the range of MAX_FACES"); if (FaceTextures[index] == null) FaceTextures[index] = new TextureEntryFace(this.DefaultTexture); return FaceTextures[index]; }
/// <summary> /// Constructor that takes a default texture UUID /// </summary> /// <param name="defaultTextureID">Texture UUID to use as the default texture</param> public TextureEntry(UUID defaultTextureID) { DefaultTexture = new TextureEntryFace(null); DefaultTexture.TextureID = defaultTextureID; }
/// <summary> /// Constructor that takes a <code>TextureEntryFace</code> for the /// default face /// </summary> /// <param name="defaultFace">Face to use as the default face</param> public TextureEntry(TextureEntryFace defaultFace) { DefaultTexture = new TextureEntryFace(null); DefaultTexture.Bump = defaultFace.Bump; DefaultTexture.Fullbright = defaultFace.Fullbright; DefaultTexture.MediaFlags = defaultFace.MediaFlags; DefaultTexture.OffsetU = defaultFace.OffsetU; DefaultTexture.OffsetV = defaultFace.OffsetV; DefaultTexture.RepeatU = defaultFace.RepeatU; DefaultTexture.RepeatV = defaultFace.RepeatV; DefaultTexture.RGBA = defaultFace.RGBA; DefaultTexture.Rotation = defaultFace.Rotation; DefaultTexture.Glow = defaultFace.Glow; DefaultTexture.Shiny = defaultFace.Shiny; DefaultTexture.TexMapType = defaultFace.TexMapType; DefaultTexture.TextureID = defaultFace.TextureID; DefaultTexture.MaterialID = defaultFace.MaterialID; }
private void FromBytes(byte[] data, int pos, int length) { if (length <= 0) { // No TextureEntry to process DefaultTexture = null; return; } else { DefaultTexture = new TextureEntryFace(null); } uint bitfieldSize = 0; uint faceBits = 0; int i = pos; #region Texture DefaultTexture.TextureID = new UUID(data, i); i += 16; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { UUID tmpUUID = new UUID(data, i); i += 16; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).TextureID = tmpUUID; } } } #endregion Texture #region Color DefaultTexture.RGBA = new Color4(data, i, true); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { Color4 tmpColor = new Color4(data, i, true); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).RGBA = tmpColor; } } } #endregion Color #region RepeatU DefaultTexture.RepeatU = Utils.BytesToFloat(data, i); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Utils.BytesToFloat(data, i); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).RepeatU = tmpFloat; } } } #endregion RepeatU #region RepeatV DefaultTexture.RepeatV = Utils.BytesToFloat(data, i); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Utils.BytesToFloat(data, i); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).RepeatV = tmpFloat; } } } #endregion RepeatV #region OffsetU DefaultTexture.OffsetU = Helpers.TEOffsetFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEOffsetFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).OffsetU = tmpFloat; } } } #endregion OffsetU #region OffsetV DefaultTexture.OffsetV = Helpers.TEOffsetFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEOffsetFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).OffsetV = tmpFloat; } } } #endregion OffsetV #region Rotation DefaultTexture.Rotation = Helpers.TERotationFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TERotationFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).Rotation = tmpFloat; } } } #endregion Rotation #region Material DefaultTexture.material = data[i]; i++; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { byte tmpByte = data[i]; i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).material = tmpByte; } } } #endregion Material #region Media DefaultTexture.media = data[i]; i++; while (i - pos < length && ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { byte tmpByte = data[i]; i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).media = tmpByte; } } } #endregion Media #region Glow DefaultTexture.Glow = Helpers.TEGlowFloat(data, i); i++; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEGlowFloat(data, i); i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) { if ((faceBits & bit) != 0) { CreateFace(face).Glow = tmpFloat; } } } #endregion Glow }
private void FromBytes(byte[] data, int pos, int length) { if (length < 16) { // No TextureEntry to process DefaultTexture = null; return; } else { DefaultTexture = new TextureEntryFace(null); } uint bitfieldSize = 0; uint faceBits = 0; int i = pos; #region Texture DefaultTexture.TextureID = new UUID(data, i); i += 16; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { UUID tmpUUID = new UUID(data, i); i += 16; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).TextureID = tmpUUID; } #endregion Texture #region Color DefaultTexture.RGBA = new Color4(data, i, true); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { Color4 tmpColor = new Color4(data, i, true); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).RGBA = tmpColor; } #endregion Color #region RepeatU DefaultTexture.RepeatU = Utils.BytesToFloat(data, i); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Utils.BytesToFloat(data, i); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).RepeatU = tmpFloat; } #endregion RepeatU #region RepeatV DefaultTexture.RepeatV = Utils.BytesToFloat(data, i); i += 4; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Utils.BytesToFloat(data, i); i += 4; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).RepeatV = tmpFloat; } #endregion RepeatV #region OffsetU DefaultTexture.OffsetU = Helpers.TEOffsetFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEOffsetFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).OffsetU = tmpFloat; } #endregion OffsetU #region OffsetV DefaultTexture.OffsetV = Helpers.TEOffsetFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEOffsetFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).OffsetV = tmpFloat; } #endregion OffsetV #region Rotation DefaultTexture.Rotation = Helpers.TERotationFloat(data, i); i += 2; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TERotationFloat(data, i); i += 2; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).Rotation = tmpFloat; } #endregion Rotation #region Material DefaultTexture.material = data[i]; i++; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { byte tmpByte = data[i]; i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).material = tmpByte; } #endregion Material #region Media DefaultTexture.media = data[i]; i++; while (i - pos < length && ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { byte tmpByte = data[i]; i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).media = tmpByte; } #endregion Media #region Glow DefaultTexture.Glow = Helpers.TEGlowFloat(data, i); i++; while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { float tmpFloat = Helpers.TEGlowFloat(data, i); i++; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).Glow = tmpFloat; } #endregion Glow #region MaterialID if (i - pos + 16 <= length) { DefaultTexture.MaterialID = new UUID(data, i); i += 16; while (i - pos + 16 <= length && ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize)) { UUID tmpUUID = new UUID(data, i); i += 16; for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1) if ((faceBits & bit) != 0) CreateFace(face).MaterialID = tmpUUID; } } #endregion MaterialID }
private static void ProcessInstances(AnArray instanceList, MeshInventoryItem item, AssetData objectAsset = null) { var grp = new ObjectGroup(); foreach (Map instanceData in instanceList.OfType <Map>()) { var shape = new ObjectPart.PrimitiveShape { SculptType = PrimitiveSculptType.Mesh, ProfileCurve = 1, PathBegin = 0, PathCurve = 16, PathEnd = 0, PathRadiusOffset = 0, PathRevolutions = 0, PathScaleX = 100, PathScaleY = 100, PathShearX = 0, PathShearY = 0, PathSkew = 0, PathTaperX = 0, PathTaperY = 0, PathTwist = 0, PathTwistBegin = 0, PCode = PrimitiveCode.Prim, ProfileBegin = 9375, ProfileEnd = 0, ProfileHollow = 0, State = 0, SculptMap = item.MeshMap[instanceData["mesh"].AsInt] }; int numfaces; if (item.MeshFaces.TryGetValue(instanceData["mesh"].AsInt, out numfaces)) { shape.SetMeshNumFaces(numfaces); } var part = new ObjectPart { Name = item.Name, Shape = shape, IsReturnAtEdge = true, Size = GetVector(instanceData["scale"]), PhysicsShapeType = (PrimitivePhysicsShapeType)instanceData["physics_shape_type"].AsInt, Material = (PrimitiveMaterial)instanceData["material"].AsInt }; grp.AddLink(part); /* use our build in transformation */ grp.GlobalPosition = GetVector(instanceData["position"]); grp.GlobalRotation = GetRotation(instanceData["rotation"]); var faceList = (AnArray)instanceData["face_list"]; var te = new TextureEntry(); uint faceidx = 0; foreach (Map face in faceList.OfType <Map>()) { TextureEntryFace teface = te[faceidx]; IValue iv; teface.FullBright = face["fullbright"].AsBoolean; teface.TextureColor = GetColorAlpha(face["diffuse_color"]); if (face.TryGetValue("image", out iv)) { teface.TextureID = item.TextureMap[iv.AsInt]; } if (face.TryGetValue("scales", out iv)) { teface.RepeatU = (float)iv.AsReal; } if (face.TryGetValue("scalet", out iv)) { teface.RepeatV = (float)iv.AsReal; } if (face.TryGetValue("offsets", out iv)) { teface.OffsetU = (float)iv.AsReal; } if (face.TryGetValue("offsett", out iv)) { teface.OffsetV = (float)iv.AsReal; } if (face.TryGetValue("imagerot", out iv)) { teface.Rotation = (float)iv.AsReal; } ++faceidx; } part.TextureEntry = te; part.Owner = item.Owner; part.Creator = item.Owner; part.OwnerMask = InventoryPermissionsMask.Every; part.BaseMask = InventoryPermissionsMask.Every; } grp.Owner = item.Owner; grp.LastOwner = item.Owner; AssetData objectasset = grp.Asset(XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.WriteOwnerInfo); if (objectAsset != null) { objectAsset.Data = objectasset.Data; item.AssetID = objectAsset.ID; objectAsset.Type = AssetType.Object; } else { item.AssetID = objectasset.ID; item.Assets.Add(objectasset); } }