我加载了一个OBJ多面体,我使用了EdgesGeometry()来提取它的边缘:
FilteredList<myObject> filteredData = new FilteredList<>(data, p -> true);
// 2. Set the filter Predicate whenever the filter changes.
filterField.textProperty().addListener((observable, oldValue, newValue) -> {
filteredData.setPredicate(myObject -> {
// If filter text is empty, display all persons.
if (newValue == null || newValue.isEmpty()) {
return true;
}
// Compare first name and last name field in your object with filter.
String lowerCaseFilter = newValue.toLowerCase();
if (String.valueOf(myObject.getFirstName()).toLowerCase().contains(lowerCaseFilter)) {
return true;
// Filter matches first name.
} else if (String.valueOf(myObject.getLastName()).toLowerCase().contains(lowerCaseFilter)) {
return true; // Filter matches last name.
}
return false; // Does not match.
});
});
// 3. Wrap the FilteredList in a SortedList.
SortedList<myObject> sortedData = new SortedList<>(filteredData);
// 4. Bind the SortedList comparator to the TableView comparator.
sortedData.comparatorProperty().bind(myTable.comparatorProperty());
// 5. Add sorted (and filtered) data to the table.
myTable.setItems(sortedData);
但我想将每个边缘渲染为具有可配置半径的圆柱体。像这样:
答案 0 :(得分:2)
这是@ prisoner849出色答案的一个版本,该答案仅对圆柱体返回合并的BufferGeometry
:
/** Convert an edges geometry to a set of cylinders w/ the given thickness. */
function edgesToCylinders(edgesGeometry, thickness) {
const {position} = edgesGeometry.attributes;
const {array, count} = position;
const r = thickness / 2;
const geoms = [];
for (let i = 0; i < count * 3 - 1; i += 6) {
const a = new THREE.Vector3(array[i], array[i + 1], array[i + 2]);
const b = new THREE.Vector3(array[i + 3], array[i + 4], array[i + 5]);
const vec = new THREE.Vector3().subVectors(b, a);
const len = vec.length();
const geom = new THREE.CylinderBufferGeometry(r, r, len, 8);
geom.translate(0, len / 2, 0);
geom.rotateX(Math.PI / 2);
geom.lookAt(vec);
geom.translate(a.x, a.y, a.z);
geoms.push(geom);
}
return THREE.BufferGeometryUtils.mergeBufferGeometries(geoms);
}
用法:
const edgesGeom = new THREE.EdgesGeometry(dodecahedronGeom);
const cylindersGeom = edgesToCylinders(edgesGeom, 0.25);
const cylinders = new THREE.Mesh(
cylindersGeom,
new THREE.MeshLambertMaterial({color: "blue"})
);
scene.add(cylinders);
请参见updated fiddle。
答案 1 :(得分:1)
可自定义的解决方案,您可以从以下开始:
var edgesGeom = new THREE.EdgesGeometry(dodecahedronGeom); //EdgesGeometry is a BufferGeometry
var thickness = 0.25; // radius of a cylinder
for (var i = 0; i < edgesGeom.attributes.position.count - 1; i+=2){
// when you know that it's BufferGeometry, you can find vertices in this way
var startPoint = new THREE.Vector3(
edgesGeom.attributes.position.array[i * 3 + 0],
edgesGeom.attributes.position.array[i * 3 + 1],
edgesGeom.attributes.position.array[i * 3 + 2]
);
var endPoint = new THREE.Vector3(
edgesGeom.attributes.position.array[i * 3 + 3],
edgesGeom.attributes.position.array[i * 3 + 4],
edgesGeom.attributes.position.array[i * 3 + 5]
);
var cylLength = new THREE.Vector3().subVectors(endPoint, startPoint).length(); // find the length of a cylinder
var cylGeom = new THREE.CylinderBufferGeometry(thickness, thickness, cylLength, 16);
cylGeom.translate(0, cylLength / 2, 0);
cylGeom.rotateX(Math.PI / 2);
var cyl = new THREE.Mesh(cylGeom, new THREE.MeshLambertMaterial({color: "blue"}));
cyl.position.copy(startPoint);
cyl.lookAt(endPoint); // and do the trick with orienation
scene.add(cyl);
}
jsfiddle示例