| 122 |
{ |
{ |
| 123 |
//lock (DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions) |
//lock (DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions) |
| 124 |
{ |
{ |
| 125 |
// DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[id] = data.Position; |
DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[id] = data.Position; |
| 126 |
} |
} |
| 127 |
|
|
| 128 |
if(Broken) |
if(Broken) |
| 148 |
else if (DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions.ContainsKey(data.ParentID)) |
else if (DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions.ContainsKey(data.ParentID)) |
| 149 |
{ |
{ |
| 150 |
data.Position += DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[data.ParentID]; |
data.Position += DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[data.ParentID]; |
| 151 |
|
// DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[id] = data.Position; |
| 152 |
|
|
| 153 |
WaitParentIn = false; |
WaitParentIn = false; |
| 154 |
} |
} |
| 155 |
|
|
|
DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[id] = data.Position; |
|
| 156 |
} |
} |
| 157 |
|
|
| 158 |
if (WaitParentIn == false) |
if (WaitParentIn == false) |
| 169 |
for (int i = 0; i < waiting.Count; i++) |
for (int i = 0; i < waiting.Count; i++) |
| 170 |
{ |
{ |
| 171 |
Primitive child = waiting[i]; |
Primitive child = waiting[i]; |
| 172 |
|
child.Position += data.Position; |
|
lock( DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions) |
|
|
DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[child.LocalID] = child.Position; |
|
|
|
|
|
|
|
| 173 |
model = CreateModel(child); |
model = CreateModel(child); |
| 174 |
if (model == null) |
if (model == null) |
| 175 |
return; |
return; |
| 176 |
|
|
| 177 |
child.Position += data.Position; |
|
| 178 |
|
lock( DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions) |
| 179 |
|
DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsParentPositions[child.LocalID] = child.Position; |
| 180 |
|
|
| 181 |
m_viewport.Children.Add(model); |
m_viewport.Children.Add(model); |
| 182 |
|
|
| 183 |
DefaultNetwork.DefaultNetwork.m_primitiveData.AddNewPrimitive(id, model, waiting[i].ParentID); |
DefaultNetwork.DefaultNetwork.m_primitiveData.AddNewPrimitive(id, model, waiting[i].ParentID); |
| 256 |
|
|
| 257 |
private ModelVisual3D CreateModel(Primitive data) |
private ModelVisual3D CreateModel(Primitive data) |
| 258 |
{ |
{ |
| 259 |
|
bool notComplete = false; |
| 260 |
|
SimpleMesh basic = m_mesher.GenerateSimpleMesh(data, DetailLevel.Medium); |
| 261 |
|
MeshGeometry3D mesh = new MeshGeometry3D(); |
| 262 |
|
ModelVisual3D model = new ModelVisual3D(); |
| 263 |
|
GeometryModel3D triangleModel = new GeometryModel3D(); |
| 264 |
|
|
| 265 |
//SimpleMesh basic = m_mesher.GenerateSimpleMesh(data, DetailLevel.Medium); |
//FacetedMesh faceMesh = m_mesher.GenerateFacetedMesh(data, DetailLevel.Medium); |
|
FacetedMesh faceMesh = m_mesher.GenerateFacetedMesh(data, DetailLevel.Medium); |
|
| 266 |
|
|
| 267 |
// Translation |
// Translation |
| 268 |
TranslateTransform3D tt = new TranslateTransform3D( |
TranslateTransform3D tt = new TranslateTransform3D( |
| 279 |
ScaleTransform3D st = new ScaleTransform3D( |
ScaleTransform3D st = new ScaleTransform3D( |
| 280 |
new Vector3D(data.Scale.X, data.Scale.Y, data.Scale.Z)); |
new Vector3D(data.Scale.X, data.Scale.Y, data.Scale.Z)); |
| 281 |
|
|
| 282 |
//foreach (Vertex v in basic.Vertices) |
foreach (Vertex v in basic.Vertices) |
| 283 |
//{ |
{ |
| 284 |
// Point3D d = new Point3D( |
Point3D d = new Point3D( |
| 285 |
// v.Position.X, |
v.Position.X, |
| 286 |
// v.Position.Y, |
v.Position.Y, |
| 287 |
// v.Position.Z); |
v.Position.Z); |
| 288 |
|
|
| 289 |
// // Scale |
// Scale |
| 290 |
// d = st.Transform(d); |
d = st.Transform(d); |
| 291 |
// // Rotate |
// Rotate |
| 292 |
// d = rt.Transform(d); |
d = rt.Transform(d); |
| 293 |
// // Move |
// Move |
| 294 |
// d = tt.Transform(d); |
d = tt.Transform(d); |
| 295 |
|
|
| 296 |
// mesh.Positions.Add(d); |
mesh.Positions.Add(d); |
| 297 |
// // These normals dont appear to be working for some reason, |
// These normals dont appear to be working for some reason, |
| 298 |
// // however the auto-generated normals appear adequate for now. |
// however the auto-generated normals appear adequate for now. |
| 299 |
// //mesh.Normals.Add(new Vector3D(v.Normal.X, v.Normal.Y, v.Normal.Z)); |
//mesh.Normals.Add(new Vector3D(v.Normal.X, v.Normal.Y, v.Normal.Z)); |
| 300 |
// mesh.TextureCoordinates.Add(new Point(v.TexCoord.X, v.TexCoord.Y)); |
// mesh.TextureCoordinates.Add(new Point(v.TexCoord.X, v.TexCoord.Y)); |
| 301 |
//} |
} |
| 302 |
|
|
| 303 |
|
foreach (ushort ind in basic.Indices) |
| 304 |
|
{ |
| 305 |
|
mesh.TriangleIndices.Add(ind); |
| 306 |
|
} |
| 307 |
|
mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 308 |
|
mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 309 |
|
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 310 |
|
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 311 |
|
|
| 312 |
|
mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 313 |
|
mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 314 |
|
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 315 |
|
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 316 |
|
|
| 317 |
//foreach (ushort ind in basic.Indices) |
mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 318 |
//{ |
mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 319 |
// mesh.TriangleIndices.Add(ind); |
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 320 |
//} |
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 321 |
|
|
| 322 |
|
Color col = Colors.YellowGreen; |
| 323 |
|
/* |
| 324 |
ModelVisual3D model = new ModelVisual3D(); |
ModelVisual3D model = new ModelVisual3D(); |
| 325 |
GeometryModel3D triangleModel = new GeometryModel3D(); |
GeometryModel3D triangleModel = new GeometryModel3D(); |
| 326 |
|
|
| 355 |
mesh.TextureCoordinates.Add(new Point(0, 1)); |
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 356 |
mesh.TextureCoordinates.Add(new Point(1, 1)); |
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 357 |
|
|
| 358 |
|
mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 359 |
|
mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 360 |
|
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 361 |
|
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 362 |
|
|
| 363 |
|
mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 364 |
|
mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 365 |
|
mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 366 |
|
mesh.TextureCoordinates.Add(new Point(1, 1)); |
| 367 |
|
|
| 368 |
//mesh.TextureCoordinates.Add(new Point(0, 0)); |
//mesh.TextureCoordinates.Add(new Point(0, 0)); |
| 369 |
//mesh.TextureCoordinates.Add(new Point(1, 0)); |
//mesh.TextureCoordinates.Add(new Point(1, 0)); |
| 370 |
//mesh.TextureCoordinates.Add(new Point(0, 1)); |
//mesh.TextureCoordinates.Add(new Point(0, 1)); |
| 382 |
string bitmapPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture\\" + face.TextureFace.TextureID.ToString() + ".bmp"); |
string bitmapPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture\\" + face.TextureFace.TextureID.ToString() + ".bmp"); |
| 383 |
if (File.Exists(bitmapPath) == false) |
if (File.Exists(bitmapPath) == false) |
| 384 |
{ |
{ |
| 385 |
|
//ADD the visual to the needUpdateTexute list.when the texture downloaded update it. |
| 386 |
|
DefaultNetwork.DefaultNetwork.m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
| 387 |
|
//notComplete = true; |
| 388 |
|
//break; |
| 389 |
|
|
| 390 |
|
|
| 391 |
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
| 392 |
data.Textures.DefaultTexture.RGBA.R, |
data.Textures.DefaultTexture.RGBA.R, |
| 393 |
data.Textures.DefaultTexture.RGBA.G, |
data.Textures.DefaultTexture.RGBA.G, |
| 398 |
visual.Content = triangleModel; |
visual.Content = triangleModel; |
| 399 |
|
|
| 400 |
model.Children.Add(visual); |
model.Children.Add(visual); |
| 401 |
//ADD the visual to the needUpdateTexute list.when the texture downloaded update it. |
|
|
DefaultNetwork.DefaultNetwork.m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
|
| 402 |
continue; |
continue; |
| 403 |
} |
} |
| 404 |
ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
| 412 |
} |
} |
| 413 |
} |
} |
| 414 |
|
|
| 415 |
|
*/ |
| 416 |
|
if (data.Textures != null && |
| 417 |
|
data.Textures.FaceTextures != null && |
| 418 |
|
data.Textures.FaceTextures.Length > 0) |
| 419 |
|
{ |
| 420 |
|
|
| 421 |
|
string bitmapPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture\\" + data.Textures.DefaultTexture.TextureID.ToString() + ".bmp"); |
| 422 |
|
|
| 423 |
|
if (File.Exists(bitmapPath)) |
| 424 |
|
{ |
| 425 |
|
ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
| 426 |
|
|
| 427 |
|
ImageBrush brush = new ImageBrush(imagesource); |
| 428 |
|
triangleModel = new GeometryModel3D( |
| 429 |
|
mesh, new DiffuseMaterial(brush)); |
| 430 |
|
} |
| 431 |
|
else |
| 432 |
|
{ |
| 433 |
|
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
| 434 |
|
data.Textures.DefaultTexture.RGBA.R, |
| 435 |
|
data.Textures.DefaultTexture.RGBA.G, |
| 436 |
|
data.Textures.DefaultTexture.RGBA.B); |
| 437 |
|
|
| 438 |
|
triangleModel = new GeometryModel3D( |
| 439 |
|
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
| 440 |
|
|
| 441 |
|
} |
| 442 |
|
} |
| 443 |
|
else |
| 444 |
|
{ |
| 445 |
|
col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
| 446 |
|
data.Textures.DefaultTexture.RGBA.R, |
| 447 |
|
data.Textures.DefaultTexture.RGBA.G, |
| 448 |
|
data.Textures.DefaultTexture.RGBA.B); |
| 449 |
|
|
| 450 |
|
triangleModel = new GeometryModel3D( |
| 451 |
|
mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
| 452 |
|
|
| 453 |
//if (data.Textures != null && |
//ADD the visual to the needUpdateTexute list.when the texture downloaded update it. |
| 454 |
// data.Textures.FaceTextures != null && |
DefaultNetwork.DefaultNetwork.m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
| 455 |
// data.Textures.FaceTextures.Length > 0) |
} |
|
//{ |
|
|
|
|
|
// string bitmapPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture\\" + data.Textures.DefaultTexture.TextureID.ToString() + ".bmp"); |
|
|
|
|
|
// if (File.Exists(bitmapPath)) |
|
|
// { |
|
|
// ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
|
|
|
|
|
// ImageBrush brush = new ImageBrush(imagesource); |
|
|
// triangleModel = new GeometryModel3D( |
|
|
// mesh, new DiffuseMaterial(brush)); |
|
|
// } |
|
|
// else |
|
|
// { |
|
|
// col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
|
|
// data.Textures.DefaultTexture.RGBA.R, |
|
|
// data.Textures.DefaultTexture.RGBA.G, |
|
|
// data.Textures.DefaultTexture.RGBA.B); |
|
|
|
|
|
// triangleModel = new GeometryModel3D( |
|
|
// mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
|
|
|
|
|
// } |
|
|
//} |
|
|
//else |
|
|
//{ |
|
|
// col = Color.FromScRgb(data.Textures.DefaultTexture.RGBA.A, |
|
|
// data.Textures.DefaultTexture.RGBA.R, |
|
|
// data.Textures.DefaultTexture.RGBA.G, |
|
|
// data.Textures.DefaultTexture.RGBA.B); |
|
|
|
|
|
// triangleModel = new GeometryModel3D( |
|
|
// mesh, new DiffuseMaterial(new SolidColorBrush(col))); |
|
|
|
|
|
// //ADD the visual to the needUpdateTexute list.when the texture downloaded update it. |
|
|
// DefaultNetwork.DefaultNetwork.m_primitiveData.AddUnAttachedTexture(data.LocalID, data.Textures.DefaultTexture.TextureID); |
|
|
//} |
|
| 456 |
|
|
| 457 |
|
|
| 458 |
|
|
| 465 |
mesh, mat); |
mesh, mat); |
| 466 |
*/ |
*/ |
| 467 |
|
|
| 468 |
//model.Content = triangleModel; |
model.Content = triangleModel; |
| 469 |
|
|
| 470 |
|
|
| 471 |
return model; |
return model; |
| 472 |
} |
} |
| 477 |
|
|
| 478 |
foreach (Primitive visual in NeedUpdateVisuals) |
foreach (Primitive visual in NeedUpdateVisuals) |
| 479 |
{ |
{ |
| 480 |
|
DefaultNetwork.DefaultNetwork.m_primitiveData.RemoveUnAttachedTexture(visual.LocalID); |
| 481 |
|
RemovePrimitive(visual.LocalID); |
| 482 |
AddPrimitive(visual.LocalID, visual); |
AddPrimitive(visual.LocalID, visual); |
|
// visual.Dispatcher.Invoke( |
|
|
// DispatcherPriority.Normal, |
|
|
// new System.Windows.Forms.MethodInvoker(delegate |
|
|
// { |
|
|
// ModelVisual3D model = visual as ModelVisual3D; |
|
|
// if (model == null) |
|
|
// return; |
|
|
// GeometryModel3D gTexture = model.Content as GeometryModel3D; |
|
|
// if (gTexture == null) |
|
|
// return; |
|
|
// string bitmapPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "texture\\" + textureID.ToString() + ".bmp"); |
|
|
|
|
|
// if (File.Exists(bitmapPath)) |
|
|
// { |
|
|
// try |
|
|
// { |
|
|
// ImageSource imagesource = new BitmapImage(new Uri(bitmapPath)); |
|
|
// ImageBrush brush = new ImageBrush(imagesource); |
|
|
// gTexture.Material = new DiffuseMaterial(brush); |
|
|
|
|
|
// model.Content = gTexture; |
|
|
|
|
|
// uint? key = DefaultNetwork.DefaultNetwork.m_primitiveData.GetKeyInSceneByValue(model); |
|
|
// if (key.HasValue) |
|
|
// DefaultNetwork.DefaultNetwork.m_primitiveData.RemoveUnAttachedTexture(key.Value); |
|
|
// } |
|
|
// catch (Exception er) |
|
|
// { |
|
|
// MessageBox.Show(er.ToString()); |
|
|
// } |
|
|
// } |
|
|
|
|
|
// })); |
|
| 483 |
} |
} |
| 484 |
|
|
|
|
|
| 485 |
} |
} |
| 486 |
|
|
| 487 |
public void RemovePrimitive(uint id) |
public void RemovePrimitive(uint id) |
| 491 |
new System.Windows.Forms.MethodInvoker |
new System.Windows.Forms.MethodInvoker |
| 492 |
(delegate |
(delegate |
| 493 |
{ |
{ |
| 494 |
if(m_models.ContainsKey(id)) |
if(DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsInScene.ContainsKey(id)) |
| 495 |
{ |
{ |
| 496 |
// Remove from scene and models list |
// Remove from scene and models list |
| 497 |
m_viewport.Children.Remove(m_models[id]); |
m_viewport.Children.Remove(DefaultNetwork.DefaultNetwork.m_primitiveData.ModelsInScene[id]); |
|
m_models.Remove(id); |
|
| 498 |
} |
} |
| 499 |
} |
} |
| 500 |
) |
) |