'From Squeak3.1alpha of 28 February 2001 [latest update: #4081] on 25 May 2001 at 4:35:32 pm'! !PoohSubdivision methodsFor: 'private' stamp: 'ar 5/25/2001 16:09'! build3DObject "Return the full triangulation of the receiver" | firstPoly poly faces mesh half vtx nrm texScale | self markExteriorEdges. firstPoly _ self triangulate. faces _ WriteStream on: #(). poly _ firstPoly. [poly == nil] whileFalse:[ faces nextPutAll: (poly elevateSpine: 4). poly _ poly next]. faces _ faces contents. faces isEmpty ifTrue:[^nil]. half _ B3DSimpleMesh withAll: faces contents. texScale _ 1.0 / (area width max: area height). Preferences twoSidedPoohTextures ifTrue:[texScale _ texScale @ (0.5 * texScale)] ifFalse:[texScale _ texScale asPoint]. half do:[:face| face do:[:v| v texCoord: (v position x @ v position y) - area origin * texScale]]. half _ half asIndexedMesh. half vertexNormals: (half computeVertexNormals collect:[:v| v negated]). vtx _ half vertices. nrm _ half vertexNormals. 1 to: vtx size do:[:i| (vtx at: i) z = 0.0 ifTrue:[nrm at: i put: ((nrm at: i) z: 0.0)]]. mesh _ self mirror: half. ^mesh! ! !PoohSubdivision methodsFor: 'private' stamp: 'ar 5/25/2001 15:48'! mirror: half "Mirror one half-mesh and return a full mesh" | vtx nrm tex faces faceOffset vtxOffset mesh | vtx _ B3DVector3Array new: half vertices size * 2. nrm _ B3DVector3Array new: half vertexNormals size * 2. tex _ B3DVector2Array new: half texCoords size * 2. faces _ B3DIndexedTriangleArray new: (half faces size * 2). "Fill in first half" vtx privateReplaceFrom: 1 to: half vertices basicSize with: half vertices startingAt: 1. nrm privateReplaceFrom: 1 to: half vertexNormals basicSize with: half vertexNormals startingAt: 1. tex privateReplaceFrom: 1 to: half texCoords basicSize with: half texCoords startingAt: 1. faces privateReplaceFrom: 1 to: half faces basicSize with: half faces startingAt: 1. "fill in second half" half transformBy: (B3DMatrix4x4 withScale: 1@1@-1). Preferences twoSidedPoohTextures ifTrue:[ half texCoords do:[:tx| tx v: (1.0 - tx v)]. ]. vtx privateReplaceFrom: half vertices basicSize + 1 to: vtx basicSize with: half vertices startingAt: 1. nrm privateReplaceFrom: half vertexNormals basicSize + 1 to: nrm basicSize with: half vertexNormals startingAt: 1. tex privateReplaceFrom: half texCoords basicSize + 1 to: tex basicSize with: half texCoords startingAt: 1. faceOffset _ half faces basicSize. vtxOffset _ half vertices size. 1 to: half faces size do:[:i| faces basicAt: (faceOffset _ faceOffset + 1) put: (half faces basicAt: (i-1) * 3 + 3) + vtxOffset. faces basicAt: (faceOffset _ faceOffset + 1) put: (half faces basicAt: (i-1) * 3 + 2) + vtxOffset. faces basicAt: (faceOffset _ faceOffset + 1) put: (half faces basicAt: (i-1) * 3 + 1) + vtxOffset. ]. mesh _ B3DIndexedTriangleMesh new. mesh vertices: vtx. mesh vertexNormals: nrm. mesh faces: faces. mesh texCoords: tex. ^mesh! ! !WonderlandCameraMorph methodsFor: 'pooh' stamp: 'ar 5/25/2001 16:14'! createPoohActor | actor pointList box scale center subdivision mesh tex | pointList _ self outline. pointList reset. pointList _ pointList contents. pointList size < 2 ifTrue:[ self clearStroke. ^errorSound play]. pointList _ self simplify: pointList. pointList _ self smoothen: pointList length: 10. pointList _ self regularize: pointList. box _ Rectangle encompassing: pointList. scale _ bounds extent y * 0.5. scale _ 1.0 / (scale @ scale negated). center _ box origin + box corner * 0.5. pointList _ pointList collect:[:each| each - center * scale]. subdivision _ PoohSubdivision constraintOutline: pointList. mesh _ subdivision build3DObject. mesh ifNil:[ errorSound play. ] ifNotNil:[ actor _ self getWonderland makeActorNamed: 'pooh'. actor setProperty: #handmade toValue: true; setBackfaceCulling: #ccw; setMesh: mesh; setColor: gray. Preferences twoSidedPoohTextures ifTrue:[tex _ (Form extent: 256@512 depth: 32) asTexture fillColor: Color white] ifFalse:[tex _ (Form extent: 256@256 depth: 32) asTexture fillColor: Color white]. actor setTexturePointer: tex. actor setComposite: (myCamera getMatrixFromRoot composedWithLocal: (B3DMatrix4x4 withOffset: 0@0@2)). actor scaleByMatrix: (B3DRotation axis: 0@1@0 angle: 90) asMatrix4x4. actor rotateByMatrix: (B3DRotation axis: 0@1@0 angle:-90) asMatrix4x4. ]. self clearStroke. self mode: nil. Cursor normal show. ! ! "Postscript: Create new preference for pooh textures." Preferences addPreference: #twoSidedPoohTextures category: #media default: true balloonHelp:'When true, Pooh objects have independent textures for front and back'. !