Beispiel #1
0
 // Add the passed MaterialInfo the to list if it is not already in the list
 public void AddUniqueMatInfo(MaterialInfo matInfo)
 {
     lock (Materials) {
         MaterialInfo existingMatInfo = null;
         if (!Materials.TryGetValue(matInfo.GetBHash(), out existingMatInfo))
         {
             // If not already in the list, add this MeshInfo
             Materials.Add(matInfo.GetBHash(), matInfo.handle, matInfo);
         }
     }
 }
Beispiel #2
0
 // Add my hashes to an in-progress hashing
 public void GetBHash(BHasher hasher)
 {
     hasher.Add(mesh.GetBHash());
     hasher.Add(material.GetBHash());
 }
Beispiel #3
0
        private RenderableMesh ConvertFaceToRenderableMesh(OMVR.Face face, IAssetFetcher assetFetcher,
                                                           OMV.Primitive.TextureEntryFace defaultTexture, OMV.Vector3 primScale)
        {
            RenderableMesh rmesh = new RenderableMesh();

            rmesh.num = face.ID;

            // Copy one face's mesh imformation from the FacetedMesh into a MeshInfo
            MeshInfo meshInfo = new MeshInfo {
                vertexs    = new List <OMVR.Vertex>(face.Vertices),
                indices    = face.Indices.ConvertAll(ii => (int)ii),
                faceCenter = face.Center,
                scale      = primScale
            };

            BConverterOS.LogBProgress("{0} ConvertFaceToRenderableMesh: faceId={1}, numVert={2}, numInd={3}",
                                      _logHeader, face.ID, meshInfo.vertexs.Count, meshInfo.indices.Count);

            if (!ConvOAR.Globals.parms.P <bool>("DisplayTimeScaling"))
            {
                if (ScaleMeshes(meshInfo, primScale))
                {
                    BConverterOS.LogBProgress("{0} ConvertFaceToRenderableMesh: scaled mesh to {1}",
                                              _logHeader, primScale);
                }
                meshInfo.scale = OMV.Vector3.One;
            }

            // Find or create the MaterialInfo for this face.
            MaterialInfo matInfo = new MaterialInfo(face, defaultTexture);

            if (matInfo.textureID != null &&
                matInfo.textureID != OMV.UUID.Zero &&
                matInfo.textureID != OMV.Primitive.TextureEntry.WHITE_TEXTURE)
            {
                // Textures/images use the UUID from OpenSim and the hash is just the hash of the UUID
                EntityHandleUUID textureHandle   = new EntityHandleUUID((OMV.UUID)matInfo.textureID);
                BHash            textureHash     = new BHashULong(textureHandle.GetUUID().GetHashCode());
                ImageInfo        lookupImageInfo = assetFetcher.GetImageInfo(textureHash, () => {
                    // The image is not in the cache yet so create an ImageInfo entry for it
                    // Note that image gets the same UUID as the OpenSim texture
                    ImageInfo imageInfo = new ImageInfo(textureHandle);
                    assetFetcher.FetchTextureAsImage(textureHandle)
                    .Then(img => {
                        imageInfo.SetImage(img);
                    })
                    .Catch(e => {
                        // Failure getting the image
                        ConvOAR.Globals.log.ErrorFormat("{0} Failure fetching texture. id={1}. {2}",
                                                        _logHeader, matInfo.textureID, e);
                        // Create a simple, single color image to fill in for the missing image
                        var fillInImage = new Bitmap(32, 32, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                        Color theColor  = Color.FromArgb(128, 202, 213, 170);       // 0x80CAB5AA
                        for (int xx = 0; xx < 32; xx++)
                        {
                            for (int yy = 0; yy < 32; yy++)
                            {
                                fillInImage.SetPixel(xx, yy, theColor);
                            }
                        }
                        imageInfo.SetImage(fillInImage);
                    });
                    imageInfo.imageIdentifier = (OMV.UUID)matInfo.textureID;
                    BConverterOS.LogBProgress("{0} ConvertFaceToRenderableMesh: create ImageInfo. hash={1}, id={2}",
                                              _logHeader, textureHash, imageInfo.handle);
                    return(imageInfo);
                });
                matInfo.image = lookupImageInfo;

                // Update the UV information for the texture mapping
                BConverterOS.LogBProgress("{0} ConvertFaceToRenderableMesh: Converting tex coords using {1} texture",
                                          _logHeader, face.TextureFace == null ? "default" : "face");
                _mesher.TransformTexCoords(meshInfo.vertexs, meshInfo.faceCenter,
                                           face.TextureFace == null ? defaultTexture : face.TextureFace, primScale);
            }

            // See that the material is in the cache
            MaterialInfo lookupMatInfo = assetFetcher.GetMaterialInfo(matInfo.GetBHash(), () => { return(matInfo); });

            rmesh.material = lookupMatInfo;

            // See that the mesh is in the cache
            MeshInfo lookupMeshInfo = assetFetcher.GetMeshInfo(meshInfo.GetBHash(true), () => { return(meshInfo); });

            rmesh.mesh = lookupMeshInfo;
            if (lookupMeshInfo.indices.Count == 0)      // DEBUG DEBUG
            {
                ConvOAR.Globals.log.ErrorFormat("{0} indices count of zero. rmesh={1}", _logHeader, rmesh.ToString());
            }   // DEBUG DEBUG

            BConverterOS.LogBProgress("{0} ConvertFaceToRenderableMesh: rmesh.mesh={1}, rmesh.material={2}",
                                      _logHeader, rmesh.mesh, rmesh.material);

            return(rmesh);
        }