GetMaterial() public method

public GetMaterial ( UUID texUUID ) : Material
texUUID UUID
return UnityEngine.Material
Exemplo n.º 1
0
    void UpdateAvTexture(uint avLocalID)
    {
        GameObject avatarGameObject;

        if (!avatars.TryGetValue(avLocalID, out avatarGameObject))
        {
            return;             //get AvatarAppearence before AvatarUpdate
        }
        bool del = true;

        Radegast.Rendering.RenderAvatar ra = renderAvatars[avLocalID];
        foreach (Radegast.Rendering.GLMesh mesh in ra.glavatar._meshes.Values)
        {
            if (mesh.Name == "skirtMesh")
            {
                continue;
            }
            UUID texID = ra.avatar.Textures.GetFace((uint)mesh.teFaceID).TextureID;

            UnityEngine.Material mat = m_textures.GetMaterial(texID);
            if (mat != null)
            {
                Transform child = avatarGameObject.transform.FindChild(mesh.Name);
                child.GetComponent <MeshRenderer>().material = mat;
            }
            else
            {
                del = false;
            }
        }
        if (del)
        {
            avHasTex.Remove(avLocalID);
        }
    }
Exemplo n.º 2
0
    void ProcessPrim(FacetedMesh mesh)
    {
        if (objects.ContainsKey(mesh.Prim.LocalID))
        {
            return;
        }

        GameObject parent = null;

        if (mesh.Prim.ParentID != 0)
        {
            if (!objects.ContainsKey(mesh.Prim.ParentID))
            {
                if (newPrims.ContainsKey(mesh.Prim.ParentID) == false)
                {
                    return;                    //temperarily ignore the prim
                }
                ProcessPrim(newPrims[mesh.Prim.ParentID]);
            }
            parent = objects[mesh.Prim.ParentID];
        }
        else
        {
            parent = primObjects;
        }

        GameObject obj = new GameObject(mesh.Prim.LocalID.ToString());

        // Create vertices, uv, triangles for EACH FACE that stores the 3D data in Unity3D friendly format
        for (int j = 0; j < mesh.Faces.Count; j++)
        {
            Face       face    = mesh.Faces[j];
            GameObject faceObj = new GameObject("face" + j.ToString());
            faceObj.transform.parent = obj.transform;

            MeshRenderer mr = (faceObj.AddComponent("MeshRenderer") as MeshRenderer);
            if (Application.platform == RuntimePlatform.WindowsPlayer ||
                Application.platform == RuntimePlatform.WindowsEditor)
            {
                UnityEngine.Material mat = m_textures.GetMaterial(face.TextureFace.TextureID);
                //Texture2D tex = m_textures.GetTexture2D(face.TextureFace.TextureID);
                if (mat != null)
                {
                    mr.material = mat;
                }
                else
                {
                    mr.material = m_defaultObjectMat;
                }
            }
            else
            {
                mr.material = m_defaultObjectMat;
            }

            UnityEngine.Mesh unityMesh = (faceObj.AddComponent("MeshFilter") as MeshFilter).mesh;

            Utility.MakeMesh(unityMesh, face, 0, face.Vertices.Count - 1, 0, face.Indices.Count - 1, 0);
        }
        //second life's child object's position and rotation is local, but scale are global.
        //So we have to set parent when setting position, and unset parent when setting rotation and scale.
        //Radegast explains well:
        //pos = parentPos + obj.InterpolatedPosition * parentRot;
        //rot = parentRot * obj.InterpolatedRotation;
        obj.transform.position = parent.transform.position +
                                 parent.transform.rotation * new UnityEngine.Vector3(mesh.Prim.Position.X, mesh.Prim.Position.Y, -mesh.Prim.Position.Z);

        //we invert the z axis, and Second Life rotatation is about right hand, but Unity rotation is about left hand, so we negate the x and y part of the quaternion.
        //You have to deeply understand the quaternion to understand this.
        obj.transform.rotation     = parent.transform.rotation * new UnityEngine.Quaternion(-mesh.Prim.Rotation.X, -mesh.Prim.Rotation.Y, mesh.Prim.Rotation.Z, mesh.Prim.Rotation.W);
        obj.transform.localScale   = new UnityEngine.Vector3(mesh.Prim.Scale.X, mesh.Prim.Scale.Y, mesh.Prim.Scale.Z);
        objects[mesh.Prim.LocalID] = obj;
        obj.transform.parent       = primObjects.transform;
        //Debug.Log("prim " + mesh.Prim.LocalID.ToString() + ": Pos,"+mesh.Prim.Position.ToString() + " Rot,"+mesh.Prim.Rotation.ToString() + " Scale,"+mesh.Prim.Scale.ToString());
        //Sadly, when it comes to non-uniform scale parent, Unity will skew the child, so we cannot make hierachy of the objects.
    }