यह परम समाधान नहीं है। यह सिर्फ एक बिंदु है जहां से आप शुरू कर सकते हैं।
युपीडी: Here इस उत्तर का एक विस्तार, यह देखते हुए अंक से आकृति बनाने के लिए कैसे है।
इसके अलावा, यह THREE.Object3D()
की .localToWorld()
विधि के बारे में WestLangley और ली Stemkoski से भयानक anwers साथ this SO question कहा जाता है।
आइए कल्पना करें कि आप एक सामान्य ज्यामिति के चौराहे के बिंदु ढूंढना चाहते हैं (उदाहरण के लिए, THREE.DodecahedronGeometry()
)।
विचार:
THREE.Plane()
.intersectLine (line, optionalTarget)
विधि
एक जाल चेहरे (THREE.Face3()
)
शामिल है
प्रत्येक चेहरा a, b, c
गुण है, जहां के सूचकांकों है कोने संग्रहित किया गया है।
जब हम कोने के सूचकांकों में जानते हैं, हम उन्हें vertices
की सरणी से प्राप्त कर सकते हैं जब हम एक चेहरे की कोने के निर्देशांक जानते हैं, हम निर्माण कर सकते हैं तीन THREE.Line3()
वस्तुओं
जब हमारे पास तीन लाइनें, हम जांच सकते हैं कि क्या हमारा विमान उन्हें छेड़छाड़ करता है।
यदि हमारे पास छेड़छाड़ का बिंदु है, तो हम इसे एक सरणी में स्टोर कर सकते हैं।
चरणों को फिर से 3 - जाल
कोड के साथ कुछ स्पष्टीकरण के प्रत्येक चेहरे के लिए 7:
हम plane
जो THREE.PlaneGeometry()
है और obj
जो है THREE.DodecahedronGeometry()
तो है, चलो चलो THREE.Plane()
बनाएं:
var planePointA = new THREE.Vector3(),
planePointB = new THREE.Vector3(),
planePointC = new THREE.Vector3();
var mathPlane = new THREE.Plane();
plane.localToWorld(planePointA.copy(plane.geometry.vertices[plane.geometry.faces[0].a]));
plane.localToWorld(planePointB.copy(plane.geometry.vertices[plane.geometry.faces[0].b]));
plane.localToWorld(planePointC.copy(plane.geometry.vertices[plane.geometry.faces[0].c]));
mathPlane.setFromCoplanarPoints(planePointA, planePointB, planePointC);
यहां, plane
के किसी भी चेहरे के तीन कोने सह-प्लानर हैं, इस प्रकार हम .setFromCoplanarPoints()
विधि का उपयोग करके mathPlane
बना सकते हैं।
फिर हम हमारे obj
के चेहरे के माध्यम से लूप:
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3();
obj.geometry.faces.forEach(function(face) {
obj.localToWorld(a.copy(obj.geometry.vertices[face.a]));
obj.localToWorld(b.copy(obj.geometry.vertices[face.b]));
obj.localToWorld(c.copy(obj.geometry.vertices[face.c]));
lineAB = new THREE.Line3(a, b);
lineBC = new THREE.Line3(b, c);
lineCA = new THREE.Line3(c, a);
setPointOfIntersection(lineAB, mathPlane);
setPointOfIntersection(lineBC, mathPlane);
setPointOfIntersection(lineCA, mathPlane);
});
जहां
var pointsOfIntersection = new THREE.Geometry();
...
var pointOfIntersection = new THREE.Vector3();
और
function setPointOfIntersection(line, plane) {
pointOfIntersection = plane.intersectLine(line);
if (pointOfIntersection) {
pointsOfIntersection.vertices.push(pointOfIntersection.clone());
};
}
अंत में हम अपने अंक दृश्यमान बना देंगे:
var pointsMaterial = new THREE.PointsMaterial({
size: .5,
color: "yellow"
});
var points = new THREE.Points(pointsOfIntersection, pointsMaterial);
scene.add(points);
jsfiddle उदाहरण। विमान और डोडकाहेड्रॉन के बीच छेड़छाड़ के बिंदु प्राप्त करने के लिए वहां बटन दबाएं।
अच्छा। साथ ही साथ बिंदुओं को भी जोड़ सकते हैं ... https://jsfiddle.net/8uxw667m/4/ – WestLangley
@WestLangley हाँ, बढ़िया! मैं वास्तव में ऐसी स्पष्ट दृश्य चीज़ को जोड़ना भूल गया। धन्यवाद! – prisoner849
अच्छा समाधान। मैंने दो बिंदुओं के बीच एक बिंदु (छेड़छाड़ बिंदु) तय करने के बारे में सोचा, अब, यह आवश्यक नहीं लगता है। –