/// <summary> /// Create VGO_PS_ShapeModule from ShapeModule. /// </summary> /// <param name="module"></param> /// <param name="gltf"></param> /// <returns></returns> /// <remarks> /// @notice TextureIO.ExportTexture() may export the same texture multiple times. /// </remarks> protected virtual VGO_PS_ShapeModule CreateVgoModule(ShapeModule module, glTF gltf) { var vgoShapeModule = new VGO_PS_ShapeModule() { enabled = module.enabled, shapeType = module.shapeType, angle = module.angle, radius = module.radius, donutRadius = module.donutRadius, radiusMode = module.radiusMode, radiusSpread = module.radiusSpread, radiusSpeed = VgoParticleSystemMinMaxCurveConverter.CreateFrom(module.radiusSpeed), radiusSpeedMultiplier = module.radiusSpeedMultiplier, radiusThickness = module.radiusThickness, boxThickness = module.boxThickness.ReverseZ().ToArray(), arc = module.arc, arcMode = module.arcMode, arcSpread = module.arcSpread, arcSpeed = VgoParticleSystemMinMaxCurveConverter.CreateFrom(module.arcSpeed), arcSpeedMultiplier = module.arcSpeedMultiplier, length = module.length, meshShapeType = module.meshShapeType, meshSpawnMode = module.meshSpawnMode, meshSpawnSpread = module.meshSpawnSpread, meshSpawnSpeed = VgoParticleSystemMinMaxCurveConverter.CreateFrom(module.meshSpawnSpread), meshSpawnSpeedMultiplier = module.meshSpawnSpeedMultiplier, //mesh //meshRenderer //skinnedMeshRenderer useMeshMaterialIndex = module.useMeshMaterialIndex, meshMaterialIndex = module.meshMaterialIndex, useMeshColors = module.useMeshColors, //sprite //spriteRenderer normalOffset = module.normalOffset, textureIndex = -1, textureClipChannel = module.textureClipChannel, textureClipThreshold = module.textureClipThreshold, textureColorAffectsParticles = module.textureColorAffectsParticles, textureAlphaAffectsParticles = module.textureAlphaAffectsParticles, textureBilinearFiltering = module.textureBilinearFiltering, textureUVChannel = module.textureUVChannel, position = module.position.ReverseZ().ToArray(), rotation = module.rotation.ReverseZ().ToArray(), scale = module.scale.ToArray(), alignToDirection = module.alignToDirection, randomPositionAmount = module.randomPositionAmount, sphericalDirectionAmount = module.sphericalDirectionAmount, randomDirectionAmount = module.randomDirectionAmount, }; if (module.texture != null) { vgoShapeModule.textureIndex = TextureIO.ExportTexture(gltf, gltf.buffers.Count - 1, module.texture, glTFTextureTypes.Unknown); } return(vgoShapeModule); }
protected Texture initializeTexture(DrawContext dc) { // The frame buffer can be used only during pre-rendering. if (!dc.isPreRenderMode()) { return(null); } // Bind actually binds the source texture only if the image source is available, otherwise it initiates image // source retrieval. If bind returns false, the image source is not yet available. if (this.sourceTexture == null || !this.sourceTexture.bind(dc)) { return(null); } // Ensure that the source texture size is available so that the FBO can be sized to match the source image. if (this.sourceTexture.getWidth(dc) < 1 || this.sourceTexture.getHeight(dc) < 1) { return(null); } int potSourceWidth = WWMath.powerOfTwoCeiling(this.sourceTexture.getWidth(dc)); int potSourceHeight = WWMath.powerOfTwoCeiling(this.sourceTexture.getHeight(dc)); this.width = Math.Min(potSourceWidth, dc.getView().getViewport().width); this.height = Math.Min(potSourceHeight, dc.getView().getViewport().height); if (!this.generateTexture(dc, this.width, this.height)) { return(null); } GL gl = dc.getGL(); TextureData td = new TextureData(gl.getGLProfile(), GL.GL_RGBA, this.width, this.height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, false, null, null); Texture t = TextureIO.newTexture(td); t.bind(gl); // must do this after generating texture because another texture is bound then gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); gl.glCopyTexImage2D(GL.GL_TEXTURE_2D, 0, td.getInternalFormat(), 0, 0, td.getWidth(), td.getHeight(), td.getBorder()); dc.getTextureCache().put(this, t); return(t); }
/** * See {@link GLEventListener#init(GLAutoDrawable)}. * * @param glAutoDrawable the drawable */ public void init(GLAutoDrawable glAutoDrawable) { if (!this.isGLContextCompatible(glAutoDrawable.getContext())) { String msg = Logging.getMessage("WorldWindowGLAutoDrawable.IncompatibleGLContext", glAutoDrawable.getContext()); this.callRenderingExceptionListeners(new WWAbsentRequirementException(msg)); } foreach (String funcName in this.getRequiredOglFunctions()) { if (!glAutoDrawable.getGL().isFunctionAvailable(funcName)) { //noinspection ThrowableInstanceNeverThrown this.callRenderingExceptionListeners(new WWAbsentRequirementException(funcName + " not available")); } } foreach (String extName in this.getRequiredOglExtensions()) { if (!glAutoDrawable.getGL().isExtensionAvailable(extName)) { //noinspection ThrowableInstanceNeverThrown this.callRenderingExceptionListeners(new WWAbsentRequirementException(extName + " not available")); } } if (this.firstInit) { this.firstInit = false; } else if (this.enableGpuCacheReinitialization) { this.reinitialize(glAutoDrawable); } // Disables use of the OpenGL extension GL_ARB_texture_rectangle by JOGL's Texture creation utility. // // Between version 1.1.1 and version 2.x, JOGL modified its texture creation utility to favor // GL_ARB_texture_rectangle over GL_ARB_texture_non_power_of_two on Mac OS X machines with ATI graphics cards. See // the following URL for details on the texture rectangle extension: http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt // // There are two problems with favoring texture rectangle for non power of two textures: // 1) As of November 2012, we cannot find any evidence that the GL_ARB_texture_non_power_of_two extension is // problematic on Mac OS X machines with ATI graphics cards. The texture rectangle extension is more limiting // than the NPOT extension, and therefore not preferred. // 2) World Wind assumes that a texture's target is always GL_TEXTURE_2D, and therefore incorrectly displays // textures with the target GL_TEXTURE_RECTANGLE. TextureIO.setTexRectEnabled(false); // this.drawable.setGL(new DebugGL(this.drawable.getGL())); // uncomment to use the debug drawable }
/** * Creates a {@link Texture} from this instance's {@link TextureData} if the <code>TextureData</code> exists. * * @param dc the current draw context. * * @return the newly created texture, or null if this instance has no current <code>TextureData</code> or if texture * creation failed. */ protected Texture makeTextureFromTextureData(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (this.getTextureData() == null) // texture not in cache yet texture data is null, can't initialize { String msg = Logging.getMessage("nullValue.TextureDataIsNull"); Logging.logger().severe(msg); throw new IllegalStateException(msg); } try { Texture texture = TextureIO.newTexture(this.getTextureData()); if (texture == null) { this.textureInitializationFailed = true; return(null); } this.width = texture.getWidth(); this.height = texture.getHeight(); this.texCoords = texture.getImageTexCoords(); this.setTextureParameters(dc, texture); // Cache the texture and release the texture data. dc.getTextureCache().put(this.getImageSource(), texture); this.setTextureData(null); return(texture); } catch (Exception e) { String name = this.isBufferedImageSource() ? "BufferedImage" : this.getImageSource().ToString(); String msg = Logging.getMessage("generic.ExceptionAttemptingToCreateTexture", name); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); return(null); } }
public static void _Export(glTF gltf, VRMExporter exporter, GameObject go) { exporter.Prepare(go); exporter.Export(); // avatar var animator = go.GetComponent <Animator>(); if (animator != null) { var humanoid = go.GetComponent <VRMHumanoidDescription>(); UniHumanoid.AvatarDescription description = null; var nodes = go.transform.Traverse().Skip(1).ToList(); { var isCreated = false; if (humanoid != null) { description = humanoid.GetDescription(out isCreated); } if (description != null) { // use description gltf.extensions.VRM.humanoid.Apply(description, nodes); } if (isCreated) { GameObject.DestroyImmediate(description); } } { // set humanoid bone mapping var avatar = animator.avatar; foreach (HumanBodyBones key in Enum.GetValues(typeof(HumanBodyBones))) { if (key == HumanBodyBones.LastBone) { break; } var transform = animator.GetBoneTransform(key); if (transform != null) { gltf.extensions.VRM.humanoid.SetNodeIndex(key, nodes.IndexOf(transform)); } } } } // morph var master = go.GetComponent <VRMBlendShapeProxy>(); if (master != null) { var avatar = master.BlendShapeAvatar; if (avatar != null) { var meshes = exporter.Meshes; foreach (var x in avatar.Clips) { gltf.extensions.VRM.blendShapeMaster.Add(x, exporter.Copy.transform, meshes); } } } // secondary VRMSpringUtility.ExportSecondary(exporter.Copy.transform, exporter.Nodes, x => gltf.extensions.VRM.secondaryAnimation.colliderGroups.Add(x), x => gltf.extensions.VRM.secondaryAnimation.boneGroups.Add(x) ); // meta(obsolete) { var meta = exporter.Copy.GetComponent <VRMMetaInformation>(); if (meta != null) { gltf.extensions.VRM.meta.author = meta.Author; gltf.extensions.VRM.meta.contactInformation = meta.ContactInformation; gltf.extensions.VRM.meta.title = meta.Title; if (meta.Thumbnail != null) { gltf.extensions.VRM.meta.texture = TextureIO.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail, false); } gltf.extensions.VRM.meta.licenseType = meta.LicenseType; gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; gltf.extensions.VRM.meta.reference = meta.Reference; } } // meta { var _meta = exporter.Copy.GetComponent <VRMMeta>(); if (_meta != null && _meta.Meta != null) { var meta = _meta.Meta; // info gltf.extensions.VRM.meta.version = meta.Version; gltf.extensions.VRM.meta.author = meta.Author; gltf.extensions.VRM.meta.contactInformation = meta.ContactInformation; gltf.extensions.VRM.meta.reference = meta.Reference; gltf.extensions.VRM.meta.title = meta.Title; if (meta.Thumbnail != null) { gltf.extensions.VRM.meta.texture = TextureIO.ExportTexture(gltf, gltf.buffers.Count - 1, meta.Thumbnail, false); } // ussage pemission gltf.extensions.VRM.meta.allowedUser = meta.AllowedUser; gltf.extensions.VRM.meta.violentUssage = meta.ViolentUssage; gltf.extensions.VRM.meta.sexualUssage = meta.SexualUssage; gltf.extensions.VRM.meta.commercialUssage = meta.CommercialUssage; gltf.extensions.VRM.meta.otherPermissionUrl = meta.OtherPermissionUrl; // distribution license gltf.extensions.VRM.meta.licenseType = meta.LicenseType; if (meta.LicenseType == LicenseType.Other) { gltf.extensions.VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; } } } // firstPerson var firstPerson = exporter.Copy.GetComponent <VRMFirstPerson>(); if (firstPerson != null) { if (firstPerson.FirstPersonBone != null) { gltf.extensions.VRM.firstPerson.firstPersonBone = exporter.Nodes.IndexOf(firstPerson.FirstPersonBone); gltf.extensions.VRM.firstPerson.firstPersonBoneOffset = firstPerson.FirstPersonOffset; gltf.extensions.VRM.firstPerson.meshAnnotations = firstPerson.Renderers.Select(x => new glTF_VRM_MeshAnnotation { mesh = exporter.Meshes.IndexOf(x.SharedMesh), firstPersonFlag = x.FirstPersonFlag.ToString(), }).ToList(); } // lookAt { var lookAtHead = exporter.Copy.GetComponent <VRMLookAtHead>(); var lookAt = exporter.Copy.GetComponent <VRMLookAt>(); if (lookAtHead != null) { var boneApplyer = exporter.Copy.GetComponent <VRMLookAtBoneApplyer>(); var blendShapeApplyer = exporter.Copy.GetComponent <VRMLookAtBlendShapeApplyer>(); if (boneApplyer != null) { gltf.extensions.VRM.firstPerson.lookAtType = LookAtType.Bone; gltf.extensions.VRM.firstPerson.lookAtHorizontalInner.Apply(boneApplyer.HorizontalInner); gltf.extensions.VRM.firstPerson.lookAtHorizontalOuter.Apply(boneApplyer.HorizontalOuter); gltf.extensions.VRM.firstPerson.lookAtVerticalDown.Apply(boneApplyer.VerticalDown); gltf.extensions.VRM.firstPerson.lookAtVerticalUp.Apply(boneApplyer.VerticalUp); } else if (blendShapeApplyer != null) { gltf.extensions.VRM.firstPerson.lookAtType = LookAtType.BlendShape; gltf.extensions.VRM.firstPerson.lookAtHorizontalOuter.Apply(blendShapeApplyer.Horizontal); gltf.extensions.VRM.firstPerson.lookAtVerticalDown.Apply(blendShapeApplyer.VerticalDown); gltf.extensions.VRM.firstPerson.lookAtVerticalUp.Apply(blendShapeApplyer.VerticalUp); } } else if (lookAt != null) { gltf.extensions.VRM.firstPerson.lookAtHorizontalInner.Apply(lookAt.HorizontalInner); gltf.extensions.VRM.firstPerson.lookAtHorizontalOuter.Apply(lookAt.HorizontalOuter); gltf.extensions.VRM.firstPerson.lookAtVerticalDown.Apply(lookAt.VerticalDown); gltf.extensions.VRM.firstPerson.lookAtVerticalUp.Apply(lookAt.VerticalUp); } } } // materials foreach (var m in exporter.Materials) { gltf.extensions.VRM.materialProperties.Add(glTF_VRM_Material.CreateFromMaterial(m, exporter.Textures)); } }
public override void Export(MeshExportSettings configuration) { base.Export(configuration); // avatar var animator = Copy.GetComponent <Animator>(); if (animator != null) { var humanoid = Copy.GetComponent <VRMHumanoidDescription>(); UniHumanoid.AvatarDescription description = null; var nodes = Copy.transform.Traverse().Skip(1).ToList(); { var isCreated = false; if (humanoid != null) { description = humanoid.GetDescription(out isCreated); } if (description != null) { // use description VRM.humanoid.Apply(description, nodes); } if (isCreated) { GameObject.DestroyImmediate(description); } } { // set humanoid bone mapping var avatar = animator.avatar; foreach (HumanBodyBones key in Enum.GetValues(typeof(HumanBodyBones))) { if (key == HumanBodyBones.LastBone) { break; } var transform = animator.GetBoneTransform(key); if (transform != null) { VRM.humanoid.SetNodeIndex(key, nodes.IndexOf(transform)); } } } } // morph var master = Copy.GetComponent <VRMBlendShapeProxy>(); if (master != null) { var avatar = master.BlendShapeAvatar; if (avatar != null) { foreach (var x in avatar.Clips) { VRM.blendShapeMaster.Add(x, this); } } } // secondary VRMSpringUtility.ExportSecondary(Copy.transform, Nodes, x => VRM.secondaryAnimation.colliderGroups.Add(x), x => VRM.secondaryAnimation.boneGroups.Add(x) ); #pragma warning disable 0618 // meta(obsolete) { var meta = Copy.GetComponent <VRMMetaInformation>(); if (meta != null) { VRM.meta.author = meta.Author; VRM.meta.contactInformation = meta.ContactInformation; VRM.meta.title = meta.Title; if (meta.Thumbnail != null) { VRM.meta.texture = TextureIO.ExportTexture(glTF, glTF.buffers.Count - 1, meta.Thumbnail, glTFTextureTypes.Unknown); } VRM.meta.licenseType = meta.LicenseType; VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; VRM.meta.reference = meta.Reference; } } #pragma warning restore 0618 // meta { var _meta = Copy.GetComponent <VRMMeta>(); if (_meta != null && _meta.Meta != null) { var meta = _meta.Meta; // info VRM.meta.version = meta.Version; VRM.meta.author = meta.Author; VRM.meta.contactInformation = meta.ContactInformation; VRM.meta.reference = meta.Reference; VRM.meta.title = meta.Title; if (meta.Thumbnail != null) { VRM.meta.texture = TextureIO.ExportTexture(glTF, glTF.buffers.Count - 1, meta.Thumbnail, glTFTextureTypes.Unknown); } // ussage permission VRM.meta.allowedUser = meta.AllowedUser; VRM.meta.violentUssage = meta.ViolentUssage; VRM.meta.sexualUssage = meta.SexualUssage; VRM.meta.commercialUssage = meta.CommercialUssage; VRM.meta.otherPermissionUrl = meta.OtherPermissionUrl; // distribution license VRM.meta.licenseType = meta.LicenseType; if (meta.LicenseType == LicenseType.Other) { VRM.meta.otherLicenseUrl = meta.OtherLicenseUrl; } } } // firstPerson var firstPerson = Copy.GetComponent <VRMFirstPerson>(); if (firstPerson != null) { if (firstPerson.FirstPersonBone != null) { VRM.firstPerson.firstPersonBone = Nodes.IndexOf(firstPerson.FirstPersonBone); VRM.firstPerson.firstPersonBoneOffset = firstPerson.FirstPersonOffset; VRM.firstPerson.meshAnnotations = firstPerson.Renderers.Select(x => new glTF_VRM_MeshAnnotation { mesh = Meshes.IndexOf(x.SharedMesh), firstPersonFlag = x.FirstPersonFlag.ToString(), }).ToList(); } // lookAt { var lookAtHead = Copy.GetComponent <VRMLookAtHead>(); if (lookAtHead != null) { var boneApplyer = Copy.GetComponent <VRMLookAtBoneApplyer>(); var blendShapeApplyer = Copy.GetComponent <VRMLookAtBlendShapeApplyer>(); if (boneApplyer != null) { VRM.firstPerson.lookAtType = LookAtType.Bone; VRM.firstPerson.lookAtHorizontalInner.Apply(boneApplyer.HorizontalInner); VRM.firstPerson.lookAtHorizontalOuter.Apply(boneApplyer.HorizontalOuter); VRM.firstPerson.lookAtVerticalDown.Apply(boneApplyer.VerticalDown); VRM.firstPerson.lookAtVerticalUp.Apply(boneApplyer.VerticalUp); } else if (blendShapeApplyer != null) { VRM.firstPerson.lookAtType = LookAtType.BlendShape; VRM.firstPerson.lookAtHorizontalOuter.Apply(blendShapeApplyer.Horizontal); VRM.firstPerson.lookAtVerticalDown.Apply(blendShapeApplyer.VerticalDown); VRM.firstPerson.lookAtVerticalUp.Apply(blendShapeApplyer.VerticalUp); } } } } // materials foreach (var m in Materials) { VRM.materialProperties.Add(VRMMaterialExporter.CreateFromMaterial(m, TextureManager.Textures)); } // Serialize VRM var f = new JsonFormatter(); VRMSerializer.Serialize(f, VRM); var bytes = f.GetStoreBytes(); glTFExtensionExport.GetOrCreate(ref glTF.extensions).Add("VRM", bytes); }
public override void Export() { base.Export(); var gltf = GLTF; var exporter = this; var go = Copy; //exporter.Prepare(go); //exporter.Export(); gltf.extensions.VCAST_vci_material_unity = new glTF_VCAST_vci_material_unity { materials = exporter.Materials .Select(m => glTF_VCI_Material.CreateFromMaterial(m, exporter.TextureManager.Textures)) .ToList() }; if (Copy == null) { return; } // vci interaction var vciObject = Copy.GetComponent <VCIObject>(); if (vciObject != null) { // script if (vciObject.Scripts.Any()) { gltf.extensions.VCAST_vci_embedded_script = new glTF_VCAST_vci_embedded_script { scripts = vciObject.Scripts.Select(x => { int viewIndex = -1; #if UNITY_EDITOR if (!string.IsNullOrEmpty(x.filePath)) { if (File.Exists(x.filePath)) { using (var resader = new StreamReader(x.filePath)) { string scriptStr = resader.ReadToEnd(); viewIndex = gltf.ExtendBufferAndGetViewIndex <byte>(0, Utf8String.Encoding.GetBytes(scriptStr)); } } else { Debug.LogError("script file not found. スクリプトファイルが見つかりませんでした: " + x.filePath); throw new FileNotFoundException(x.filePath); } } else #endif { viewIndex = gltf.ExtendBufferAndGetViewIndex <byte>(0, Utf8String.Encoding.GetBytes(x.source)); } return(new glTF_VCAST_vci_embedded_script_source { name = x.name, mimeType = x.mimeType, targetEngine = x.targetEngine, source = viewIndex, }); }) .ToList() } } ; var springBones = Copy.GetComponents <VCISpringBone>(); if (springBones.Length > 0) { var sbg = new glTF_VCAST_vci_spring_bone(); sbg.springBones = new List <glTF_VCAST_vci_SpringBone>(); gltf.extensions.VCAST_vci_spring_bone = sbg; foreach (var sb in springBones) { sbg.springBones.Add(new glTF_VCAST_vci_SpringBone() { center = Nodes.IndexOf(sb.m_center), dragForce = sb.m_dragForce, gravityDir = sb.m_gravityDir, gravityPower = sb.m_gravityPower, stiffiness = sb.m_stiffnessForce, hitRadius = sb.m_hitRadius, colliderIds = sb.m_colliderObjects .Where(x => x != null) .Select(x => Nodes.IndexOf(x)) .ToArray(), bones = sb.RootBones.Where(x => x != null).Select(x => Nodes.IndexOf(x.transform)).ToArray() }); } } // meta var meta = vciObject.Meta; gltf.extensions.VCAST_vci_meta = new glTF_VCAST_vci_meta { exporterVCIVersion = VCIVersion.VCI_VERSION, specVersion = VCISpecVersion.Version, title = meta.title, version = meta.version, author = meta.author, contactInformation = meta.contactInformation, reference = meta.reference, description = meta.description, modelDataLicenseType = meta.modelDataLicenseType, modelDataOtherLicenseUrl = meta.modelDataOtherLicenseUrl, scriptLicenseType = meta.scriptLicenseType, scriptOtherLicenseUrl = meta.scriptOtherLicenseUrl, scriptWriteProtected = meta.scriptWriteProtected, scriptEnableDebugging = meta.scriptEnableDebugging, scriptFormat = meta.scriptFormat }; if (meta.thumbnail != null) { gltf.extensions.VCAST_vci_meta.thumbnail = TextureIO.ExportTexture( gltf, gltf.buffers.Count - 1, meta.thumbnail, glTFTextureTypes.Unknown); } } // collider & rigidbody & joint & item for (var i = 0; i < exporter.Nodes.Count; i++) { var node = exporter.Nodes[i]; var gltfNode = gltf.nodes[i]; // 各ノードに複数のコライダーがあり得る var colliders = node.GetComponents <Collider>(); if (colliders.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_collider = new glTF_VCAST_vci_colliders(); gltfNode.extensions.VCAST_vci_collider.colliders = new List <glTF_VCAST_vci_Collider>(); foreach (var collider in colliders) { var gltfCollider = glTF_VCAST_vci_Collider.GetglTfColliderFromUnityCollider(collider); if (gltfCollider == null) { Debug.LogWarningFormat("collider is not supported: {0}", collider.GetType().Name); continue; } gltfNode.extensions.VCAST_vci_collider.colliders.Add(gltfCollider); } } var rigidbodies = node.GetComponents <Rigidbody>(); if (rigidbodies.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_rigidbody = new glTF_VCAST_vci_rigidbody(); gltfNode.extensions.VCAST_vci_rigidbody.rigidbodies = new List <glTF_VCAST_vci_Rigidbody>(); foreach (var rigidbody in rigidbodies) { gltfNode.extensions.VCAST_vci_rigidbody.rigidbodies.Add( glTF_VCAST_vci_Rigidbody.GetglTfRigidbodyFromUnityRigidbody(rigidbody)); } } var joints = node.GetComponents <Joint>(); if (joints.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_joints = new glTF_VCAST_vci_joints(); gltfNode.extensions.VCAST_vci_joints.joints = new List <glTF_VCAST_vci_joint>(); foreach (var joint in joints) { gltfNode.extensions.VCAST_vci_joints.joints.Add( glTF_VCAST_vci_joint.GetglTFJointFromUnityJoint(joint, exporter.Nodes)); } } var item = node.GetComponent <VCISubItem>(); if (item != null) { var warning = item.ExportWarning; if (!string.IsNullOrEmpty(warning)) { throw new System.Exception(warning); } if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_item = new glTF_VCAST_vci_item { grabbable = item.Grabbable, scalable = item.Scalable, uniformScaling = item.UniformScaling, groupId = item.GroupId, }; } // Attachable var vciAttachable = node.GetComponent <VCIAttachable>(); if (vciAttachable != null && vciAttachable.AttachableHumanBodyBones != null && vciAttachable.AttachableHumanBodyBones.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_attachable = new glTF_VCAST_vci_attachable { attachableHumanBodyBones = vciAttachable.AttachableHumanBodyBones.Select(x => x.ToString()).ToList(), attachableDistance = vciAttachable.AttachableDistance, }; } // Text var tmp = node.GetComponent <TextMeshPro>(); var rt = node.GetComponent <RectTransform>(); if (tmp != null && rt != null) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_rectTransform = new glTF_VCAST_vci_rectTransform() { rectTransform = glTF_VCAST_vci_RectTransform.CreateFromRectTransform(rt) }; gltfNode.extensions.VCAST_vci_text = new glTF_VCAST_vci_text { text = glTF_VCAST_vci_Text.Create(tmp) }; } } // Audio var clips = exporter.Copy.GetComponentsInChildren <AudioSource>() .Select(x => x.clip) .Where(x => x != null) .ToArray(); if (clips.Any()) { var audios = clips.Select(x => FromAudioClip(gltf, x)).Where(x => x != null).ToList(); gltf.extensions.VCAST_vci_audios = new glTF_VCAST_vci_audios { audios = audios }; } #if UNITY_EDITOR // Animation // None RootAnimation var animators = exporter.Copy.GetComponentsInChildren <Animator>().Where(x => exporter.Copy != x.gameObject); var animations = exporter.Copy.GetComponentsInChildren <Animation>().Where(x => exporter.Copy != x.gameObject); // NodeIndex to AnimationClips Dictionary <int, AnimationClip[]> animationNodeList = new Dictionary <int, AnimationClip[]>(); foreach (var animator in animators) { var animationClips = AnimationExporter.GetAnimationClips(animator); var nodeIndex = exporter.Nodes.FindIndex(0, exporter.Nodes.Count, x => x == animator.transform); if (animationClips.Any() && nodeIndex != -1) { animationNodeList.Add(nodeIndex, animationClips.ToArray()); } } foreach (var animation in animations) { var animationClips = AnimationExporter.GetAnimationClips(animation); var nodeIndex = exporter.Nodes.FindIndex(0, exporter.Nodes.Count, x => x == animation.transform); if (animationClips.Any() && nodeIndex != -1) { animationNodeList.Add(nodeIndex, animationClips.ToArray()); } } int bufferIndex = 0; foreach (var animationNode in animationNodeList) { List <int> clipIndices = new List <int>(); // write animationClips foreach (var clip in animationNode.Value) { var animationWithCurve = AnimationExporter.Export(clip, Nodes[animationNode.Key], Nodes); AnimationExporter.WriteAnimationWithSampleCurves(gltf, animationWithCurve, clip.name, bufferIndex); clipIndices.Add(gltf.animations.IndexOf(animationWithCurve.Animation)); } // write node if (clipIndices.Any()) { var node = gltf.nodes[animationNode.Key]; if (node.extensions == null) { node.extensions = new glTFNode_extensions(); } node.extensions.VCAST_vci_animation = new glTF_VCAST_vci_animation() { animationReferences = new List <glTF_VCAST_vci_animationReference>() }; foreach (var index in clipIndices) { node.extensions.VCAST_vci_animation.animationReferences.Add(new glTF_VCAST_vci_animationReference() { animation = index }); } } } #endif // Effekseer var effekseerEmitters = exporter.Copy.GetComponentsInChildren <Effekseer.EffekseerEmitter>() .Where(x => x.effectAsset != null) .ToArray(); if (effekseerEmitters.Any()) { gltf.extensions.Effekseer = new glTF_Effekseer() { effects = new List <glTF_Effekseer_effect>() }; foreach (var emitter in effekseerEmitters) { var index = exporter.Nodes.FindIndex(x => x == emitter.transform); if (index < 0) { continue; } var effectIndex = AddEffekseerEffect(gltf, emitter); var gltfNode = gltf.nodes[index]; if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } if (gltfNode.extensions.Effekseer_emitters == null) { gltfNode.extensions.Effekseer_emitters = new glTF_Effekseer_emitters() { emitters = new List <glTF_Effekseer_emitter>() }; } gltfNode.extensions.Effekseer_emitters.emitters.Add(new glTF_Effekseer_emitter() { effectIndex = effectIndex, isLoop = emitter.isLooping, isPlayOnStart = emitter.playOnStart }); } } }
protected Texture initializeTexture(DrawContext dc) { // Bind actually binds the source texture only if the image source is available, otherwise it initiates image // source retrieval. If bind returns false, the image source is not yet available. if (this.sourceTexture == null || !this.sourceTexture.bind(dc)) { return(null); } // Ensure that the source texture size is available so that the FBO can be sized to match the source image. if (sourceTexture.getWidth(dc) < 1 || sourceTexture.getHeight(dc) < 1) { return(null); } // Limit FBO size to the max OGL size or 4k, whichever is smaller int maxSize = Math.Min(dc.getGLRuntimeCapabilities().getMaxTextureSize(), 4096); this.width = Math.Min(maxSize, sourceTexture.getWidth(dc)); this.height = Math.Min(maxSize, sourceTexture.getHeight(dc)); GL gl = dc.getGL(); int[] previousFbo = new int[1]; gl.glGetIntegerv(GL.GL_FRAMEBUFFER_BINDING, previousFbo, 0); int[] fbo = new int[1]; gl.glGenFramebuffers(1, fbo, 0); try { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbo[0]); TextureData td = new TextureData(gl.getGLProfile(), GL.GL_RGBA, this.width, this.height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, false, false, true, Buffers.newDirectByteBuffer(this.width * this.height * 4), null); Texture t = TextureIO.newTexture(td); t.bind(gl); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D, t.getTextureObject(gl), 0); int status = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER); if (status == GL.GL_FRAMEBUFFER_COMPLETE) { this.generateTexture(dc, this.width, this.height); } else { String msg = Logging.getMessage("FBOTexture.TextureNotCreated"); throw new IllegalStateException(msg); } dc.getTextureCache().put(this, t); return(t); } finally { gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, previousFbo[0]); gl.glDeleteFramebuffers(1, fbo, 0); } }
public override void Export() { base.Export(); var gltf = GLTF; var exporter = this; var go = Copy; //exporter.Prepare(go); //exporter.Export(); gltf.extensions.VCAST_vci_material_unity = new glTF_VCAST_vci_material_unity { materials = exporter.Materials .Select(m => glTF_VCI_Material.CreateFromMaterial(m, exporter.TextureManager.Textures)) .ToList() }; if (Copy == null) { return; } // vci interaction var vciObject = Copy.GetComponent <VCIObject>(); if (vciObject != null) { // script if (vciObject.Scripts.Any()) { gltf.extensions.VCAST_vci_embedded_script = new glTF_VCAST_vci_embedded_script { scripts = vciObject.Scripts.Select(x => { int viewIndex = -1; #if UNITY_EDITOR if (!string.IsNullOrEmpty(x.filePath)) { if (File.Exists(x.filePath)) { using (var resader = new StreamReader(x.filePath)) { string scriptStr = resader.ReadToEnd(); viewIndex = gltf.ExtendBufferAndGetViewIndex <byte>(0, Utf8String.Encoding.GetBytes(scriptStr)); } } else { Debug.LogError("script file not found. スクリプトファイルが見つかりませんでした: " + x.filePath); throw new FileNotFoundException(x.filePath); } } else #endif { viewIndex = gltf.ExtendBufferAndGetViewIndex <byte>(0, Utf8String.Encoding.GetBytes(x.source)); } return(new glTF_VCAST_vci_embedded_script_source { name = x.name, mimeType = x.mimeType, targetEngine = x.targetEngine, source = viewIndex, }); }) .ToList() } } ; // meta var meta = vciObject.Meta; gltf.extensions.VCAST_vci_meta = new glTF_VCAST_vci_meta { exporterVCIVersion = VCIVersion.VCI_VERSION, specVersion = VCISpecVersion.Version, title = meta.title, version = meta.version, author = meta.author, contactInformation = meta.contactInformation, reference = meta.reference, description = meta.description, modelDataLicenseType = meta.modelDataLicenseType, modelDataOtherLicenseUrl = meta.modelDataOtherLicenseUrl, scriptLicenseType = meta.scriptLicenseType, scriptOtherLicenseUrl = meta.scriptOtherLicenseUrl, scriptWriteProtected = meta.scriptWriteProtected, scriptEnableDebugging = meta.scriptEnableDebugging, scriptFormat = meta.scriptFormat }; if (meta.thumbnail != null) { gltf.extensions.VCAST_vci_meta.thumbnail = TextureIO.ExportTexture( gltf, gltf.buffers.Count - 1, meta.thumbnail, glTFTextureTypes.Unknown); } } // collider & rigidbody & joint & item for (var i = 0; i < exporter.Nodes.Count; i++) { var node = exporter.Nodes[i]; var gltfNode = gltf.nodes[i]; // 各ノードに複数のコライダーがあり得る var colliders = node.GetComponents <Collider>(); if (colliders.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_collider = new glTF_VCAST_vci_colliders(); gltfNode.extensions.VCAST_vci_collider.colliders = new List <glTF_VCAST_vci_Collider>(); foreach (var collider in colliders) { var gltfCollider = glTF_VCAST_vci_Collider.GetglTfColliderFromUnityCollider(collider); if (gltfCollider == null) { Debug.LogWarningFormat("collider is not supported: {0}", collider.GetType().Name); continue; } gltfNode.extensions.VCAST_vci_collider.colliders.Add(gltfCollider); } } var rigidbodies = node.GetComponents <Rigidbody>(); if (rigidbodies.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_rigidbody = new glTF_VCAST_vci_rigidbody(); gltfNode.extensions.VCAST_vci_rigidbody.rigidbodies = new List <glTF_VCAST_vci_Rigidbody>(); foreach (var rigidbody in rigidbodies) { gltfNode.extensions.VCAST_vci_rigidbody.rigidbodies.Add( glTF_VCAST_vci_Rigidbody.GetglTfRigidbodyFromUnityRigidbody(rigidbody)); } } var joints = node.GetComponents <Joint>(); if (joints.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_joints = new glTF_VCAST_vci_joints(); gltfNode.extensions.VCAST_vci_joints.joints = new List <glTF_VCAST_vci_joint>(); foreach (var joint in joints) { gltfNode.extensions.VCAST_vci_joints.joints.Add( glTF_VCAST_vci_joint.GetglTFJointFromUnityJoint(joint, exporter.Nodes)); } } var item = node.GetComponent <VCISubItem>(); if (item != null) { var warning = item.ExportWarning; if (!string.IsNullOrEmpty(warning)) { throw new System.Exception(warning); } if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_item = new glTF_VCAST_vci_item { grabbable = item.Grabbable, scalable = item.Scalable, uniformScaling = item.UniformScaling, groupId = item.GroupId, }; } // Attachable var vciAttachable = node.GetComponent <VCIAttachable>(); if (vciAttachable != null && vciAttachable.AttachableHumanBodyBones != null && vciAttachable.AttachableHumanBodyBones.Any()) { if (gltfNode.extensions == null) { gltfNode.extensions = new glTFNode_extensions(); } gltfNode.extensions.VCAST_vci_attachable = new glTF_VCAST_vci_attachable { attachableHumanBodyBones = vciAttachable.AttachableHumanBodyBones.Select(x => x.ToString()).ToList(), attachableDistance = vciAttachable.AttachableDistance, }; } } var clips = exporter.Copy.GetComponentsInChildren <AudioSource>() .Select(x => x.clip) .Where(x => x != null) .ToArray(); if (clips.Any()) { var audios = clips.Select(x => FromAudioClip(gltf, x)).Where(x => x != null).ToList(); gltf.extensions.VCAST_vci_audios = new glTF_VCAST_vci_audios { audios = audios }; } }
protected Texture initializeTexture(DrawContext dc, Object imageSource) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (this.textureInitializationFailed) { return(null); } Texture t; bool haveMipMapData; GL gl = dc.getGL(); if (imageSource is String) { String path = (String)imageSource; Object streamOrException = WWIO.getFileOrResourceAsStream(path, this.GetType()); if (streamOrException == null || streamOrException is Exception) { Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile", streamOrException != null ? streamOrException : path); this.textureInitializationFailed = true; return(null); } try { TextureData td = OGLUtil.newTextureData(gl.getGLProfile(), (InputStream)streamOrException, this.useMipMaps); t = TextureIO.newTexture(td); haveMipMapData = td.getMipmapData() != null; } catch (Exception e) { String msg = Logging.getMessage("layers.TextureLayer.ExceptionAttemptingToReadTextureFile", imageSource); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); this.textureInitializationFailed = true; return(null); } } else if (imageSource is BufferedImage) { try { TextureData td = AWTTextureIO.newTextureData(gl.getGLProfile(), (BufferedImage)imageSource, this.useMipMaps); t = TextureIO.newTexture(td); haveMipMapData = td.getMipmapData() != null; } catch (Exception e) { String msg = Logging.getMessage("generic.IOExceptionDuringTextureInitialization"); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); this.textureInitializationFailed = true; return(null); } } else if (imageSource is URL) { try { InputStream stream = ((URL)imageSource).openStream(); if (stream == null) { Logging.logger().log(java.util.logging.Level.SEVERE, "generic.ExceptionAttemptingToReadImageFile", imageSource); this.textureInitializationFailed = true; return(null); } TextureData td = OGLUtil.newTextureData(gl.getGLProfile(), stream, this.useMipMaps); t = TextureIO.newTexture(td); haveMipMapData = td.getMipmapData() != null; } catch (Exception e) { String msg = Logging.getMessage("layers.TextureLayer.ExceptionAttemptingToReadTextureFile", imageSource); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); this.textureInitializationFailed = true; return(null); } } else { Logging.logger().log(java.util.logging.Level.SEVERE, "generic.UnrecognizedImageSourceType", imageSource.GetType().Name); this.textureInitializationFailed = true; return(null); } if (t == null) // In case JOGL TextureIO returned null { Logging.logger().log(java.util.logging.Level.SEVERE, "generic.TextureUnreadable", imageSource is String ? imageSource : imageSource.GetType().Name); this.textureInitializationFailed = true; return(null); } // Textures with the same path are assumed to be identical textures, so key the texture id off the // image source. dc.getTextureCache().put(imageSource, t); t.bind(gl); // Enable the appropriate mip-mapping texture filters if the caller has specified that mip-mapping should be // enabled, and the texture itself supports mip-mapping. bool useMipMapFilter = this.useMipMaps && (haveMipMapData || t.isUsingAutoMipmapGeneration()); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, useMipMapFilter ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); if (this.isUseAnisotropy() && useMipMapFilter) { double maxAnisotropy = dc.getGLRuntimeCapabilities().getMaxTextureAnisotropy(); if (dc.getGLRuntimeCapabilities().isUseAnisotropicTextureFilter() && maxAnisotropy >= 2.0) { gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)maxAnisotropy); } } this.width = t.getWidth(); this.height = t.getHeight(); this.texCoords = t.getImageTexCoords(); return(t); }