public MeshContainer(SkinnedMeshRenderer skinnedRenderer) { Mesh = skinnedRenderer.sharedMesh; transform = skinnedRenderer.GetComponent <Transform>(); bones = skinnedRenderer.bones; isAnimated = true; }
// -- PUBLIC // .. EXENSION_METHODS public static Vector3 LocalPointToWorldSpace(this SkinnedMeshRenderer skinned_mesh_renderer, Vector3 point) { Transform transform; transform = skinned_mesh_renderer.GetComponent <Transform>(); return(transform.rotation * point + transform.position); }
public CocoMakeupControlExecutorBase(GameObject target, string materialProperty, bool bakeMesh) { m_Renderer = target.GetComponentInChildren <SkinnedMeshRenderer> (); // collider m_MeshCollider = m_Renderer.GetComponent <MeshCollider> (); if (m_MeshCollider == null) { m_MeshCollider = m_Renderer.gameObject.AddComponent <MeshCollider> (); m_ColliderIsOwned = true; } // bake mesh m_OriginMesh = m_MeshCollider.sharedMesh; m_BakeMesh = bakeMesh; if (m_BakeMesh) { if (m_MeshCollider.sharedMesh == null || m_MeshCollider.sharedMesh == m_Renderer.sharedMesh) { Mesh mesh = new Mesh(); m_Renderer.BakeMesh(mesh); m_MeshCollider.sharedMesh = mesh; } else { m_BakeMesh = false; } } else { m_MeshCollider.sharedMesh = m_Renderer.sharedMesh; } }
private static string SkinnedMeshRendererFilterToString(SkinnedMeshRenderer mf, Dictionary <string, ObjMaterial> materialList) { Mesh m = mf.sharedMesh; Material[] mats = mf.GetComponent <Renderer>().sharedMaterials; StringBuilder sb = new StringBuilder(); sb.Append("g ").Append(mf.name).Append("\n"); foreach (Vector3 lv in m.vertices) { Vector3 wv = mf.transform.TransformPoint(lv); //This is sort of ugly - inverting x-component since we're in //a different coordinate system than "everyone" is "used to". sb.Append(string.Format("v {0} {1} {2}\n", -wv.x, wv.y, wv.z)); } sb.Append("\n"); foreach (Vector3 lv in m.normals) { Vector3 wv = mf.transform.TransformDirection(lv); sb.Append(string.Format("vn {0} {1} {2}\n", -wv.x, wv.y, wv.z)); } sb.Append("\n"); foreach (Vector3 v in m.uv) { sb.Append(string.Format("vt {0} {1}\n", v.x, v.y)); } return(MeshToString(m, mats, sb, materialList)); }
public SkinnedMeshCapturer(AlembicExporter exp, ComponentCapturer parent, SkinnedMeshRenderer target) : base(exp, parent, target) { m_target = target; var mesh = target.sharedMesh; if (mesh == null) { return; } m_abc = parent.abc.NewPolyMesh(target.name); m_mbuf = new MeshBuffer(); m_mbuf.SetupSubmeshes(m_abc, mesh, m_target.sharedMaterials); m_meshSrc = target.sharedMesh; m_cloth = m_target.GetComponent <Cloth>(); if (m_cloth != null) { m_cbuf = new ClothBuffer(); m_cbuf.rootBone = m_target.rootBone != null ? m_target.rootBone : m_target.GetComponent <Transform>(); var tc = m_parent as TransformCapturer; if (tc != null) { tc.capturePosition = false; tc.captureRotation = false; tc.captureScale = false; } } }
public SkinnedMeshCapturer(usdiExporter exporter, ComponentCapturer parent, SkinnedMeshRenderer target) : base(exporter, parent, target.GetComponent <Transform>(), false) { m_usd = usdi.usdiCreateMesh(ctx, parent.usd, CreateName(target)); m_target = target; m_buffer = new MeshBuffer(); if (m_target.GetComponent <Cloth>() != null) { base.scale = false; } m_captureNormals = exporter.m_captureMeshNormals; m_captureTangents = exporter.m_captureMeshTangents; m_captureUVs = exporter.m_captureMeshUVs; m_captureBones = exporter.m_captureSkinnedMeshAs == SkinnedMeshCaptureMode.BoneAndWeights; m_captureEveryFrame = !m_captureBones; var conf = target.GetComponent <usdiMeshExportConfig>(); if (conf != null) { m_captureNormals = conf.m_captureNormals; m_captureTangents = conf.m_captureTangents; m_captureUVs = conf.m_captureUVs; m_captureEveryFrame = conf.m_captureEveryFrame; m_captureEveryFrameUV = conf.m_captureEveryFrameUV; m_captureEveryFrameIndices = conf.m_captureEveryFrameIndices; } }
public override void Setup(Component c) { var target = c as SkinnedMeshRenderer; m_target = target; var mesh = target.sharedMesh; if (mesh == null) { return; } abcObject = parent.abcObject.NewPolyMesh(target.name, timeSamplingIndex); if (recorder.Settings.MeshSubmeshes) { m_mbuf.SetupSubmeshes(abcObject, mesh); } m_meshSrc = target.sharedMesh; m_cloth = m_target.GetComponent <Cloth>(); if (m_cloth != null) { m_cbuf = new ClothBuffer(); m_cbuf.rootBone = m_target.rootBone != null ? m_target.rootBone : m_target.GetComponent <Transform>(); var tc = parent as TransformCapturer; if (tc != null) { tc.capturePosition = false; tc.captureRotation = false; tc.captureScale = false; } } }
protected IEnumerator Reload() { m_isReloading = true; if (m_isOutOfAmmo == true) { // 탄창 모두 소진시 다른 애니메이션 재생 m_Animator.Play("Reload Out Of Ammo", 0, 0f); m_MainAudioSource.clip = m_SoundClips.reloadSoundOutOfAmmo; m_MainAudioSource.Play(); //If out of ammo, hide the bullet renderer in the mag //Do not show if bullet renderer is not assigned in inspector if (m_BulletInMagRenderer != null) { m_BulletInMagRenderer.GetComponent <SkinnedMeshRenderer>().enabled = false; //Start show bullet delay StartCoroutine(ShowBulletInMag()); } } else { // 탄창이 남아 있으면 일반 재장전 애니메이션 재생 m_Animator.Play("Reload Ammo Left", 0, 0f); m_MainAudioSource.clip = m_SoundClips.reloadSoundAmmoLeft; m_MainAudioSource.Play(); //If reloading when ammo left, show bullet in mag //Do not show if bullet renderer is not assigned in inspector if (m_BulletInMagRenderer != null) { m_BulletInMagRenderer.GetComponent <SkinnedMeshRenderer>().enabled = true; } } yield return(new WaitForSeconds(1)); //Restore ammo when reloading m_CurrentAmmo = m_MaxAmmo; if (m_isOutOfAmmo) { m_CurrentAmmo -= m_SpairBullet; } m_isOutOfAmmo = false; }
private void Start() { _leftHandRenderer = LeftVisualHand.GetComponent <Renderer>(); _rightHandRenderer = RightVisualHand.GetComponent <Renderer>(); _leftUnderarm = LeftVisualUnderarm.GetComponent <Renderer>(); _rightUnderarm = RightVisualUnderarm.GetComponent <Renderer>(); _handManager = GetComponent <PhysicsHandManager>(); }
public void ChangeCloth(SkinnedMeshRenderer usedSkinMeshRenderer) { if (itemUnlocked) { usedSkinMeshRenderer.sharedMesh = mesh; usedSkinMeshRenderer.GetComponent <Renderer>().sharedMaterial = usedMaterial; } }
private void OnTriggerEnter(Collider other) { //doorSoundSource.PlayOneShot(hitSound); HitBoxScript hit; if (!isInvincibile && other.TryGetComponent <HitBoxScript>(out hit)) { Damage((uint)hit.damage); hitSoundSource.PlayOneShot(hitSound); if (HP <= 0) { mesh.GetComponent <SkinnedMeshRenderer>().enabled = false; Instantiate(playerExplosion, this.transform.position, Quaternion.identity); StartCoroutine(Wait(waitTime)); } else { StartCoroutine(playerInvincibility()); } } if (other.CompareTag("Key")) { keySoundSource.PlayOneShot(keyCollectSound); GetKey(); Destroy(other.gameObject); } if (other.CompareTag("Win")) { itemSoundSource.PlayOneShot(itemCollectSound); Destroy(other.gameObject); StartCoroutine(Wait(waitTime)); SceneManager.LoadScene(youWin); } if (other.CompareTag("Lose")) { mesh.GetComponent <SkinnedMeshRenderer>().enabled = false; Instantiate(playerExplosion, this.transform.position, Quaternion.identity); StartCoroutine(Wait(waitTime)); } }
// Use this for initialization void Start() { isWingOpen = true; //beetles wings are open at first BossAnim = GetComponent <Animator>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); _neptoScript = _neptoScript.GetComponent <BossNepto>(); beetleCollider = GetComponent <Collider>(); BossRenderer = BossRenderer.GetComponent <SkinnedMeshRenderer>(); }
public static void CreateControlPoints(SkinnedMeshRenderer skin) { if (skin.sharedMesh != null) { Skin2D skin2D = skin.GetComponent <Skin2D>(); if (skin2D != null) { skin2D.controlPoints = new ControlPoints.Point[skin.sharedMesh.vertices.Length]; if (skin2D.points == null) { skin2D.points = skin2D.gameObject.AddComponent <ControlPoints>(); } } for (int i = 0; i < skin.sharedMesh.vertices.Length; i++) { Vector3 originalPos = skin.sharedMesh.vertices[i]; if (skin2D != null) { skin2D.controlPoints[i] = new ControlPoints.Point(originalPos); skin2D.controlPoints[i].index = i; skin2D.points.SetPoint(skin2D.controlPoints[i]); } GameObject b = new GameObject(skin.name + " Control Point"); // Unparent the skin temporarily before adding the control point Transform skinParent = skin.transform.parent; skin.transform.parent = null; // Reset the rotation before creating the mesh so the UV's will align properly Quaternion localRotation = skin.transform.localRotation; skin.transform.localRotation = Quaternion.identity; b.transform.position = new Vector3(skin.transform.position.x + (skin.sharedMesh.vertices[i].x * skin.transform.localScale.x), skin.transform.position.y + (skin.sharedMesh.vertices[i].y * skin.transform.localScale.y), skin.transform.position.z + (skin.sharedMesh.vertices[i].z * skin.transform.localScale.z)); b.transform.parent = skin.transform; ControlPoint[] points = b.transform.parent.transform.GetComponentsInChildren <ControlPoint>(); if (points != null && points.Length > 0) { b.gameObject.name = b.gameObject.name + points.Length; } Undo.RegisterCreatedObjectUndo(b, "Add control point"); ControlPoint controlPoint = b.AddComponent <ControlPoint>(); controlPoint.index = i; controlPoint.skin = skin; controlPoint.originalPosition = b.transform.localPosition; // Reset the rotations of the object skin.transform.localRotation = localRotation; skin.transform.parent = skinParent; } } }
private IEnumerator AutoReload() { if (!hasStartedSliderBack) { hasStartedSliderBack = true; StartCoroutine(HandgunSliderBackDelay()); } //Wait for set amount of time yield return(new WaitForSeconds(autoReloadDelay)); if (outOfAmmo == true) { //Play diff anim if out of ammo anim.Play("Reload Out Of Ammo", 0, 0f); mainAudioSource.clip = SoundClips.reloadSoundOutOfAmmo; mainAudioSource.Play(); //If out of ammo, hide the bullet renderer in the mag //Do not show if bullet renderer is not assigned in inspector if (bulletInMagRenderer != null) { bulletInMagRenderer.GetComponent <SkinnedMeshRenderer> ().enabled = false; //Start show bullet delay StartCoroutine(ShowBulletInMag()); } } //Restore ammo when reloading if (AmmoCtr.Instance.armList[armNumber].backupAmmo + AmmoCtr.Instance.armList[armNumber].magazineClipAmmo >= AmmoCtr.Instance.armList[armNumber].magazineClip) { AmmoCtr.Instance.armList[armNumber].backupAmmo -= AmmoCtr.Instance.armList[armNumber].magazineClip; AmmoCtr.Instance.armList[armNumber].backupAmmo += AmmoCtr.Instance.armList[armNumber].magazineClipAmmo; AmmoCtr.Instance.armList[armNumber].magazineClipAmmo = AmmoCtr.Instance.armList[armNumber].magazineClip; } else { AmmoCtr.Instance.armList[armNumber].magazineClipAmmo += AmmoCtr.Instance.armList[armNumber].backupAmmo; AmmoCtr.Instance.armList[armNumber].backupAmmo = 0; } outOfAmmo = false; }
public void PrecacheBones() { skeleton = new List <string>(); Transform[] ts = smr.GetComponent <SkinnedMeshRenderer>().bones; for (int i = 0; i < ts.Length; i++) { skeleton.Add(ts[i].name); } smr = this.GetComponent <SkinnedMeshRenderer>(); }
public void AddGlowMaterial(SkinnedMeshRenderer skinnedMRenderer) { Material[] temp = new Material[skinnedMRenderer.materials.Length + 1]; for (int i = 0; i < temp.Length - 1; i++) { temp[i] = skinnedMRenderer.materials[i]; } temp[temp.Length - 1] = glowMaterial; glowMaterial.SetFloat("_Outline", skinnedMRenderer.GetComponent <InteractingController>().glowValue); skinnedMRenderer.materials = temp; }
void ModelChange(string _name) { if (!string.IsNullOrEmpty(_name)) { print("ModelChange : " + _name); curModelName = Path.GetFileNameWithoutExtension(_name); var loaded = Resources.Load <GameObject>(_name); Destroy(obj); obj = Instantiate(loaded) as GameObject; SM = obj.GetComponentInChildren(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer; SM.quality = SkinQuality.Bone4; SM.updateWhenOffscreen = true; viewCam.ModelTarget(GetBone(obj, boneName)); int i = 0; foreach (Material mat in SM.GetComponent <Renderer>().sharedMaterials) { if (mat.name == facialMatName + "_m") { SM.GetComponent <Renderer>().materials[i] = faceMat_M; } else if (mat.name == facialMatName + "_l") { SM.GetComponent <Renderer>().materials[i] = faceMat_L; } i++; } foreach (AnimationState anim in animTest.GetComponent <Animation>()) { obj.GetComponent <Animation>().AddClip(anim.clip, anim.name); } //this.facialMaterialSet(); this.SetAnimation("" + animationList[curAnim]); this.SetAnimationSpeed(animSpeed); } }
void Update() { if (anti_stealth) { if (dt2 < fadeTime2) { dt2 += Time.deltaTime; smr.GetComponent <Renderer>().material.SetFloat("_Dt2", dt2); } else { MonoBehaviour.Destroy(this); } } else { if (dt1 < fadeTime1) { dt1 += Time.deltaTime; smr.GetComponent <Renderer>().material.SetFloat("_Dt1", dt1); } } }
public override void Capture() { if (m_target == null) { return; } if (m_mesh == null) { m_mesh = new Mesh(); } m_target.BakeMesh(m_mesh); CaptureMesh(m_abc, m_mesh, m_target.GetComponent <Cloth>(), m_mesh_buffer); }
//tsubaki @ https://gist.github.com/tsubaki/ea6ece1cd9a851ff977e#file-skinnedmeshupdater-cs public void UpdateMeshRenderer(int lod) { // update mesh SkinnedMeshRenderer meshrenderer = skinnedMeshRenderer.GetComponent <SkinnedMeshRenderer>(); meshrenderer.sharedMesh = skinnedMeshRenderers[lod].sharedMesh; if (updateMaterial) { meshrenderer.sharedMaterial = skinnedMeshRenderers[lod].sharedMaterial; } // update bones meshrenderer.bones = newSkeleton_LOD[lod].bones; }
public SkinnedMeshCapturer(ComponentCapturer parent, SkinnedMeshRenderer target) : base(parent) { m_obj = target.gameObject; m_abc = AbcAPI.aeNewPolyMesh(parent.abc, target.name); m_target = target; m_mesh_buffer = new MeshBuffer(); if (m_target.GetComponent <Cloth>() != null) { var t = m_parent as TransformCapturer; if (t != null) { t.scale = false; } } }
rthsMeshInstanceData GetMeshInstanceData(SkinnedMeshRenderer smr) { var rec = GetInstanceRecord(smr); // bake is needed if there is Cloth, or skinned or has blendshapes and GPU skinning is disabled var cloth = smr.GetComponent <Cloth>(); bool requireBake = cloth != null || (!m_GPUSkinning && (smr.rootBone != null || smr.sharedMesh.blendShapeCount != 0)); if (requireBake) { rec.Update(GetBakedMeshData(smr), smr, m_useObjectShadowSettings, false); } else { rec.Update(GetMeshData(smr.sharedMesh), smr, m_useObjectShadowSettings, true); } return(rec.instData); }
void SetFacialTex(int _i) { string file = resourcesPath + "Textures/" + facialTexList[_i] + lodList[curLOD]; string matName = facialMatName + lodList[curLOD] + " (Instance)"; Texture2D tex = Resources.Load <Texture2D>(file); curFacialName = facialTexList[_i]; foreach (Material mat in faceSM.GetComponent <Renderer>().sharedMaterials) { if (mat) { if (mat.name == matName) { mat.SetTexture("_MainTex", tex); } } } }
public static void CaptureMesh( usdi.Mesh usd, ref usdi.MeshData data, MeshBuffer buf, SkinnedMeshRenderer smr, MeshCaptureFlags flags, bool captureBones) { Cloth cloth = smr.GetComponent <Cloth>(); if (cloth != null) { var mesh = buf.bakedMesh; smr.BakeMesh(mesh); buf.vertices = flags.points ? cloth.vertices : null; buf.normals = flags.normals ? cloth.normals : null; buf.tangents = flags.tangents ? mesh.tangents : null; buf.indices = flags.indices ? mesh.triangles : null; buf.uvs = flags.uvs ? mesh.uv : null; } else if (captureBones && buf.bones != null) { var mesh = smr.sharedMesh; buf.vertices = flags.points ? mesh.vertices : null; buf.normals = flags.normals ? mesh.normals : null; buf.tangents = flags.tangents ? mesh.tangents : null; buf.indices = flags.indices ? mesh.triangles : null; buf.uvs = flags.uvs ? mesh.uv : null; buf.weights = mesh.boneWeights; buf.bindposes = mesh.bindposes; } else { var mesh = buf.bakedMesh; smr.BakeMesh(mesh); buf.vertices = flags.points ? mesh.vertices : null; buf.normals = flags.normals ? mesh.normals : null; buf.tangents = flags.tangents ? mesh.tangents : null; buf.indices = flags.indices ? mesh.triangles : null; buf.uvs = flags.uvs ? mesh.uv : null; } CaptureMesh(usd, ref data, buf); }
public void Transfer() { if (remap) { mapper.Save(); remap = false; } Mesh sharedMesh = clone.GetComponent <SkinnedMeshRenderer>().sharedMesh; if (sharedMesh == source.sharedMesh) { Debug.Log("please use clone!"); return; } sharedMesh.triangles = new int[0]; Vector3[] vertices = (Vector3[])target.mesh.vertices.Clone(); for (int i = 0; i < vertices.Length; i++) { vertices[i] = target.transform.TransformPoint(vertices[i]); } sharedMesh.vertices = vertices; sharedMesh.triangles = (int[])target.mesh.triangles.Clone(); sharedMesh.RecalculateNormals(); sharedMesh.RecalculateBounds(); sharedMesh.RecalculateTangents(); BoneWeight[] newBoneWeights = new BoneWeight[sharedMesh.vertexCount]; if (sharedMesh.vertexCount != mapper.mapping.Length) { Debug.Log("please generate mapping!"); return; } //Vector3[] positions = (Vector3[])source.GetComponent<SkinnedMeshRenderer>().sharedMesh.vertices.Clone(); BoneWeight[] boneWeights = (BoneWeight[])source.GetComponent <SkinnedMeshRenderer>().sharedMesh.boneWeights.Clone(); for (int i = 0; i < sharedMesh.vertices.Length; i++) { newBoneWeights[i] = boneWeights[mapper.mapping[i]]; } sharedMesh.boneWeights = newBoneWeights; sharedMesh.RecalculateNormals(); }
void Shoot() { RaycastHit hitInfo; var ray = m_Camera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hitInfo)) { // Debug.Log(hitInfo.transform.name); SkinnedMeshRenderer ski = hitInfo.transform.GetComponent <SkinnedMeshRenderer>(); if (ski == null) { return; } // for (int i = 0; i < ski.Length; i++) // { DecalSet decalset = ski.GetComponent <DecalSet>(); decalset.AddDecal(transform, hitInfo.point, decalMaterial, m_Size, Random.Range(0, 360), m_NormalFactor, m_Offset); // } } }
void SetLayer(string filePath) { GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(filePath, typeof(GameObject)); if (prefab != null) { int index = LayerMask.NameToLayer(m_LayerName[m_layerIndex]); //获取材质,修改材质的shader Shader sd = Shader.Find("Custom/CharacterLightingSurface"); Transform transform = prefab.transform; if (index == -1) { Debug.Log("名字为" + m_LayerName[m_layerIndex] + "的Layer没有找到"); } else { transform.gameObject.layer = index; foreach (Transform child in transform) { //if (index == -1) //{ // Debug.Log("名字为" + m_LayerName[m_layerIndex] + "的Layer没有找到"); //} //else //{ //修改Layer child.gameObject.layer = index; SkinnedMeshRenderer smr = child.GetComponent <SkinnedMeshRenderer>(); if (smr != null) { //Debug.Log(LayerMask.NameToLayer("aaaa")); smr.GetComponent <Renderer>().sharedMaterial.shader = sd; AssetDatabase.SaveAssets(); } //} } } } }
public override void Capture(double t) // called from main thread { base.Capture(t); if (m_target == null) { return; } if (m_captureEveryFrame || m_count == 0) { if (m_mesh == null) { m_mesh = new Mesh(); } m_target.BakeMesh(m_mesh); bool captureUV = m_captureUVs && (m_count == 0 || m_captureEveryFrameUV); bool captureIndices = m_count == 0 || m_captureEveryFrameIndices; CaptureMesh(m_mesh, m_target.GetComponent <Cloth>(), m_mesh_buffer, ref m_data, t, m_captureNormals, captureUV, captureIndices); } }
bool CaptureSkinnedMeshRenderer(ref MeshData dst, SkinnedMeshRenderer smr, GetMessage mes, ref Mesh mesh) { mesh = smr.sharedMesh; if (mesh == null) { return(false); } if (!mes.bakeSkin && !mesh.isReadable) { Debug.LogWarning("Mesh " + smr.name + " is not readable and be ignored"); return(false); } Cloth cloth = smr.GetComponent <Cloth>(); if (cloth != null && mes.bakeCloth) { CaptureMesh(ref dst, mesh, cloth, mes.flags, smr.sharedMaterials); } if (mes.bakeSkin) { var tmp = new Mesh(); smr.BakeMesh(tmp); CaptureMesh(ref dst, tmp, null, mes.flags, smr.sharedMaterials); } else { CaptureMesh(ref dst, mesh, null, mes.flags, smr.sharedMaterials); if (mes.flags.getBones) { dst.SetBonePaths(smr.bones); dst.bindposes = mesh.bindposes; dst.boneWeights = mesh.boneWeights; } } return(true); }
void Start() { SkinnedMeshRenderer targetRenderer = Character.GetComponent <SkinnedMeshRenderer>(); Dictionary <string, Transform> boneMap = new Dictionary <string, Transform>(); foreach (Transform bone in targetRenderer.bones) { boneMap[bone.name] = bone; } SkinnedMeshRenderer thisRenderer = GetComponent <SkinnedMeshRenderer>(); Transform[] boneArray = thisRenderer.bones; for (int idx = 0; idx < boneArray.Length; ++idx) { string boneName = boneArray[idx].name; if (false == boneMap.TryGetValue(boneName, out boneArray[idx])) { } } thisRenderer.bones = boneArray; }