public void bake( Transform ownerTransform, Transform targetTransform, Track ownerTrack, Track targetTrack, Ipo influenceIpo) { TrackWrapper ownerWrapperTrack = ownerTrack != null ? new TrackWrapper(ownerTrack) : null; TrackWrapper targetWrapperTrack = targetTrack != null ? new TrackWrapper(targetTrack) : null; // uruchamiamy bake dla transformat zalenie od tego, ktre argumenty s nullami, a ktre - nie this.bake(ownerTransform, targetTransform, influenceIpo.calculateValue(0)); if (ownerWrapperTrack != null) { float[] ownerTimes = ownerWrapperTrack.getTimes(); Vector3f[] translations = ownerWrapperTrack.getTranslations(); Quaternion[] rotations = ownerWrapperTrack.getRotations(); Vector3f[] scales = ownerWrapperTrack.getScales(); float[] targetTimes = targetWrapperTrack == null ? null : targetWrapperTrack.getTimes(); Vector3f[] targetTranslations = targetWrapperTrack == null ? null : targetWrapperTrack.getTranslations(); Quaternion[] targetRotations = targetWrapperTrack == null ? null : targetWrapperTrack.getRotations(); Vector3f[] targetScales = targetWrapperTrack == null ? null : targetWrapperTrack.getScales(); Vector3f translation = new Vector3f(), scale = new Vector3f(); Quaternion rotation = new Quaternion(); Transform ownerTemp = new Transform(), targetTemp = new Transform(); for (int i = 0; i < ownerTimes.length; ++i) { float t = ownerTimes[i]; ownerTemp.setTranslation(translations[i]); ownerTemp.setRotation(rotations[i]); ownerTemp.setScale(scales[i]); if (targetWrapperTrack == null) { this.bake(ownerTemp, targetTransform, influenceIpo.calculateValue(i)); } else { // getting the values that are the interpolation of the target track for the time 't' this.interpolate(targetTranslations, targetTimes, t, translation); this.interpolate(targetRotations, targetTimes, t, rotation); this.interpolate(targetScales, targetTimes, t, scale); targetTemp.setTranslation(translation); targetTemp.setRotation(rotation); targetTemp.setScale(scale); this.bake(ownerTemp, targetTemp, influenceIpo.calculateValue(i)); } // need to clone here because each of the arrays will reference the same instance if they // hold the same value in the compact array translations[i] = ownerTemp.getTranslation().clone(); rotations[i] = ownerTemp.getRotation().clone(); scales[i] = ownerTemp.getScale().clone(); } ownerWrapperTrack.setKeyframes(ownerTimes, translations, rotations, scales); } }
/** This method computes the pose transform for the bone. */ @SuppressWarnings("unchecked") private void computePoseTransform() { DynamicArray<Number> loc = (DynamicArray<Number>) poseChannel.getFieldValue("loc"); DynamicArray<Number> size = (DynamicArray<Number>) poseChannel.getFieldValue("size"); DynamicArray<Number> quat = (DynamicArray<Number>) poseChannel.getFieldValue("quat"); if (fixUpAxis) { poseTransform.setTranslation( loc.get(0).floatValue(), -loc.get(2).floatValue(), loc.get(1).floatValue()); poseTransform.setRotation( new Quaternion( quat.get(1).floatValue(), quat.get(3).floatValue(), -quat.get(2).floatValue(), quat.get(0).floatValue())); poseTransform.setScale( size.get(0).floatValue(), size.get(2).floatValue(), size.get(1).floatValue()); } else { poseTransform.setTranslation( loc.get(0).floatValue(), loc.get(1).floatValue(), loc.get(2).floatValue()); poseTransform.setRotation( new Quaternion( quat.get(0).floatValue(), quat.get(1).floatValue(), quat.get(2).floatValue(), quat.get(3).floatValue())); poseTransform.setScale( size.get(0).floatValue(), size.get(1).floatValue(), size.get(2).floatValue()); } Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation()); localTransform.setScale(bone.getLocalScale()); localTransform.getTranslation().addLocal(poseTransform.getTranslation()); localTransform.getRotation().multLocal(poseTransform.getRotation()); localTransform.getScale().multLocal(poseTransform.getScale()); poseTransform.set(localTransform); }
private static Transform convertPositions(FloatBuffer input, BoundingBox bbox, Buffer output) { if (output.capacity() < input.capacity()) throw new RuntimeException("Output must be at least as large as input!"); Vector3f offset = bbox.getCenter().negate(); Vector3f size = new Vector3f(bbox.getXExtent(), bbox.getYExtent(), bbox.getZExtent()); size.multLocal(2); ShortBuffer sb = null; ByteBuffer bb = null; float dataTypeSize; float dataTypeOffset; if (output instanceof ShortBuffer) { sb = (ShortBuffer) output; dataTypeOffset = shortOff; dataTypeSize = shortSize; } else { bb = (ByteBuffer) output; dataTypeOffset = byteOff; dataTypeSize = byteSize; } Vector3f scale = new Vector3f(); scale.set(dataTypeSize, dataTypeSize, dataTypeSize).divideLocal(size); Vector3f invScale = new Vector3f(); invScale.set(size).divideLocal(dataTypeSize); offset.multLocal(scale); offset.addLocal(dataTypeOffset, dataTypeOffset, dataTypeOffset); // offset = (-modelOffset * shortSize)/modelSize + shortOff // scale = shortSize / modelSize input.clear(); output.clear(); Vector3f temp = new Vector3f(); int vertexCount = input.capacity() / 3; for (int i = 0; i < vertexCount; i++) { BufferUtils.populateFromBuffer(temp, input, i); // offset and scale vector into -32768 ... 32767 // or into -128 ... 127 if using bytes temp.multLocal(scale); temp.addLocal(offset); // quantize and store if (sb != null) { short v1 = (short) temp.getX(); short v2 = (short) temp.getY(); short v3 = (short) temp.getZ(); sb.put(v1).put(v2).put(v3); } else { byte v1 = (byte) temp.getX(); byte v2 = (byte) temp.getY(); byte v3 = (byte) temp.getZ(); bb.put(v1).put(v2).put(v3); } } Transform transform = new Transform(); transform.setTranslation(offset.negate().multLocal(invScale)); transform.setScale(invScale); return transform; }
@AttributeName("trns") private void loadTranslation(Vector3f translation) { Transform transform = spatial.getLocalTransform(); transform.setTranslation(translation); }