| 28 |
private DefaultTexture m_textureManager; |
private DefaultTexture m_textureManager; |
| 29 |
private DefaultPrimControl m_primitiveData; |
private DefaultPrimControl m_primitiveData; |
| 30 |
|
|
|
//public ITextureManage TextureManager |
|
|
//{ |
|
|
// set { m_textureManager = value; } |
|
|
//} |
|
|
|
|
| 31 |
private bool Broken; |
private bool Broken; |
| 32 |
|
|
| 33 |
private readonly Point3D[,] m_heightmapPoints = new Point3D[256,256]; |
private readonly Point3D[,] m_heightmapPoints = new Point3D[256,256]; |
| 37 |
private readonly DiffuseMaterial m_terrainMaterial; |
private readonly DiffuseMaterial m_terrainMaterial; |
| 38 |
private string textureImageFolderPath = |
private string textureImageFolderPath = |
| 39 |
System.IO.Path.Combine(System.Windows.Forms.Application.LocalUserAppDataPath, "texture"); |
System.IO.Path.Combine(System.Windows.Forms.Application.LocalUserAppDataPath, "texture"); |
| 40 |
private GridClient m_gridclient; |
|
| 41 |
|
|
| 42 |
private GridClient gridClient; |
private GridClient gridClient; |
| 43 |
|
|
| 58 |
|
|
| 59 |
public DefaultRenderer(Viewport3D m_viewport) |
public DefaultRenderer(Viewport3D m_viewport) |
| 60 |
{ |
{ |
|
|
|
| 61 |
// Viewport |
// Viewport |
| 62 |
this.m_viewport = m_viewport; |
this.m_viewport = m_viewport; |
| 63 |
// m_viewport.ClipToBounds = false; |
// m_viewport.ClipToBounds = false; |
| 67 |
//setup data store control |
//setup data store control |
| 68 |
m_primitiveData = DefaultPrimControl.SingleSceneDataManager(); |
m_primitiveData = DefaultPrimControl.SingleSceneDataManager(); |
| 69 |
|
|
|
|
|
| 70 |
// Camera Issues |
// Camera Issues |
| 71 |
Point3D CameraPos = new Point3D(0,0,50); |
Point3D CameraPos = new Point3D(0,0,50); |
| 72 |
Point3D CameraLook = new Point3D(128,128,10); |
Point3D CameraLook = new Point3D(128,128,10); |
| 76 |
|
|
| 77 |
m_camera.Position = CameraPos; |
m_camera.Position = CameraPos; |
| 78 |
m_camera.LookDirection = new Vector3D(CameraLook.X - m_camera.Position.X, CameraLook.Y - m_camera.Position.Y, CameraLook.Z - m_camera.Position.Z); |
m_camera.LookDirection = new Vector3D(CameraLook.X - m_camera.Position.X, CameraLook.Y - m_camera.Position.Y, CameraLook.Z - m_camera.Position.Z); |
|
|
|
| 79 |
m_camera.FarPlaneDistance = 1024; |
m_camera.FarPlaneDistance = 1024; |
| 80 |
m_camera.NearPlaneDistance = 0.01; |
m_camera.NearPlaneDistance = 0.01; |
| 81 |
m_viewport.Camera = m_camera; |
m_viewport.Camera = m_camera; |
| 109 |
{ |
{ |
| 110 |
for(int y=0;y<256;y++) |
for(int y=0;y<256;y++) |
| 111 |
{ |
{ |
| 112 |
m_heightmap[x, y] = 10.0; |
m_heightmap[x, y] = 0.0; |
| 113 |
} |
} |
| 114 |
} |
} |
| 115 |
|
|
| 270 |
if (m_primitiveData.PrimModelsInScene.ContainsKey(data.ParentID)) |
if (m_primitiveData.PrimModelsInScene.ContainsKey(data.ParentID)) |
| 271 |
{ |
{ |
| 272 |
Primitive parent = m_primitiveData.PrimModelsInScene[data.ParentID]; |
Primitive parent = m_primitiveData.PrimModelsInScene[data.ParentID]; |
| 273 |
data.Position *= parent.Rotation; |
//data.Position *= parent.Rotation; |
| 274 |
data.Position += parent.Position; |
data.Position += parent.Position; |
| 275 |
|
|
| 276 |
} |
} |
| 303 |
mesh.TriangleIndices.Add(ind); |
mesh.TriangleIndices.Add(ind); |
| 304 |
} |
} |
| 305 |
|
|
| 306 |
triangleModel = PatchTexture(data, mesh, triangleModel); |
if (data.Textures != null && data.Textures.DefaultTexture != null && |
| 307 |
|
data.Textures.DefaultTexture.TextureID != null) |
| 308 |
|
triangleModel = PatchTexture(data.Textures.DefaultTexture.TextureID, data.LocalID, mesh, triangleModel); |
| 309 |
|
else |
| 310 |
|
{ |
| 311 |
|
triangleModel = new GeometryModel3D( |
| 312 |
|
mesh, new DiffuseMaterial(new SolidColorBrush(Colors.CadetBlue))); |
| 313 |
|
} |
| 314 |
model = new ModelVisual3D(); |
model = new ModelVisual3D(); |
| 315 |
model.Content = triangleModel; |
model.Content = triangleModel; |
| 316 |
model.SetValue(dep, data.LocalID); |
model.SetValue(dep, data.LocalID); |
| 322 |
} |
} |
| 323 |
DependencyProperty dep = DependencyProperty.Register("ID", typeof(uint), typeof(Visual3D)); |
DependencyProperty dep = DependencyProperty.Register("ID", typeof(uint), typeof(Visual3D)); |
| 324 |
|
|
| 325 |
private GeometryModel3D PatchTexture(Primitive data, MeshGeometry3D mesh, GeometryModel3D triangleModel) |
private GeometryModel3D PatchTexture(UUID TextureID, uint LocalID, MeshGeometry3D mesh, GeometryModel3D triangleModel) |
| 326 |
{ |
{ |
| 327 |
Color col = Colors.YellowGreen; |
Color col = Colors.YellowGreen; |
| 328 |
|
|
| 329 |
if (data.Textures != null && |
if (TextureID != null) |
|
data.Textures.DefaultTexture != null && |
|
|
data.Textures.DefaultTexture.TextureID != null) |
|
| 330 |
{ |
{ |
| 331 |
Material m = m_primitiveData.GetMaterialFromCache(data.Textures.DefaultTexture.TextureID); |
Material m = m_primitiveData.GetMaterialFromCache(TextureID); |
| 332 |
if (m != null) |
if (m != null) |
| 333 |
{ |
{ |
| 334 |
triangleModel = new GeometryModel3D(mesh, m); |
triangleModel = new GeometryModel3D(mesh, m); |
| 335 |
// |
|
| 336 |
m_primitiveData.RemoveUnAttachedTexture(data.LocalID); |
m_primitiveData.RemoveUnAttachedTexture(LocalID); |
| 337 |
} |
} |
| 338 |
else |
else |
| 339 |
{ |
{ |
| 340 |
string bitmapPath = System.IO.Path.Combine(textureImageFolderPath, data.Textures.DefaultTexture.TextureID.ToString() + ".jpg"); |
string bitmapPath = System.IO.Path.Combine(textureImageFolderPath, TextureID.ToString() + ".jpg"); |
| 341 |
|
|
| 342 |
if (File.Exists(bitmapPath)) |
if (File.Exists(bitmapPath)) |
| 343 |
{ |
{ |
|
//ImageSource imagesource = JpegBitmapDecoder.Create(new Uri(bitmapPath), BitmapCreateOptions.None, BitmapCacheOption.Default).Preview; |
|
|
|
|
| 344 |
ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
|
|
|
| 345 |
ImageBrush brush = new ImageBrush(imagesource); |
ImageBrush brush = new ImageBrush(imagesource); |
| 346 |
m = new DiffuseMaterial(brush); |
m = new DiffuseMaterial(brush); |
| 347 |
|
|
| 348 |
triangleModel = new GeometryModel3D(mesh, m); |
triangleModel = new GeometryModel3D(mesh, m); |
| 349 |
// |
|
| 350 |
m_primitiveData.RemoveUnAttachedTexture(data.LocalID); |
m_primitiveData.RemoveUnAttachedTexture(LocalID); |
| 351 |
|
|
| 352 |
if (m != null) |
if (m != null) |
| 353 |
m_primitiveData.AddNewMaterial2Cache(data.Textures.DefaultTexture.TextureID, m); |
m_primitiveData.AddNewMaterial2Cache(TextureID, m); |
| 354 |
|
|
| 355 |
//imagesource = null; |
imagesource = null; |
| 356 |
// brush = null; |
brush = null; |
| 357 |
// m = null; |
m = null; |
| 358 |
} |
} |
| 359 |
else |
else |
| 360 |
{ |
{ |
| 361 |
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
//col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
| 362 |
data.Textures.DefaultTexture.RGBA.R, |
// data.Textures.DefaultTexture.RGBA.R, |
| 363 |
data.Textures.DefaultTexture.RGBA.G, |
// data.Textures.DefaultTexture.RGBA.G, |
| 364 |
data.Textures.DefaultTexture.RGBA.B); |
// data.Textures.DefaultTexture.RGBA.B); |
| 365 |
|
|
| 366 |
triangleModel = new GeometryModel3D( |
triangleModel = new GeometryModel3D( |
| 367 |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
| 368 |
|
|
| 369 |
m_textureManager.RequestTexture(data.Textures.DefaultTexture.TextureID); |
m_textureManager.RequestTexture(TextureID); |
| 370 |
m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
m_primitiveData.AddUnAttachedTexture(LocalID, TextureID); |
| 371 |
} |
} |
| 372 |
} |
} |
| 373 |
} |
} |
| 374 |
else |
else |
| 375 |
{ |
{ |
|
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
|
|
data.Textures.DefaultTexture.RGBA.R, |
|
|
data.Textures.DefaultTexture.RGBA.G, |
|
|
data.Textures.DefaultTexture.RGBA.B); |
|
|
|
|
| 376 |
triangleModel = new GeometryModel3D( |
triangleModel = new GeometryModel3D( |
| 377 |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
|
|
|
|
//ADD the visual to the needUpdateTexute list.when the texture downloaded update it. |
|
|
m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
|
| 378 |
} |
} |
| 379 |
return triangleModel; |
return triangleModel; |
| 380 |
} |
} |
| 543 |
foreach (Primitive visual in NeedUpdateVisuals) |
foreach (Primitive visual in NeedUpdateVisuals) |
| 544 |
{ |
{ |
| 545 |
//m_primitiveData.RemoveUnAttachedTexture(visual.LocalID); |
//m_primitiveData.RemoveUnAttachedTexture(visual.LocalID); |
| 546 |
RemovePrimitive(visual.LocalID); |
//RemovePrimitive(visual.LocalID); |
| 547 |
AddPrimitive(visual.LocalID, visual); |
|
| 548 |
|
UpdatePrimTexture(visual.LocalID,visual.Textures.DefaultTexture.TextureID); |
| 549 |
|
|
| 550 |
|
//AddPrimitive(visual.LocalID, visual); |
| 551 |
} |
} |
| 552 |
|
|
|
NeedUpdateVisuals.Clear(); |
|
| 553 |
NeedUpdateVisuals = null; |
NeedUpdateVisuals = null; |
| 554 |
|
|
| 555 |
} |
} |
| 556 |
|
|
| 557 |
public void RemovePrimitive(uint id) |
private void UpdatePrimTexture(uint id,UUID textureID) |
| 558 |
{ |
{ |
| 559 |
m_viewport.Dispatcher.Invoke( |
m_viewport.Dispatcher.Invoke( |
| 560 |
DispatcherPriority.Normal, |
DispatcherPriority.Normal, |
| 561 |
new System.Windows.Forms.MethodInvoker |
new System.Windows.Forms.MethodInvoker |
| 562 |
(delegate |
(delegate |
| 563 |
{ |
{ |
| 564 |
|
Visual3D v = m_primitiveData.GetVisualInScene(id); |
| 565 |
|
ModelVisual3D visual = v as ModelVisual3D; |
| 566 |
|
GeometryModel3D tringle = visual.Content as GeometryModel3D; |
| 567 |
|
tringle = PatchTexture(textureID, id, tringle.Geometry as MeshGeometry3D, tringle); |
| 568 |
|
|
| 569 |
{ |
visual.Content = tringle; |
| 570 |
|
|
| 571 |
|
m_primitiveData.RemoveVisualInScene(id); |
| 572 |
|
m_primitiveData.RemovePrimtivePrimData(id); |
| 573 |
|
} |
| 574 |
|
) |
| 575 |
|
); |
| 576 |
|
} |
| 577 |
|
|
| 578 |
|
public void RemovePrimitive(uint id) |
| 579 |
|
{ |
| 580 |
|
m_viewport.Dispatcher.Invoke( |
| 581 |
|
DispatcherPriority.Normal, |
| 582 |
|
new System.Windows.Forms.MethodInvoker |
| 583 |
|
(delegate |
| 584 |
|
{ |
| 585 |
// Remove from scene and models list |
// Remove from scene and models list |
| 586 |
Visual3D v = m_primitiveData.GetVisualInScene(id); |
Visual3D v = m_primitiveData.GetVisualInScene(id); |
| 587 |
m_viewport.Children.Remove(v); |
m_viewport.Children.Remove(v); |
| 590 |
m_primitiveData.RemoveVisualInScene(id); |
m_primitiveData.RemoveVisualInScene(id); |
| 591 |
m_primitiveData.RemovePrimtivePrimData(id); |
m_primitiveData.RemovePrimtivePrimData(id); |
| 592 |
} |
} |
|
} |
|
| 593 |
) |
) |
| 594 |
); |
); |
| 595 |
} |
} |