| 43 |
public static DependencyProperty depIdentity = DependencyProperty.Register("ID", typeof(uint), typeof(Visual3D)); |
public static DependencyProperty depIdentity = DependencyProperty.Register("ID", typeof(uint), typeof(Visual3D)); |
| 44 |
public static DependencyProperty depPosition = DependencyProperty.Register("Position", typeof(Vector3), typeof(Visual3D)); |
public static DependencyProperty depPosition = DependencyProperty.Register("Position", typeof(Vector3), typeof(Visual3D)); |
| 45 |
|
|
| 46 |
private int EnvirementCircleLength = 200; |
private int EnvirementCircleLength = 300; |
| 47 |
|
|
| 48 |
private GridClient gridClient; |
private GridClient gridClient; |
| 49 |
|
|
| 182 |
if (parent != null) |
if (parent != null) |
| 183 |
{ |
{ |
| 184 |
//Primitive parent = m_primitiveData.PrimModelsInScene[data.ParentID]; |
//Primitive parent = m_primitiveData.PrimModelsInScene[data.ParentID]; |
| 185 |
data.Position *= parent.Rotation; |
//data.Position *= parent.Rotation; |
| 186 |
data.Position += parent.Position; |
data.Position += parent.Position; |
| 187 |
} |
} |
| 188 |
|
|
| 290 |
v = CreateModel_Avatar(avatar); |
v = CreateModel_Avatar(avatar); |
| 291 |
|
|
| 292 |
if (data.LocalID == gridClient.Self.LocalID) |
if (data.LocalID == gridClient.Self.LocalID) |
| 293 |
|
{ |
| 294 |
avatarManager.Myself = avatar; |
avatarManager.Myself = avatar; |
| 295 |
|
//Vector3D direction = new Vector3D(avatar.Acceleration.X, avatar.Velocity.Y, avatar.Velocity.Z); |
| 296 |
|
//direction.Normalize(); |
| 297 |
|
//avatarManager.MySelfLookDirection = direction; |
| 298 |
|
} |
| 299 |
//TODO: |
//TODO: |
| 300 |
//v = avatarManager.CreateAvatarModel(m_mesher, data as Avatar); |
//v = avatarManager.CreateAvatarModel(m_mesher, data as Avatar); |
| 301 |
|
|
| 309 |
//to do more than primitives |
//to do more than primitives |
| 310 |
private ModelVisual3D CreateModel_Avatar(Avatar data) |
private ModelVisual3D CreateModel_Avatar(Avatar data) |
| 311 |
{ |
{ |
| 312 |
basic = m_mesher.GenerateSimpleMesh(data, DetailLevel.Highest); |
|
| 313 |
|
FacetedMesh faceMesh = m_mesher.GenerateFacetedMesh(data, DetailLevel.Highest); |
| 314 |
|
|
| 315 |
|
ModelVisual3D model = new ModelVisual3D(); |
| 316 |
|
GeometryModel3D triangleModel = new GeometryModel3D(); |
| 317 |
|
MeshGeometry3D mesh = new MeshGeometry3D(); |
| 318 |
|
|
| 319 |
|
// Draw the prim faces |
| 320 |
|
for (int j = 0; j < faceMesh.Faces.Count; j++) |
| 321 |
|
{ |
| 322 |
|
//mesh = new MeshGeometry3D(); |
| 323 |
|
Face face = faceMesh.Faces[j]; |
| 324 |
|
foreach (Vertex v in face.Vertices) |
| 325 |
|
{ |
| 326 |
|
Vector3 pos = v.Position; |
| 327 |
|
|
| 328 |
|
pos *= data.Scale; |
| 329 |
|
pos *= data.Rotation;//there's something wrong about rotation |
| 330 |
|
pos += data.Position; |
| 331 |
|
|
| 332 |
|
Point3D d = new Point3D(pos.X+1, pos.Y+1, pos.Z+1); |
| 333 |
|
mesh.Positions.Add(d); |
| 334 |
|
|
| 335 |
|
// These normals dont appear to be working for some reason, |
| 336 |
|
// however the auto-generated normals appear adequate for now. |
| 337 |
|
// Vector3D normal = new Vector3D(v.Normal.X, v.Normal.Y, v.Normal.Z); |
| 338 |
|
// mesh.Normals.Add(normal); |
| 339 |
|
double x = (v.Position.Length() == float.Parse("0")) ? 0 : (v.Position.X / v.Position.Length()); |
| 340 |
|
double y = (v.Position.Length() == float.Parse("0")) ? 0 : (v.Position.Y / v.Position.Length()); |
| 341 |
|
|
| 342 |
|
mesh.TextureCoordinates.Add(new Point(x, y)); |
| 343 |
|
} |
| 344 |
|
foreach (ushort ind in face.Indices) |
| 345 |
|
{ |
| 346 |
|
mesh.TriangleIndices.Add(ind); |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
if (data.Textures != null && data.Textures.DefaultTexture != null && |
| 350 |
|
data.Textures.DefaultTexture.TextureID != null) |
| 351 |
|
triangleModel = PatchTexture(data.Textures.DefaultTexture, data.LocalID, mesh, triangleModel); |
| 352 |
|
else |
| 353 |
|
{ |
| 354 |
|
triangleModel = new GeometryModel3D( |
| 355 |
|
mesh, new DiffuseMaterial(new SolidColorBrush(Colors.Red))); |
| 356 |
|
} |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
model = new ModelVisual3D(); |
| 360 |
|
model.Content = triangleModel; |
| 361 |
|
// model = DefaultUtil.CreateCube(triangleModel.Bounds.Location, new Point3D(3, 3, 3), new DiffuseMaterial(new SolidColorBrush(Colors.Red))); |
| 362 |
|
|
| 363 |
|
model.SetValue(depIdentity, data.LocalID); |
| 364 |
|
model.SetValue(depPosition, data.Position); |
| 365 |
|
|
| 366 |
|
return model; |
| 367 |
|
|
| 368 |
|
|
| 369 |
|
#region oldversion |
| 370 |
|
|
| 371 |
|
/* |
| 372 |
|
FacetedMesh facedMesh = m_mesher.GenerateFacetedMesh(data, DetailLevel.Highest); |
| 373 |
mesh = new MeshGeometry3D(); |
mesh = new MeshGeometry3D(); |
| 374 |
triangleModel = new GeometryModel3D(); |
triangleModel = new GeometryModel3D(); |
| 375 |
foreach (Vertex v in basic.Vertices) |
foreach (Face v in facedMesh.Faces) |
| 376 |
{ |
{ |
| 377 |
Vector3 pos = v.Position; |
Vector3 pos = v.Position; |
| 378 |
|
|
| 393 |
mesh.TextureCoordinates.Add(new Point(x, y)); |
mesh.TextureCoordinates.Add(new Point(x, y)); |
| 394 |
} |
} |
| 395 |
|
|
| 396 |
foreach (ushort ind in basic.Indices) |
foreach (ushort ind in facedMesh.Indices) |
| 397 |
{ |
{ |
| 398 |
mesh.TriangleIndices.Add(ind); |
mesh.TriangleIndices.Add(ind); |
| 399 |
} |
} |
| 414 |
model.SetValue(depPosition, data.Position); |
model.SetValue(depPosition, data.Position); |
| 415 |
|
|
| 416 |
return model; |
return model; |
| 417 |
|
*/ |
| 418 |
|
#endregion |
| 419 |
} |
} |
| 420 |
|
|
| 421 |
private ModelVisual3D CreateModel_Vertices(Primitive data) |
private ModelVisual3D CreateModel_Vertices(Primitive data) |
| 751 |
//Ray r = new Ray(new Vector3(oldpos.X, oldpos.Y, oldpos.Z), new Vector3(vec3d.X, vec3d.Y, vec3d.Z)); |
//Ray r = new Ray(new Vector3(oldpos.X, oldpos.Y, oldpos.Z), new Vector3(vec3d.X, vec3d.Y, vec3d.Z)); |
| 752 |
|
|
| 753 |
//ModelVisual3D v; |
//ModelVisual3D v; |
| 754 |
|
if (avatarManager.Myself == null) |
| 755 |
|
return; |
| 756 |
|
|
| 757 |
Visual3D v = m_primitiveData.GetVisualInScene(avatarManager.Myself.LocalID); |
Visual3D v = m_primitiveData.GetVisualInScene(avatarManager.Myself.LocalID); |
| 758 |
|
|
| 759 |
|
//Point3D pos = new Point3D(avatarManager.Myself.Position.X,avatarManager.Myself.Position.Y,avatarManager.Myself.Position.Z); |
| 760 |
|
//Visual3D v = DefaultUtil.CreateCube(pos, new Point3D(3, 3, 3), new DiffuseMaterial(new SolidColorBrush(Colors.Red))); |
| 761 |
|
|
| 762 |
if (v != null) |
if (v != null) |
| 763 |
{ |
{ |
| 764 |
VisualTreeHelper.HitTest(v, null, |
VisualTreeHelper.HitTest(v, null, |