| 9 |
using OpenMetaverse.Rendering; |
using OpenMetaverse.Rendering; |
| 10 |
using Xenki.Framework; |
using Xenki.Framework; |
| 11 |
using Quaternion=System.Windows.Media.Media3D.Quaternion; |
using Quaternion=System.Windows.Media.Media3D.Quaternion; |
| 12 |
|
using System.IO; |
| 13 |
|
using System.Windows.Media.Imaging; |
| 14 |
|
|
| 15 |
namespace Xenki.DefaultRenderer |
namespace Xenki.DefaultRenderer |
| 16 |
{ |
{ |
| 303 |
Random x = new Random(); |
Random x = new Random(); |
| 304 |
Color col = colAry[x.Next(0, 5)]; |
Color col = colAry[x.Next(0, 5)]; |
| 305 |
|
|
| 306 |
|
bool NeedAttachedTexture = false; |
| 307 |
|
|
| 308 |
if (data.Textures != null && |
if (data.Textures != null && |
| 309 |
data.Textures.FaceTextures != null && |
data.Textures.FaceTextures != null && |
| 310 |
data.Textures.FaceTextures.Length > 0) |
data.Textures.FaceTextures.Length > 0) |
| 311 |
{ |
{ |
| 312 |
|
byte[] imagebytes; |
| 313 |
|
lock (DefaultNetwork.DefaultNetwork.textureCache) |
| 314 |
|
{ |
| 315 |
|
imagebytes = DefaultNetwork.DefaultNetwork.textureCache.GetCachedImageBytes(data.Textures.DefaultTexture.TextureID); |
| 316 |
|
} |
| 317 |
|
if (imagebytes != null && imagebytes.Length > 0) |
| 318 |
|
{ |
| 319 |
|
BitmapImage bitmap = new BitmapImage(); |
| 320 |
|
//if(imagebytes.Length<=0) |
| 321 |
|
|
| 322 |
|
using (MemoryStream ms = new MemoryStream(imagebytes)) |
| 323 |
|
{ |
| 324 |
|
ms.Write(imagebytes, 0, imagebytes.Length); |
| 325 |
|
// bitimg = new System.Drawing.Bitmap(ms); |
| 326 |
|
bitmap.StreamSource = ms; |
| 327 |
|
} |
| 328 |
|
|
| 329 |
|
ImageBrush brush = new ImageBrush(bitmap); |
| 330 |
|
|
| 331 |
|
triangleModel = new GeometryModel3D( |
| 332 |
|
mesh, new DiffuseMaterial(brush)); |
| 333 |
|
} |
| 334 |
|
else |
| 335 |
|
{ |
| 336 |
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
| 337 |
data.Textures.DefaultTexture.RGBA.R, |
data.Textures.DefaultTexture.RGBA.R, |
| 338 |
data.Textures.DefaultTexture.RGBA.G, |
data.Textures.DefaultTexture.RGBA.G, |
| 339 |
data.Textures.DefaultTexture.RGBA.B); |
data.Textures.DefaultTexture.RGBA.B); |
|
} |
|
| 340 |
|
|
| 341 |
|
|
| 342 |
|
NeedAttachedTexture = true; |
| 343 |
|
} |
| 344 |
|
} |
| 345 |
triangleModel = new GeometryModel3D( |
triangleModel = new GeometryModel3D( |
| 346 |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
| 347 |
|
|
| 355 |
*/ |
*/ |
| 356 |
ModelVisual3D model = new ModelVisual3D(); |
ModelVisual3D model = new ModelVisual3D(); |
| 357 |
model.Content = triangleModel; |
model.Content = triangleModel; |
| 358 |
|
|
| 359 |
|
if (NeedAttachedTexture) |
| 360 |
|
{ |
| 361 |
|
DefaultNetwork.DefaultNetwork.m_primitiveData.AddUnAttachedTexture(data.Textures.DefaultTexture.TextureID,model); |
| 362 |
|
} |
| 363 |
return model; |
return model; |
| 364 |
} |
} |
| 365 |
|
|
| 366 |
|
public void UpdatePrimTexture(UUID textureID) |
| 367 |
|
{ |
| 368 |
|
List<Visual3D> NeedUpdateVisuals = DefaultNetwork.DefaultNetwork.m_primitiveData.GetVisualByTextureID(textureID); |
| 369 |
|
foreach (Visual3D visual in NeedUpdateVisuals) |
| 370 |
|
{ |
| 371 |
|
ModelVisual3D model = visual as ModelVisual3D; |
| 372 |
|
if (model == null) |
| 373 |
|
return; |
| 374 |
|
GeometryModel3D gTexture = model.Content as GeometryModel3D; |
| 375 |
|
if (gTexture == null) |
| 376 |
|
return; |
| 377 |
|
|
| 378 |
|
byte[] imagebytes; |
| 379 |
|
lock (DefaultNetwork.DefaultNetwork.textureCache) |
| 380 |
|
{ |
| 381 |
|
imagebytes = DefaultNetwork.DefaultNetwork.textureCache.GetCachedImageBytes(textureID); |
| 382 |
|
} |
| 383 |
|
if (imagebytes != null && imagebytes.Length > 0) |
| 384 |
|
{ |
| 385 |
|
BitmapImage bitmap = new BitmapImage(); |
| 386 |
|
//if(imagebytes.Length<=0) |
| 387 |
|
|
| 388 |
|
using (MemoryStream ms = new MemoryStream(imagebytes)) |
| 389 |
|
{ |
| 390 |
|
ms.Write(imagebytes, 0, imagebytes.Length); |
| 391 |
|
|
| 392 |
|
bitmap.StreamSource = ms; |
| 393 |
|
} |
| 394 |
|
|
| 395 |
|
ImageBrush brush = new ImageBrush(bitmap); |
| 396 |
|
|
| 397 |
|
gTexture.SetValue(GeometryModel3D.MaterialProperty, new DiffuseMaterial(brush)); |
| 398 |
|
} |
| 399 |
|
|
| 400 |
|
|
| 401 |
|
} |
| 402 |
|
} |
| 403 |
|
|
| 404 |
public void RemovePrimitive(uint id) |
public void RemovePrimitive(uint id) |
| 405 |
{ |
{ |
| 406 |
m_viewport.Dispatcher.Invoke( |
m_viewport.Dispatcher.Invoke( |