Ejemplo n.º 1
0
        public void SetMesh(PolyMesh mesh)
        {
            Mesh = mesh;

            FreeSkinData();

            if (Mesh == null)
            {
                return;
            }

            // acquire the transform from the mesh object
            // SL-315
            SetPosition(Mesh.Position);
            SetRotation(Mesh.Rotation);
            SetScale(Mesh.Scale);

            // create skin joints if necessary
            if (Mesh.HasWeights && !Mesh.IsLod)
            {
                int numJointNames = Mesh.JointNames.Length;

                AllocateSkinData((UInt32)numJointNames);

                for (int i = 0; i < numJointNames; i++)
                {
                    AvatarJoint joint = (AvatarJoint)GetRoot().FindJoint(Mesh.JointNames[i]);
                    SkinJoints[i].SetupSkinJoint(joint);
                }
            }

            // setup joint array
            if (!Mesh.IsLod)
            {
                SetupJoint((AvatarJoint)GetRoot());
                Logger.LogDebug("AvatarJointMesh.SetMesh", $"{Name} joint render entries: {Mesh.JointRenderData.Count}");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called after construction to initialise the instance.
        /// </summary>
        public virtual void InitInstance()
        {
            // Initialise joint, mesh and shape members

            Root      = CreateAvatarJoint();
            Root.Name = "mRoot";

            foreach (var keyValuePair in AvatarAppearanceDictionary.Instance.MeshEntries)
            {
                AvatarAppearanceDictionary.MeshIndex meshIndex = keyValuePair.Key;
                AvatarAppearanceDictionary.MeshEntry meshEntry = keyValuePair.Value;

                AvatarJoint joint = CreateAvatarJoint();
                joint.Name   = meshEntry.Name;
                joint.MeshId = (int)meshIndex;
                MeshLod.Add(joint);

                for (int lod = 0; lod < meshEntry.Lod; lod++)
                {
                    // TODO: Stopped here!
                    AvatarJointMesh mesh = CreateAvatarJointMesh();

                    //// We pre-pended an m - need to capitalise first character for camelCase
                    char   first    = Char.ToUpper(meshEntry.Name[0]);
                    string meshName = $"m{first}{meshEntry.Name.Substring(1)}{lod}"; // "m" + mesh_dict->mName + boost::lexical_cast < std::string> (lod); // TODO: What is lexical_cast()?
                    mesh.Name   = meshName;
                    mesh.MeshId = (int)meshIndex;
                    //mesh->setPickName(mesh_dict->mPickName);
                    mesh.IsTransparent = false;
                    switch (meshIndex)
                    {
                    case AvatarAppearanceDictionary.MeshIndex.Hair:
                        mesh.IsTransparent = true;
                        break;

                    case AvatarAppearanceDictionary.MeshIndex.Skirt:
                        mesh.IsTransparent = true;
                        break;

                    case AvatarAppearanceDictionary.MeshIndex.EyeBallLeft:
                    case AvatarAppearanceDictionary.MeshIndex.EyeBallRight:
                        mesh.SetSpecular(new Color(1.0f, 1.0f, 1.0f, 1.0f), 1f);
                        break;
                    }

                    joint.MeshParts.Add(mesh);
                }
            }

            // Associate baked textures with meshes
            foreach (KeyValuePair <AvatarAppearanceDictionary.MeshIndex, AvatarAppearanceDictionary.MeshEntry> keyValuePair in AvatarAppearanceDictionary.Instance.MeshEntries)
            {
                AvatarAppearanceDictionary.MeshIndex         meshIndex         = keyValuePair.Key;
                AvatarAppearanceDictionary.MeshEntry         meshEntry         = keyValuePair.Value;
                AvatarAppearanceDictionary.BakedTextureIndex bakedTextureIndex = meshEntry.BakedTextureIndex;

                // Skip it if there's no associated baked texture.
                if (bakedTextureIndex == AvatarAppearanceDictionary.BakedTextureIndex.NumIndices)
                {
                    continue;
                }

                foreach (AvatarJointMesh mesh in MeshLod[(int)meshIndex].MeshParts)
                {
                    BakedTextureDatas[(int)bakedTextureIndex].JointMeshes.Add(mesh);
                }
            }

            BuildCharacter();

            InitFlags |= 1 << 0;
        }